Improvements to GUI performance

This commit is contained in:
Yousef Khadadeh 2026-05-19 16:35:08 +03:00
parent 1960ea827e
commit 80097dc41e
8 changed files with 31 additions and 21 deletions

View file

@ -34,8 +34,8 @@ struct ColorPickerItemsOptions {
template <typename T> 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 <typename T> void color_picker_items(GUIManager& gui, const char* id, T
},
.aspectRatio = {options.forceAspectRatioOnColorPicker ? 1.0f : 0.0f}
}) {
gui.element<ColorPicker<T>>("c", val, options.hasAlpha, ColorPickerData{ .onChange = fullOnEdit, .onHold = options.onSelect, .onRelease = options.onDeselect });
gui.element<ColorPicker<T>>("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 });
});
}
});

View file

@ -24,10 +24,6 @@
namespace GUIStuff { namespace ElementHelpers {
template <typename T> 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);

View file

@ -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);
}

View file

@ -29,6 +29,7 @@ class PaintCircleMenu : public Element {
Vector4f* selectedColor = nullptr;
std::vector<Vector3f> palette;
std::function<void()> onRotate;
std::function<void()> onRotateDone;
std::function<void()> onPaletteClick;
std::function<void(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering)> mouseButton;
};

View file

@ -51,6 +51,8 @@ template <typename T> void TextBox<T>::layout(const Clay_ElementId& id, const Te
}
template <typename T> void TextBox<T>::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();