Merge commit '511548a2ee54c5ceb2fd858919b278721cf5ba31'

This commit is contained in:
Gary Talent 2024-09-28 23:44:24 -05:00
commit aa61dd0efa
9 changed files with 40 additions and 19 deletions

View File

@ -316,7 +316,7 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
testIn.Union.Int = 93;
oxAssert(ox::writeMC(dataBuff.data(), dataBuff.size(), testIn), "Data generation failed");
ox::TypeStore typeStore;
const auto [type, typeErr] = ox::buildTypeDef(&typeStore, &testIn);
const auto [type, typeErr] = ox::buildTypeDef(typeStore, testIn);
oxAssert(typeErr, "Descriptor write failed");
ox::ModelObject testOut;
oxReturnError(testOut.setType(type));
@ -368,7 +368,7 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
testIn.Struct.IString = "Test String 2";
oxAssert(ox::writeMC(dataBuff, dataBuffLen, testIn), "Data generation failed");
ox::TypeStore typeStore;
const auto [type, typeErr] = ox::buildTypeDef(&typeStore, &testIn);
const auto [type, typeErr] = ox::buildTypeDef(typeStore, testIn);
oxAssert(typeErr, "Descriptor write failed");
ox::BufferReader br({dataBuff, dataBuffLen});
oxReturnError(ox::walkModel<ox::MetalClawReader>(type, br,

View File

@ -357,8 +357,8 @@ constexpr const DescriptorType *TypeDescWriter::getType(StringViewCR tn, int typ
}
template<typename T>
constexpr Result<DescriptorType*> buildTypeDef(TypeStore *typeStore) noexcept {
TypeDescWriter writer(typeStore);
constexpr Result<DescriptorType*> buildTypeDef(TypeStore &typeStore) noexcept {
TypeDescWriter writer(&typeStore);
ModelHandlerInterface<TypeDescWriter, ox::OpType::Reflect> handler(&writer);
if (std::is_constant_evaluated()) {
std::allocator<T> a;
@ -373,10 +373,10 @@ constexpr Result<DescriptorType*> buildTypeDef(TypeStore *typeStore) noexcept {
}
template<typename T>
constexpr Result<DescriptorType*> buildTypeDef(TypeStore *typeStore, T *val) noexcept {
TypeDescWriter writer(typeStore);
constexpr Result<DescriptorType*> buildTypeDef(TypeStore &typeStore, T &val) noexcept {
TypeDescWriter writer(&typeStore);
ModelHandlerInterface<TypeDescWriter, ox::OpType::Reflect> handler(&writer);
oxReturnError(model(&handler, val));
oxReturnError(model(&handler, &val));
return writer.definition();
}

View File

@ -652,7 +652,7 @@ class ModelObject {
}
[[nodiscard]]
constexpr CRString typeName() const noexcept {
constexpr StringCR typeName() const noexcept {
return m_type->typeName;
}

View File

@ -207,7 +207,7 @@ const std::map<ox::StringView, ox::Error(*)()> tests = {
testIn.Union.Int = 93;
oxAssert(ox::writeOC(testIn).moveTo(dataBuff), "Data generation failed");
ox::TypeStore typeStore;
auto type = ox::buildTypeDef(&typeStore, &testIn);
auto type = ox::buildTypeDef(typeStore, testIn);
oxAssert(type.error, "Descriptor write failed");
ox::ModelObject testOut;
oxReturnError(testOut.setType(type.value));
@ -257,7 +257,7 @@ const std::map<ox::StringView, ox::Error(*)()> tests = {
auto [oc, ocErr] = ox::writeOC(testIn);
oxAssert(ocErr, "Data generation failed");
ox::TypeStore typeStore;
auto type = ox::buildTypeDef(&typeStore, &testIn);
auto type = ox::buildTypeDef(typeStore, testIn);
oxAssert(type.error, "Descriptor write failed");
oxReturnError(ox::walkModel<ox::OrganicClawReader>(type.value, oc.data(), oc.size(),
[](const ox::Vector<ox::FieldName>&, const ox::Vector<ox::String>&, const ox::DescriptorField &f,

View File

@ -539,7 +539,7 @@ constexpr void BasicString<SmallStringSize_v>::set(const char8_t *str) noexcept
extern template class BasicString<8>;
using String = BasicString<8>;
using CRString = String const&;
using StringCR = String const&;
[[nodiscard]]

View File

@ -98,6 +98,12 @@ void PaletteEditorImGui::drawColumn(ox::CStringView txt) noexcept {
ImGui::Text("%s", txt.c_str());
}
void PaletteEditorImGui::colorInput(ox::CStringView label, int &v, bool &inputFocused) noexcept {
ImGui::InputInt(label.c_str(), &v, 1, 5);
inputFocused = inputFocused || ImGui::IsItemFocused();
v = ox::max(v, 0);
}
void PaletteEditorImGui::drawColorsEditor() noexcept {
constexpr auto tableFlags = ImGuiTableFlags_RowBg;
auto const colorsSz = ImGui::GetContentRegionAvail();
@ -238,17 +244,27 @@ void PaletteEditorImGui::drawColorEditor() noexcept {
ox::IString<50> name;
name = currentName;
ImGui::InputText("Name", name.data(), name.cap() + 1);
bool inputFocused = ImGui::IsItemFocused();
ImGui::Separator();
ImGui::InputInt("Red", &r, 1, 5);
ImGui::InputInt("Green", &g, 1, 5);
ImGui::InputInt("Blue", &b, 1, 5);
colorInput("Red", r, inputFocused);
colorInput("Green", g, inputFocused);
colorInput("Blue", b, inputFocused);
if (ig::PushButton("Apply to all pages", {-1, ig::BtnSz.y})) {
std::ignore = pushCommand<ApplyColorAllPagesCommand>(
m_pal, m_page, m_selectedColorRow);
}
r = ox::max(r, 0);
g = ox::max(g, 0);
b = ox::max(b, 0);
if (!inputFocused) {
auto const lastColor = largestPage(m_pal) - 1;
if (ImGui::IsKeyPressed(ImGuiKey_0, false)) {
m_selectedColorRow = ox::min<size_t>(9, lastColor);
} else for (auto i = 9u; i < 10; --i) {
auto const key = static_cast<ImGuiKey>(ImGuiKey_1 + i);
if (ImGui::IsKeyPressed(key, false)) {
m_selectedColorRow = ox::min<size_t>(i, lastColor);
break;
}
}
}
auto const newColor = color16(r, g, b, a);
if (c != newColor) {
std::ignore = pushCommand<UpdateColorCommand>(m_pal, m_page, m_selectedColorRow, newColor);

View File

@ -56,6 +56,8 @@ class PaletteEditorImGui: public studio::Editor {
drawColumn(ox::itoa(i));
}
static void colorInput(ox::CStringView label, int &v, bool &inputFocused) noexcept;
void drawColorsEditor() noexcept;
void drawPagesEditor() noexcept;

View File

@ -15,7 +15,7 @@ using TypeDescGenerator = ox::Error(*)(ox::TypeStore&);
template<typename T>
ox::Error generateTypeDesc(ox::TypeStore &ts) noexcept {
return ox::buildTypeDef<T>(&ts).error;
return ox::buildTypeDef<T>(ts).error;
}
class Module {

View File

@ -131,12 +131,15 @@ class Project {
template<typename T>
ox::Error Project::writeObj(ox::StringViewCR path, T const&obj, ox::ClawFormat fmt) noexcept {
oxRequireM(buff, ox::writeClaw(obj, fmt));
if (fmt == ox::ClawFormat::Organic) {
buff.pop_back();
}
// write to FS
oxReturnError(mkdir(parentDir(path)));
oxReturnError(writeBuff(path, buff));
// write type descriptor
if (m_typeStore.get<T>().error) {
oxReturnError(ox::buildTypeDef(&m_typeStore, &obj));
oxReturnError(ox::buildTypeDef(m_typeStore, obj));
}
oxRequire(desc, m_typeStore.get<T>());
auto const descPath = ox::sfmt("{}/{}", m_typeDescPath, buildTypeId(*desc));