Started work on grid creation menu

This commit is contained in:
Yousef Khadadeh 2025-09-06 19:06:30 +03:00
parent 57392cdfdd
commit 55b15e0ec1
18 changed files with 533 additions and 181 deletions

View file

@ -6,7 +6,7 @@ namespace GUIStuff {
template <typename T> class TextBox : public Element {
public:
void update(UpdateInputData& io, T* newData, const std::function<std::optional<T>(const std::string&)>& newFromStr, const std::function<std::string(const T&)> newToStr, bool newSingleLine, const std::function<void()>& elemUpdate) {
void update(UpdateInputData& io, T* newData, const std::function<std::optional<T>(const std::string&)>& newFromStr, const std::function<std::string(const T&)> newToStr, bool newSingleLine, bool updateEveryEdit, const std::function<void()>& elemUpdate) {
data = newData;
fromStr = newFromStr;
toStr = newToStr;
@ -18,7 +18,7 @@ template <typename T> class TextBox : public Element {
CLAY({
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(static_cast<float>(io.fontSize * 2)), .height = CLAY_SIZING_GROW(0)}
.sizing = {.width = CLAY_SIZING_GROW(static_cast<float>(io.fontSize * 2)), .height = CLAY_SIZING_GROW(static_cast<float>(io.fontSize))}
},
.custom = { .customData = this }
}) {
@ -59,12 +59,14 @@ template <typename T> class TextBox : public Element {
cur.selectionEndPos = cur.selectionBeginPos = cur.pos = textbox.remove(cur.selectionBeginPos, cur.selectionEndPos);
else
cur.selectionEndPos = cur.selectionBeginPos = cur.pos = textbox.remove(cur.pos, textbox.move(CollabTextBox::Movement::kLeft, cur.pos));
update_on_edit(updateEveryEdit);
}
if(io.key.del) {
if(cur.selectionBeginPos != cur.selectionEndPos)
cur.selectionEndPos = cur.selectionBeginPos = cur.pos = textbox.remove(cur.selectionBeginPos, cur.selectionEndPos);
else
cur.selectionEndPos = cur.selectionBeginPos = cur.pos = textbox.remove(cur.pos, textbox.move(CollabTextBox::Movement::kRight, cur.pos));
update_on_edit(updateEveryEdit);
}
if(io.key.paste) {
if(cur.selectionBeginPos != cur.selectionEndPos)
@ -76,6 +78,7 @@ template <typename T> class TextBox : public Element {
}
else
cur.selectionEndPos = cur.selectionBeginPos = cur.pos = textbox.insert(cur.pos, io.clipboard.textInFunc());
update_on_edit(updateEveryEdit);
}
if(io.key.enter) {
if(singleLine) {
@ -91,6 +94,7 @@ template <typename T> class TextBox : public Element {
cur.pos.fParagraphIndex++;
cur.pos.fTextByteIndex = 0;
cur.selectionBeginPos = cur.selectionEndPos = cur.pos;
update_on_edit(updateEveryEdit);
}
}
if(io.key.copy) {
@ -100,6 +104,7 @@ template <typename T> class TextBox : public Element {
io.clipboard.textOut = textbox.copy(cur.selectionBeginPos, cur.selectionEndPos);
if(cur.selectionBeginPos != cur.selectionEndPos)
cur.selectionEndPos = cur.selectionBeginPos = cur.pos = textbox.remove(cur.selectionBeginPos, cur.selectionEndPos);
update_on_edit(updateEveryEdit);
}
if(io.key.selectAll) {
cur.selectionEndPos.fParagraphIndex = textbox.lineCount() == 0 ? 0 : textbox.lineCount() - 1;
@ -112,6 +117,7 @@ template <typename T> class TextBox : public Element {
if(cur.selectionBeginPos != cur.selectionEndPos)
cur.selectionEndPos = cur.selectionBeginPos = cur.pos = textbox.remove(cur.selectionBeginPos, cur.selectionEndPos);
cur.selectionEndPos = cur.selectionBeginPos = cur.pos = textbox.insert(cur.pos, io.textInput);
update_on_edit(updateEveryEdit);
}
io.acceptingTextInput = true;
@ -178,6 +184,16 @@ template <typename T> class TextBox : public Element {
//oldData = T();
}
void update_on_edit(bool updateEveryEdit) {
if(updateEveryEdit) {
std::optional<T> dataToAssign = fromStr(textbox.get_string());
if(dataToAssign) {
*data = dataToAssign.value();
oldData = *data;
}
}
}
T* data = nullptr;
T oldData;

View file

@ -317,7 +317,7 @@ void GUIManager::input_color_component_255(const std::string& id, float* val, co
std::stringstream ss;
ss << convertTo255;
return ss.str();
}, true, elemUpdate);
}, true, false, elemUpdate);
pop_id();
}
@ -329,7 +329,7 @@ void GUIManager::input_text(const std::string& id, std::string* val, const std::
},
[&](const std::string& str) {
return str;
}, true, elemUpdate);
}, true, true, elemUpdate);
pop_id();
}
@ -414,7 +414,7 @@ void GUIManager::input_scalar(const std::string& id, uint8_t* val, uint8_t min,
},
[&](const uint8_t& a) {
return std::to_string(static_cast<uint32_t>(a));
}, true, elemUpdate);
}, true, false, elemUpdate);
pop_id();
}
@ -429,7 +429,7 @@ void GUIManager::input_path(const std::string& id, std::filesystem::path* val, s
},
[&](const std::filesystem::path& a) {
return a.string();
}, true, elemUpdate);
}, true, false, elemUpdate);
pop_id();
}

View file

@ -107,9 +107,9 @@ class GUIManager {
return toRet;
}
template <typename T> void input_generic(const std::string& id, T* val, const std::function<std::optional<T>(const std::string&)>& fromStr, const std::function<std::string(const T&)>& toStr, bool singleLine, const std::function<void()>& elemUpdate = nullptr) {
template <typename T> void input_generic(const std::string& id, T* val, const std::function<std::optional<T>(const std::string&)>& fromStr, const std::function<std::string(const T&)>& toStr, bool singleLine, bool updateEveryEdit, const std::function<void()>& elemUpdate = nullptr) {
push_id(id);
insert_element<TextBox<T>>()->update(*io, val, fromStr, toStr, singleLine, elemUpdate);
insert_element<TextBox<T>>()->update(*io, val, fromStr, toStr, singleLine, updateEveryEdit, elemUpdate);
pop_id();
}
@ -135,7 +135,7 @@ class GUIManager {
else
ss << *val;
return ss.str();
}, true, elemUpdate);
}, true, false, elemUpdate);
}
void input_scalar(const std::string& id, uint8_t* val, uint8_t min, uint8_t max, int decimalPrecision, const std::function<void()>& elemUpdate);
@ -184,7 +184,7 @@ class GUIManager {
}
return ss.str();
},
true, elemUpdate);
true, false, elemUpdate);
}
template <typename T> void color_picker(const std::string& id, T* val, bool selectAlpha, const std::function<void()>& elemUpdate = nullptr) {