From 80097dc41e4b193fa4085d30d0db63f3f76487c1 Mon Sep 17 00:00:00 2001 From: Yousef Khadadeh Date: Tue, 19 May 2026 16:35:08 +0300 Subject: [PATCH] Improvements to GUI performance --- .../Tools/EditTools/TextBoxEditTool.cpp | 14 ++++++++++---- .../ElementHelpers/ColorPickerItemsHelpers.hpp | 16 ++++++++-------- .../ElementHelpers/NumberSliderHelpers.hpp | 4 ---- src/GUIStuff/Elements/PaintCircleMenu.cpp | 3 +++ src/GUIStuff/Elements/PaintCircleMenu.hpp | 1 + src/GUIStuff/Elements/TextBox.impl.hpp | 2 ++ src/Screens/PhoneDrawingProgramScreen.cpp | 10 +++++----- src/Toolbar.cpp | 2 ++ 8 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/DrawingProgram/Tools/EditTools/TextBoxEditTool.cpp b/src/DrawingProgram/Tools/EditTools/TextBoxEditTool.cpp index 3668488..302701b 100644 --- a/src/DrawingProgram/Tools/EditTools/TextBoxEditTool.cpp +++ b/src/DrawingProgram/Tools/EditTools/TextBoxEditTool.cpp @@ -220,10 +220,13 @@ void TextBoxEditTool::edit_gui(Toolbar& t) { .onChange = [&] { currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR] = std::make_shared(newHighlightColor); a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR]); - commit_update_and_layout_func_and_android_update(); + commit_update_func_and_android_update(); }, .onSelect = [&] { hold_undo_data("Highlight Color", a); }, - .onDeselect = [&] { release_undo_data("Highlight Color"); } + .onDeselect = [&] { + release_undo_data("Highlight Color"); + gui.set_to_layout(); + } }); if(newHighlightColor.w() != 0.0f) { svg_icon_button(gui, "Remove Highlight Color", "data/icons/close.svg", { @@ -374,10 +377,13 @@ void TextBoxEditTool::phone_bottom_toolbar_gui(PhoneDrawingProgramScreen& t) { .onChange = [&] { currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR] = std::make_shared(newHighlightColor); a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR]); - commit_update_and_layout_func_and_android_update(); + commit_update_func_and_android_update(); }, .onSelect = [&] { hold_undo_data("Highlight Color", a); }, - .onDeselect = [&] { release_undo_data("Highlight Color"); } + .onDeselect = [&] { + release_undo_data("Highlight Color"); + gui.set_to_layout(); + } }; } }); diff --git a/src/GUIStuff/ElementHelpers/ColorPickerItemsHelpers.hpp b/src/GUIStuff/ElementHelpers/ColorPickerItemsHelpers.hpp index d764423..af183fc 100644 --- a/src/GUIStuff/ElementHelpers/ColorPickerItemsHelpers.hpp +++ b/src/GUIStuff/ElementHelpers/ColorPickerItemsHelpers.hpp @@ -34,8 +34,8 @@ struct ColorPickerItemsOptions { template void color_picker_items(GUIManager& gui, const char* id, T* val, const ColorPickerItemsOptions& options = {}) { gui.new_id(id, [&] { - auto fullOnEdit = [&gui, oE = options.onEdit]() { - if(oE) oE(); + auto fullOnDeselect = [&gui, oD = options.onDeselect]() { + if(oD) oD(); gui.set_to_layout(); }; CLAY_AUTO_ID({ @@ -44,24 +44,24 @@ template void color_picker_items(GUIManager& gui, const char* id, T }, .aspectRatio = {options.forceAspectRatioOnColorPicker ? 1.0f : 0.0f} }) { - gui.element>("c", val, options.hasAlpha, ColorPickerData{ .onChange = fullOnEdit, .onHold = options.onSelect, .onRelease = options.onDeselect }); + gui.element>("c", val, options.hasAlpha, ColorPickerData{ .onChange = options.onEdit, .onHold = options.onSelect, .onRelease = fullOnDeselect }); } if(!gui.io.isTouchDevice) { left_to_right_line_layout(gui, [&]() { text_label(gui, "R"); - input_color_component_255(gui, "r", &(*val)[0], { .onEdit = fullOnEdit, .onSelect = options.onSelect, .onDeselect = options.onDeselect }); + input_color_component_255(gui, "r", &(*val)[0], { .onEdit = options.onEdit, .onSelect = options.onSelect, .onDeselect = fullOnDeselect }); text_label(gui, "G"); - input_color_component_255(gui, "g", &(*val)[1], { .onEdit = fullOnEdit, .onSelect = options.onSelect, .onDeselect = options.onDeselect }); + input_color_component_255(gui, "g", &(*val)[1], { .onEdit = options.onEdit, .onSelect = options.onSelect, .onDeselect = fullOnDeselect }); text_label(gui, "B"); - input_color_component_255(gui, "b", &(*val)[2], { .onEdit = fullOnEdit, .onSelect = options.onSelect, .onDeselect = options.onDeselect }); + input_color_component_255(gui, "b", &(*val)[2], { .onEdit = options.onEdit, .onSelect = options.onSelect, .onDeselect = fullOnDeselect }); if(options.hasAlpha) { text_label(gui, "A"); - input_color_component_255(gui, "a", &(*val)[3], { .onEdit = fullOnEdit, .onSelect = options.onSelect, .onDeselect = options.onDeselect }); + input_color_component_255(gui, "a", &(*val)[3], { .onEdit = options.onEdit, .onSelect = options.onSelect, .onDeselect = fullOnDeselect }); } }); left_to_right_line_layout(gui, [&]() { text_label(gui, "Hex"); - input_color_hex(gui, "h", val, { .hasAlpha = options.hasAlpha, .onEdit = fullOnEdit, .onSelect = options.onSelect, .onDeselect = options.onDeselect }); + input_color_hex(gui, "h", val, { .hasAlpha = options.hasAlpha, .onEdit = options.onEdit, .onSelect = options.onSelect, .onDeselect = fullOnDeselect }); }); } }); diff --git a/src/GUIStuff/ElementHelpers/NumberSliderHelpers.hpp b/src/GUIStuff/ElementHelpers/NumberSliderHelpers.hpp index 0bfaf0e..3352007 100644 --- a/src/GUIStuff/ElementHelpers/NumberSliderHelpers.hpp +++ b/src/GUIStuff/ElementHelpers/NumberSliderHelpers.hpp @@ -24,10 +24,6 @@ namespace GUIStuff { namespace ElementHelpers { template void slider_scalar_field(GUIManager& gui, const char* id, std::string_view name, T* val, T min, T max, TextBoxScalarOptions options = {}) { gui.new_id(id, [&] { - options.onEdit = [&, oE = options.onEdit] { - if(oE) oE(); - gui.set_to_layout(); - }; left_to_right_line_layout(gui, [&]() { text_label(gui, name); input_scalar(gui, "textbox", val, min, max, options); diff --git a/src/GUIStuff/Elements/PaintCircleMenu.cpp b/src/GUIStuff/Elements/PaintCircleMenu.cpp index 1c59269..52a3e39 100644 --- a/src/GUIStuff/Elements/PaintCircleMenu.cpp +++ b/src/GUIStuff/Elements/PaintCircleMenu.cpp @@ -61,7 +61,10 @@ void PaintCircleMenu::input_mouse_button_callback(const InputManager::MouseButto if(d.mouseButton) d.mouseButton(button, mouseHovering); dd.isHeld = mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down; update_paint_circle_menu_mouse_hover(button.pos); + bool isRotateBarHeldOld = dd.isRotateBarHeld; dd.isRotateBarHeld = dd.isRotateBarHovered && dd.isHeld; + if(isRotateBarHeldOld && !dd.isRotateBarHeld && d.onRotateDone) + d.onRotateDone(); update_paint_circle_menu_mouse(button.pos, button.button == InputManager::MouseButton::LEFT && button.down); } diff --git a/src/GUIStuff/Elements/PaintCircleMenu.hpp b/src/GUIStuff/Elements/PaintCircleMenu.hpp index 3bd1257..c606b10 100644 --- a/src/GUIStuff/Elements/PaintCircleMenu.hpp +++ b/src/GUIStuff/Elements/PaintCircleMenu.hpp @@ -29,6 +29,7 @@ class PaintCircleMenu : public Element { Vector4f* selectedColor = nullptr; std::vector palette; std::function onRotate; + std::function onRotateDone; std::function onPaletteClick; std::function mouseButton; }; diff --git a/src/GUIStuff/Elements/TextBox.impl.hpp b/src/GUIStuff/Elements/TextBox.impl.hpp index 50af79d..c6b8aad 100644 --- a/src/GUIStuff/Elements/TextBox.impl.hpp +++ b/src/GUIStuff/Elements/TextBox.impl.hpp @@ -51,6 +51,8 @@ template void TextBox::layout(const Clay_ElementId& id, const Te } template void TextBox::update() { + if(!is_selected()) + reset_textbox_text(); std::string newTextboxStr = textbox->get_string(); if(oldDD.isSelected != is_selected() || oldDD.textboxStr != newTextboxStr || oldDD.cur != *cur) { oldDD.isSelected = is_selected(); diff --git a/src/Screens/PhoneDrawingProgramScreen.cpp b/src/Screens/PhoneDrawingProgramScreen.cpp index 1fcc1be..ed5641b 100644 --- a/src/Screens/PhoneDrawingProgramScreen.cpp +++ b/src/Screens/PhoneDrawingProgramScreen.cpp @@ -1002,12 +1002,12 @@ void PhoneDrawingProgramScreen::color_settings_popup(Vector4f* color, const Colo .aspectRatio = {1.0f} }) { gui.element>("color picker element", color, true, ColorPickerData{ - .onChange = [&, d] { - if(d.onChange) d.onChange(); - gui.set_to_layout(); - }, + .onChange = d.onChange, .onHold = d.onSelect, - .onRelease = d.onDeselect + .onRelease = [&, d] { + if(d.onDeselect) d.onDeselect(); + main.g.gui.set_to_layout(); + } }); } CLAY_AUTO_ID({ diff --git a/src/Toolbar.cpp b/src/Toolbar.cpp index 533afcf..4bfe79d 100644 --- a/src/Toolbar.cpp +++ b/src/Toolbar.cpp @@ -392,6 +392,8 @@ void Toolbar::paint_popup(Vector2f popupPos) { .onRotate = [&, newRotationAngle] { main.world->drawData.cam.c.rotate_about(main.world->drawData.cam.c.from_space(main.window.size.cast() * 0.5f), *newRotationAngle - main.world->drawData.cam.c.rotation); *newRotationAngle = main.world->drawData.cam.c.rotation; + }, + .onRotateDone = [&] { gui.set_to_layout(); }, .onPaletteClick = [&] {