Starting work on moving GUI to event system (doesnt compile)

This commit is contained in:
Yousef Khadadeh 2026-03-27 09:51:53 +03:00
parent f1a855edc3
commit ef7dfcef05
69 changed files with 4296 additions and 3709 deletions

View file

@ -145,12 +145,14 @@ void TextBox::process_key_input(Cursor& cur, InputKey in, bool ctrl, bool shift,
cur.selectionEndPos = cur.selectionBeginPos = cur.pos = remove(cur.selectionBeginPos, cur.selectionEndPos);
else
cur.selectionEndPos = cur.selectionBeginPos = cur.pos = remove(cur.pos, move(ctrl ? Movement::LEFT_WORD : Movement::LEFT, cur.pos));
if(onUserTextEdit) onUserTextEdit();
break;
case InputKey::DEL:
if(cur.selectionBeginPos != cur.selectionEndPos)
cur.selectionEndPos = cur.selectionBeginPos = cur.pos = remove(cur.selectionBeginPos, cur.selectionEndPos);
else
cur.selectionEndPos = cur.selectionBeginPos = cur.pos = remove(cur.pos, move(ctrl ? Movement::RIGHT_WORD : Movement::RIGHT, cur.pos));
if(onUserTextEdit) onUserTextEdit();
break;
case InputKey::ENTER:
process_text_input(cur, "\n", inputModMap);
@ -170,6 +172,7 @@ void TextBox::process_key_input(Cursor& cur, InputKey in, bool ctrl, bool shift,
if(in != InputKey::UP && in != InputKey::DOWN)
cur.previousX = std::nullopt;
if(onChange) onChange();
inputChangedTextBox = true;
}
@ -224,6 +227,7 @@ void TextBox::process_mouse_left_button(Cursor& cur, const Vector2f& pos, int cl
cur.previousX = std::nullopt;
if((oldCursor != cur) && onChange) onChange();
inputChangedTextBox |= (oldCursor != cur);
}
else
@ -239,6 +243,8 @@ std::pair<std::string, TextData> TextBox::process_cut(Cursor& cur) {
if(cur.selectionBeginPos != cur.selectionEndPos) {
cur.selectionEndPos = cur.selectionBeginPos = cur.pos = remove(cur.selectionBeginPos, cur.selectionEndPos);
cur.previousX = std::nullopt;
if(onChange) onChange();
if(onUserTextEdit) onUserTextEdit();
inputChangedTextBox = true;
}
return toRet;
@ -250,6 +256,8 @@ void TextBox::process_text_input(Cursor& cur, const std::string& in, const std::
cur.selectionEndPos = cur.selectionBeginPos = cur.pos = remove(cur.selectionBeginPos, cur.selectionEndPos);
cur.selectionEndPos = cur.selectionBeginPos = cur.pos = insert(cur.pos, in, inputModMap);
cur.previousX = std::nullopt;
if(onChange) onChange();
if(onUserTextEdit) onUserTextEdit();
inputChangedTextBox = true;
}
}
@ -260,6 +268,8 @@ void TextBox::process_rich_text_input(Cursor& cur, const TextData& richText) {
cur.selectionEndPos = cur.selectionBeginPos = cur.pos = remove(cur.selectionBeginPos, cur.selectionEndPos);
cur.selectionEndPos = cur.selectionBeginPos = cur.pos = insert_rich_text(cur.pos, richText);
cur.previousX = std::nullopt;
if(onChange) onChange();
if(onUserTextEdit) onUserTextEdit();
inputChangedTextBox = true;
}
}
@ -456,6 +466,7 @@ TextPosition TextBox::insert_rich_text(TextPosition p, const TextData& richText)
paragraphs[pIndex].pStyleData = richText.paragraphs[pIndex - p.fParagraphIndex].pStyleData;
}
if(onChange) onChange();
inputChangedTextBox = true;
needsRebuild = true;
@ -483,6 +494,7 @@ void TextBox::set_rich_text_data(const TextData& richText) {
if(richText.paragraphs.empty())
paragraphs.emplace_back();
tStyleMods = richText.tStyleMods;
if(onChange) onChange();
inputChangedTextBox = true;
needsRebuild = true;
}
@ -514,6 +526,7 @@ std::string TextBox::get_text_between(TextPosition p1, TextPosition p2) {
void TextBox::set_initial_text_style(const skia::textlayout::TextStyle& tStyle) {
if(!tStyle.equals(initialTStyle)) {
initialTStyle = tStyle;
if(onChange) onChange();
inputChangedTextBox = true;
needsRebuild = true;
}
@ -585,6 +598,7 @@ void TextBox::set_text_style_modifier_between(TextPosition p1, TextPosition p2,
insert_style_at_pos(start, modifier);
insert_style_at_pos(end, lastModOfThisTypeBeforeEnd); // Even if the end is the literal end of the text (which wont be seen), the end style must still be placed at the end so that it can merge with and delete the start style when the styled text is erased
remove_duplicate_text_style_mods();
if(onChange) onChange();
inputChangedTextBox = true;
needsRebuild = true;
}
@ -600,6 +614,7 @@ void TextBox::set_text_alignment_between(size_t paragraphIndex1, size_t paragrap
}
}
if(anythingChanged) {
if(onChange) onChange();
inputChangedTextBox = true;
needsRebuild = true;
}
@ -615,6 +630,7 @@ void TextBox::set_text_direction_between(size_t paragraphIndex1, size_t paragrap
}
}
if(anythingChanged) {
if(onChange) onChange();
inputChangedTextBox = true;
needsRebuild = true;
}
@ -851,6 +867,7 @@ int TextBox::get_line_number_at_from_byte_text_pos(TextPosition pos) {
void TextBox::set_width(float newWidth) {
if(width != newWidth) {
width = std::max(newWidth, 4.0f);
if(onChange) onChange();
inputChangedTextBox = true;
needsRebuild = true;
}
@ -868,6 +885,7 @@ void TextBox::set_allow_newlines(bool allow) {
void TextBox::set_font_data(const std::shared_ptr<FontData>& fD) {
if(fontData != fD) {
fontData = fD;
if(onChange) onChange();
inputChangedTextBox = true;
needsRebuild = true;
}
@ -1037,6 +1055,7 @@ TextPosition TextBox::insert(TextPosition pos, std::string_view textToInsert, co
for(const auto& [modType, modifier] : inputModMap.value())
set_text_style_modifier_between(oldPos, pos, modifier);
}
if(onChange) onChange();
inputChangedTextBox = true;
needsRebuild = true;
}
@ -1086,6 +1105,7 @@ TextPosition TextBox::remove(TextPosition p1, TextPosition p2) {
}
remove_duplicate_text_style_mods();
if(onChange) onChange();
inputChangedTextBox = true;
needsRebuild = true;

View file

@ -67,6 +67,8 @@ class TextBox {
TextBox();
bool inputChangedTextBox = false;
std::function<void()> onChange;
std::function<void()> onUserTextEdit;
enum class Movement {
NOWHERE,