Fixed multiple segfaults

This commit is contained in:
Yousef Khadadeh 2026-03-30 18:51:14 +03:00
parent b4c35124c3
commit 2ad5684594
32 changed files with 1035 additions and 1010 deletions

View file

@ -329,7 +329,7 @@ void DrawingProgram::toolbar_gui() {
using namespace ElementHelpers; using namespace ElementHelpers;
Toolbar& t = world.main.toolbar; Toolbar& t = world.main.toolbar;
t.gui.push_id("Drawing Program Toolbar GUI"); t.gui.new_id("Drawing Program Toolbar GUI", [&] {
t.gui.element<LayoutElement>("Drawing Program Toolbar GUI", [&] { t.gui.element<LayoutElement>("Drawing Program Toolbar GUI", [&] {
CLAY_AUTO_ID({ CLAY_AUTO_ID({
.layout = { .layout = {
@ -373,6 +373,7 @@ void DrawingProgram::toolbar_gui() {
}); });
} }
}); });
});
} }
void DrawingProgram::popup_menu_action_button(const char* id, const char* text, const std::function<void()>& onClick) { void DrawingProgram::popup_menu_action_button(const char* id, const char* text, const std::function<void()>& onClick) {
@ -422,9 +423,9 @@ void DrawingProgram::selection_action_menu(Vector2f popupPos) {
void DrawingProgram::right_click_popup_gui(Vector2f popupPos) { void DrawingProgram::right_click_popup_gui(Vector2f popupPos) {
Toolbar& t = world.main.toolbar; Toolbar& t = world.main.toolbar;
t.gui.push_id("Drawing Program right click GUI"); t.gui.new_id("Drawing Program right click GUI", [&] {
drawTool->right_click_popup_gui(popupPos); drawTool->right_click_popup_gui(popupPos);
t.gui.pop_id(); });
} }
void DrawingProgram::tool_options_gui() { void DrawingProgram::tool_options_gui() {

View file

@ -36,7 +36,7 @@ void DrawingProgramSelection::selection_gui() {
using namespace ElementHelpers; using namespace ElementHelpers;
auto& t = drawP.world.main.toolbar; auto& t = drawP.world.main.toolbar;
t.gui.push_id("general selection gui"); t.gui.new_id("general selection gui", [&] {
text_label(t.gui, "Select from:"); text_label(t.gui, "Select from:");
radio_button_selector(t.gui, "layer selector", &drawP.controls.layerSelector, { radio_button_selector(t.gui, "layer selector", &drawP.controls.layerSelector, {
{"Layer being edited", DrawingProgramLayerManager::LayerSelector::LAYER_BEING_EDITED}, {"Layer being edited", DrawingProgramLayerManager::LayerSelector::LAYER_BEING_EDITED},
@ -53,7 +53,7 @@ void DrawingProgramSelection::selection_gui() {
}); });
update_selection_stroke_color(); update_selection_stroke_color();
} }
t.gui.pop_id(); });
} }
void DrawingProgramSelection::update_selection_stroke_color() { void DrawingProgramSelection::update_selection_stroke_color() {

View file

@ -172,11 +172,11 @@ void BrushTool::gui_toolbox() {
using namespace ElementHelpers; using namespace ElementHelpers;
Toolbar& t = drawP.world.main.toolbar; Toolbar& t = drawP.world.main.toolbar;
t.gui.push_id("brush tool"); t.gui.new_id("brush tool", [&] {
text_label_centered(t.gui, "Brush"); text_label_centered(t.gui, "Brush");
checkbox_boolean_field(t.gui, "hasroundcaps", "Round Caps", &drawP.world.main.toolConfig.brush.hasRoundCaps); checkbox_boolean_field(t.gui, "hasroundcaps", "Round Caps", &drawP.world.main.toolConfig.brush.hasRoundCaps);
drawP.world.main.toolConfig.relative_width_gui(drawP, "Size"); drawP.world.main.toolConfig.relative_width_gui(drawP, "Size");
t.gui.pop_id(); });
} }
void BrushTool::right_click_popup_gui(Vector2f popupPos) { void BrushTool::right_click_popup_gui(Vector2f popupPos) {

View file

@ -33,9 +33,9 @@ void EditTool::gui_toolbox() {
if(objInfoBeingEdited) if(objInfoBeingEdited)
compEditTool->edit_gui(objInfoBeingEdited); compEditTool->edit_gui(objInfoBeingEdited);
else { else {
t.gui.push_id("edit tool"); t.gui.new_id("edit tool", [&] {
text_label_centered(t.gui, "Edit"); text_label_centered(t.gui, "Edit");
t.gui.pop_id(); });
} }
} }

View file

@ -16,14 +16,14 @@ void BrushEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
using namespace ElementHelpers; using namespace ElementHelpers;
Toolbar& t = drawP.world.main.toolbar; Toolbar& t = drawP.world.main.toolbar;
t.gui.push_id("edit tool brush"); t.gui.new_id("edit tool brush", [&] {
text_label_centered(t.gui, "Edit Brush Stroke"); text_label_centered(t.gui, "Edit Brush Stroke");
left_to_right_line_layout(t.gui, [&]() { left_to_right_line_layout(t.gui, [&]() {
//if(t.gui.color_button_big("Outline Color", &a.d.color, &a.d.color == t.colorRight)) //if(t.gui.color_button_big("Outline Color", &a.d.color, &a.d.color == t.colorRight))
// t.color_selector_right(&a.d.color == t.colorRight ? nullptr : &a.d.color); // t.color_selector_right(&a.d.color == t.colorRight ? nullptr : &a.d.color);
text_label(t.gui, "Outline Color"); text_label(t.gui, "Outline Color");
}); });
t.gui.pop_id(); });
} }
void BrushEditTool::edit_start(EditTool& editTool, CanvasComponentContainer::ObjInfo* comp, std::any& prevData) { void BrushEditTool::edit_start(EditTool& editTool, CanvasComponentContainer::ObjInfo* comp, std::any& prevData) {

View file

@ -23,7 +23,7 @@ void EllipseDrawEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
auto& a = static_cast<EllipseCanvasComponent&>(comp->obj->get_comp()); auto& a = static_cast<EllipseCanvasComponent&>(comp->obj->get_comp());
Toolbar& t = drawP.world.main.toolbar; Toolbar& t = drawP.world.main.toolbar;
t.gui.push_id("edit tool ellipse"); t.gui.new_id("edit tool ellipse", [&] {
text_label_centered(t.gui, "Edit Ellipse"); text_label_centered(t.gui, "Edit Ellipse");
radio_button_selector(t.gui, "Fill selector", &a.d.fillStrokeMode, { radio_button_selector(t.gui, "Fill selector", &a.d.fillStrokeMode, {
{"Fill only", 0}, {"Fill only", 0},
@ -45,7 +45,7 @@ void EllipseDrawEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
text_label(t.gui, "Outline Color"); text_label(t.gui, "Outline Color");
}); });
} }
t.gui.pop_id(); });
} }
void EllipseDrawEditTool::edit_start(EditTool& editTool, CanvasComponentContainer::ObjInfo* comp, std::any& prevData) { void EllipseDrawEditTool::edit_start(EditTool& editTool, CanvasComponentContainer::ObjInfo* comp, std::any& prevData) {

View file

@ -51,7 +51,7 @@ void ImageEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
ImageCanvasComponent& a = static_cast<ImageCanvasComponent&>(comp->obj->get_comp()); ImageCanvasComponent& a = static_cast<ImageCanvasComponent&>(comp->obj->get_comp());
Toolbar& t = drawP.world.main.toolbar; Toolbar& t = drawP.world.main.toolbar;
t.gui.push_id("edit tool image"); t.gui.new_id("edit tool image", [&] {
text_label_centered(t.gui, "File Properties"); text_label_centered(t.gui, "File Properties");
auto resourceData = drawP.world.netObjMan.get_obj_temporary_ref_from_id<ResourceData>(a.d.imageID); auto resourceData = drawP.world.netObjMan.get_obj_temporary_ref_from_id<ResourceData>(a.d.imageID);
@ -75,5 +75,5 @@ void ImageEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
} }
else else
text_label_centered(t.gui, "Loading resource..."); text_label_centered(t.gui, "Loading resource...");
t.gui.pop_id(); });
} }

View file

@ -19,7 +19,7 @@ void RectDrawEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
auto& a = static_cast<RectangleCanvasComponent&>(comp->obj->get_comp()); auto& a = static_cast<RectangleCanvasComponent&>(comp->obj->get_comp());
Toolbar& t = drawP.world.main.toolbar; Toolbar& t = drawP.world.main.toolbar;
t.gui.push_id("edit tool rectangle"); t.gui.new_id("edit tool rectangle", [&] {
text_label_centered(t.gui, "Edit Rectangle"); text_label_centered(t.gui, "Edit Rectangle");
slider_scalar_field(t.gui, "relradiuswidth", "Corner Radius", &a.d.cornerRadius, 0.0f, 40.0f); slider_scalar_field(t.gui, "relradiuswidth", "Corner Radius", &a.d.cornerRadius, 0.0f, 40.0f);
radio_button_selector(t.gui, "Fill selector", &a.d.fillStrokeMode, { radio_button_selector(t.gui, "Fill selector", &a.d.fillStrokeMode, {
@ -42,7 +42,7 @@ void RectDrawEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
text_label(t.gui, "Outline Color"); text_label(t.gui, "Outline Color");
}); });
} }
t.gui.pop_id(); });
} }
void RectDrawEditTool::edit_start(EditTool& editTool, CanvasComponentContainer::ObjInfo* comp, std::any& prevData) { void RectDrawEditTool::edit_start(EditTool& editTool, CanvasComponentContainer::ObjInfo* comp, std::any& prevData) {

View file

@ -33,7 +33,7 @@ void TextBoxEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
auto& currentMods = *currentModsPtr; auto& currentMods = *currentModsPtr;
t.gui.push_id("edit tool text"); t.gui.new_id("edit tool text", [&] {
text_label_centered(t.gui, "Edit Text"); text_label_centered(t.gui, "Edit Text");
left_to_right_line_layout(t.gui, [&] { left_to_right_line_layout(t.gui, [&] {
@ -148,7 +148,7 @@ void TextBoxEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
// a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR]); // a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR]);
//} //}
//t.gui.pop_id(); });
//if(a.textBox->inputChangedTextBox) //if(a.textBox->inputChangedTextBox)
// set_styles_at_selection(a); // set_styles_at_selection(a);

View file

@ -27,7 +27,7 @@ void EllipseDrawTool::gui_toolbox() {
Toolbar& t = drawP.world.main.toolbar; Toolbar& t = drawP.world.main.toolbar;
auto& toolConfig = drawP.world.main.toolConfig; auto& toolConfig = drawP.world.main.toolConfig;
auto& fillStrokeMode = toolConfig.ellipseDraw.fillStrokeMode; auto& fillStrokeMode = toolConfig.ellipseDraw.fillStrokeMode;
t.gui.push_id("ellipse draw tool"); t.gui.new_id("ellipse draw tool", [&] {
text_label_centered(t.gui, "Draw Ellipse"); text_label_centered(t.gui, "Draw Ellipse");
radio_button_selector(t.gui, "fill type", &fillStrokeMode, { radio_button_selector(t.gui, "fill type", &fillStrokeMode, {
{"Fill only", 0}, {"Fill only", 0},
@ -36,7 +36,7 @@ void EllipseDrawTool::gui_toolbox() {
}); });
if(fillStrokeMode == 1 || fillStrokeMode == 2) if(fillStrokeMode == 1 || fillStrokeMode == 2)
toolConfig.relative_width_gui(drawP, "Outline Size"); toolConfig.relative_width_gui(drawP, "Outline Size");
t.gui.pop_id(); });
} }
void EllipseDrawTool::input_mouse_button_on_canvas_callback(const InputManager::MouseButtonCallbackArgs& button) { void EllipseDrawTool::input_mouse_button_on_canvas_callback(const InputManager::MouseButtonCallbackArgs& button) {

View file

@ -21,7 +21,7 @@ void EraserTool::gui_toolbox() {
using namespace ElementHelpers; using namespace ElementHelpers;
Toolbar& t = drawP.world.main.toolbar; Toolbar& t = drawP.world.main.toolbar;
t.gui.push_id("eraser tool"); t.gui.new_id("eraser tool", [&] {
text_label_centered(t.gui, "Eraser"); text_label_centered(t.gui, "Eraser");
drawP.world.main.toolConfig.relative_width_gui(drawP, "Size"); drawP.world.main.toolConfig.relative_width_gui(drawP, "Size");
text_label(t.gui, "Erase from:"); text_label(t.gui, "Erase from:");
@ -29,7 +29,7 @@ void EraserTool::gui_toolbox() {
{"Layer being edited", DrawingProgramLayerManager::LayerSelector::LAYER_BEING_EDITED}, {"Layer being edited", DrawingProgramLayerManager::LayerSelector::LAYER_BEING_EDITED},
{"All visible layers", DrawingProgramLayerManager::LayerSelector::ALL_VISIBLE_LAYERS} {"All visible layers", DrawingProgramLayerManager::LayerSelector::ALL_VISIBLE_LAYERS}
}); });
t.gui.pop_id(); });
} }
void EraserTool::right_click_popup_gui(Vector2f popupPos) { void EraserTool::right_click_popup_gui(Vector2f popupPos) {

View file

@ -32,14 +32,14 @@ void EyeDropperTool::gui_toolbox() {
Toolbar& t = drawP.world.main.toolbar; Toolbar& t = drawP.world.main.toolbar;
auto& selectingStrokeColor = drawP.world.main.toolConfig.eyeDropper.selectingStrokeColor; auto& selectingStrokeColor = drawP.world.main.toolConfig.eyeDropper.selectingStrokeColor;
t.gui.push_id("Color select tool"); t.gui.new_id("Color select tool", [&] {
text_label_centered(t.gui, "Color Select"); text_label_centered(t.gui, "Color Select");
radio_button_selector<bool>(t.gui, "Stroke type", &selectingStrokeColor, { radio_button_selector<bool>(t.gui, "Stroke type", &selectingStrokeColor, {
{"Stroke Color", true}, {"Stroke Color", true},
{"Fill Color", false} {"Fill Color", false}
}); });
t.gui.pop_id(); });
} }
void EyeDropperTool::right_click_popup_gui(Vector2f popupPos) { void EyeDropperTool::right_click_popup_gui(Vector2f popupPos) {

View file

@ -118,7 +118,7 @@ void GridModifyTool::gui_toolbox() {
using namespace ElementHelpers; using namespace ElementHelpers;
Toolbar& t = drawP.world.main.toolbar; Toolbar& t = drawP.world.main.toolbar;
t.gui.push_id("Grid modify tool"); t.gui.new_id("Grid modify tool", [&] {
text_label_centered(t.gui, "Edit Grid"); text_label_centered(t.gui, "Edit Grid");
NetworkingObjects::NetObjTemporaryPtr<WorldGrid> gLock = grid.lock(); NetworkingObjects::NetObjTemporaryPtr<WorldGrid> gLock = grid.lock();
if(gLock) { if(gLock) {
@ -162,7 +162,7 @@ void GridModifyTool::gui_toolbox() {
g.bounds = std::nullopt; g.bounds = std::nullopt;
checkbox_boolean_field(t.gui, "Show Coordinates", "Show Coordinates (visible\nwhen canvas isn't rotated)", &g.showCoordinates); checkbox_boolean_field(t.gui, "Show Coordinates", "Show Coordinates (visible\nwhen canvas isn't rotated)", &g.showCoordinates);
} }
t.gui.pop_id(); });
} }
void GridModifyTool::right_click_popup_gui(Vector2f popupPos) { void GridModifyTool::right_click_popup_gui(Vector2f popupPos) {

View file

@ -42,10 +42,10 @@ DrawingProgramToolType LassoSelectTool::get_type() {
void LassoSelectTool::gui_toolbox() { void LassoSelectTool::gui_toolbox() {
auto& t = drawP.world.main.toolbar; auto& t = drawP.world.main.toolbar;
t.gui.push_id("lasso select tool"); t.gui.new_id("lasso select tool", [&] {
GUIStuff::ElementHelpers::text_label_centered(t.gui, "Lasso Select"); GUIStuff::ElementHelpers::text_label_centered(t.gui, "Lasso Select");
drawP.selection.selection_gui(); drawP.selection.selection_gui();
t.gui.pop_id(); });
} }
void LassoSelectTool::right_click_popup_gui(Vector2f popupPos) { void LassoSelectTool::right_click_popup_gui(Vector2f popupPos) {

View file

@ -24,11 +24,11 @@ void LineDrawTool::gui_toolbox() {
using namespace ElementHelpers; using namespace ElementHelpers;
Toolbar& t = drawP.world.main.toolbar; Toolbar& t = drawP.world.main.toolbar;
auto& toolConfig = drawP.world.main.toolConfig; auto& toolConfig = drawP.world.main.toolConfig;
t.gui.push_id("rect draw tool"); t.gui.new_id("rect draw tool", [&] {
text_label_centered(t.gui, "Draw Line"); text_label_centered(t.gui, "Draw Line");
toolConfig.relative_width_gui(drawP, "Size"); toolConfig.relative_width_gui(drawP, "Size");
checkbox_boolean_field(t.gui, "hasroundcaps", "Round Caps", &toolConfig.lineDraw.hasRoundCaps); checkbox_boolean_field(t.gui, "hasroundcaps", "Round Caps", &toolConfig.lineDraw.hasRoundCaps);
t.gui.pop_id(); });
} }
void LineDrawTool::input_mouse_button_on_canvas_callback(const InputManager::MouseButtonCallbackArgs& button) { void LineDrawTool::input_mouse_button_on_canvas_callback(const InputManager::MouseButtonCallbackArgs& button) {

View file

@ -18,9 +18,9 @@ DrawingProgramToolType PanCanvasTool::get_type() {
void PanCanvasTool::gui_toolbox() { void PanCanvasTool::gui_toolbox() {
Toolbar& t = drawP.world.main.toolbar; Toolbar& t = drawP.world.main.toolbar;
t.gui.push_id("Pan canvas tool"); t.gui.new_id("Pan canvas tool", [&] {
GUIStuff::ElementHelpers::text_label_centered(t.gui, "Pan tool"); GUIStuff::ElementHelpers::text_label_centered(t.gui, "Pan tool");
t.gui.pop_id(); });
} }
void PanCanvasTool::right_click_popup_gui(Vector2f popupPos) { void PanCanvasTool::right_click_popup_gui(Vector2f popupPos) {

View file

@ -26,7 +26,7 @@ void RectDrawTool::gui_toolbox() {
auto& toolConfig = drawP.world.main.toolConfig; auto& toolConfig = drawP.world.main.toolConfig;
auto& fillStrokeMode = toolConfig.rectDraw.fillStrokeMode; auto& fillStrokeMode = toolConfig.rectDraw.fillStrokeMode;
auto& relativeRadiusWidth = toolConfig.rectDraw.relativeRadiusWidth; auto& relativeRadiusWidth = toolConfig.rectDraw.relativeRadiusWidth;
t.gui.push_id("rect draw tool"); t.gui.new_id("rect draw tool", [&] {
text_label_centered(t.gui, "Draw Rectangle"); text_label_centered(t.gui, "Draw Rectangle");
slider_scalar_field(t.gui, "relradiuswidth", "Corner Radius", &relativeRadiusWidth, 0.0f, 40.0f); slider_scalar_field(t.gui, "relradiuswidth", "Corner Radius", &relativeRadiusWidth, 0.0f, 40.0f);
radio_button_selector(t.gui, "fill type", &fillStrokeMode, { radio_button_selector(t.gui, "fill type", &fillStrokeMode, {
@ -36,7 +36,7 @@ void RectDrawTool::gui_toolbox() {
}); });
if(fillStrokeMode == 1 || fillStrokeMode == 2) if(fillStrokeMode == 1 || fillStrokeMode == 2)
toolConfig.relative_width_gui(drawP, "Outline Size"); toolConfig.relative_width_gui(drawP, "Outline Size");
t.gui.pop_id(); });
} }
void RectDrawTool::input_mouse_button_on_canvas_callback(const InputManager::MouseButtonCallbackArgs& button) { void RectDrawTool::input_mouse_button_on_canvas_callback(const InputManager::MouseButtonCallbackArgs& button) {

View file

@ -20,10 +20,10 @@ DrawingProgramToolType RectSelectTool::get_type() {
void RectSelectTool::gui_toolbox() { void RectSelectTool::gui_toolbox() {
auto& t = drawP.world.main.toolbar; auto& t = drawP.world.main.toolbar;
t.gui.push_id("rectangle select tool"); t.gui.new_id("rectangle select tool", [&] {
GUIStuff::ElementHelpers::text_label_centered(t.gui, "Rectangle Select"); GUIStuff::ElementHelpers::text_label_centered(t.gui, "Rectangle Select");
drawP.selection.selection_gui(); drawP.selection.selection_gui();
t.gui.pop_id(); });
} }
void RectSelectTool::input_key_callback(const InputManager::KeyCallbackArgs& key) { void RectSelectTool::input_key_callback(const InputManager::KeyCallbackArgs& key) {

View file

@ -58,7 +58,7 @@ void ScreenshotTool::gui_toolbox() {
Toolbar& t = drawP.world.main.toolbar; Toolbar& t = drawP.world.main.toolbar;
auto& screenshotConfig = drawP.world.main.toolConfig.screenshot; auto& screenshotConfig = drawP.world.main.toolConfig.screenshot;
t.gui.push_id("screenshot tool"); t.gui.new_id("screenshot tool", [&] {
text_label_centered(t.gui, "Screenshot"); text_label_centered(t.gui, "Screenshot");
auto oldImgSize = controls.imageSize; auto oldImgSize = controls.imageSize;
if(controls.selectionMode == ScreenshotControls::SelectionMode::NO_SELECTION) if(controls.selectionMode == ScreenshotControls::SelectionMode::NO_SELECTION)
@ -122,7 +122,7 @@ void ScreenshotTool::gui_toolbox() {
} }
}); });
} }
t.gui.pop_id(); });
} }
void ScreenshotTool::right_click_popup_gui(Vector2f popupPos) { void ScreenshotTool::right_click_popup_gui(Vector2f popupPos) {

View file

@ -23,9 +23,9 @@ DrawingProgramToolType TextBoxTool::get_type() {
void TextBoxTool::gui_toolbox() { void TextBoxTool::gui_toolbox() {
Toolbar& t = drawP.world.main.toolbar; Toolbar& t = drawP.world.main.toolbar;
t.gui.push_id("textbox tool"); t.gui.new_id("textbox tool", [&] {
GUIStuff::ElementHelpers::text_label_centered(t.gui, "Zoom tool"); GUIStuff::ElementHelpers::text_label_centered(t.gui, "Zoom tool");
t.gui.pop_id(); });
} }
void TextBoxTool::input_mouse_button_on_canvas_callback(const InputManager::MouseButtonCallbackArgs& button) { void TextBoxTool::input_mouse_button_on_canvas_callback(const InputManager::MouseButtonCallbackArgs& button) {

View file

@ -18,9 +18,9 @@ DrawingProgramToolType ZoomCanvasTool::get_type() {
void ZoomCanvasTool::gui_toolbox() { void ZoomCanvasTool::gui_toolbox() {
Toolbar& t = drawP.world.main.toolbar; Toolbar& t = drawP.world.main.toolbar;
t.gui.push_id("Zoom canvas tool"); t.gui.new_id("Zoom canvas tool", [&] {
GUIStuff::ElementHelpers::text_label_centered(t.gui, "Zoom tool"); GUIStuff::ElementHelpers::text_label_centered(t.gui, "Zoom tool");
t.gui.pop_id(); });
} }
void ZoomCanvasTool::right_click_popup_gui(Vector2f popupPos) { void ZoomCanvasTool::right_click_popup_gui(Vector2f popupPos) {

View file

@ -47,7 +47,7 @@ void text_button_sized(GUIManager& gui, const char* id, std::string_view text, C
void svg_icon_button(GUIManager& gui, const char* id, const std::string& svgPath, const SVGButtonOptions& options = {}); void svg_icon_button(GUIManager& gui, const char* id, const std::string& svgPath, const SVGButtonOptions& options = {});
template <typename T> void color_button(GUIManager& gui, const char* id, T* val, const FixedSizeColorButtonOptions& options = {}) { template <typename T> void color_button(GUIManager& gui, const char* id, T* val, const FixedSizeColorButtonOptions& options = {}) {
gui.push_id(id); gui.new_id(id, [&] {
SelectableButton::Data d = selectable_button_options_to_data(options); SelectableButton::Data d = selectable_button_options_to_data(options);
d.innerContent = [&] (const SelectableButton::InnerContentCallbackParameters&) { d.innerContent = [&] (const SelectableButton::InnerContentCallbackParameters&) {
gui.element<ColorRectangleDisplay>("color display", [val, hasAlpha = options.hasAlpha] { gui.element<ColorRectangleDisplay>("color display", [val, hasAlpha = options.hasAlpha] {
@ -60,7 +60,7 @@ template <typename T> void color_button(GUIManager& gui, const char* id, T* val,
CLAY_AUTO_ID({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(options.size), .height = CLAY_SIZING_FIXED(options.size) } } }) { CLAY_AUTO_ID({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(options.size), .height = CLAY_SIZING_FIXED(options.size) } } }) {
gui.element<SelectableButton>("button", d); gui.element<SelectableButton>("button", d);
} }
gui.pop_id(); });
} }
}} }}

View file

@ -11,7 +11,7 @@ struct ColorPickerItemsOptions {
}; };
template <typename T> void color_picker_items(GUIManager& gui, const char* id, T* val, const ColorPickerItemsOptions& options = {}) { template <typename T> void color_picker_items(GUIManager& gui, const char* id, T* val, const ColorPickerItemsOptions& options = {}) {
gui.push_id(id); gui.new_id(id, [&] {
auto fullOnEdit = [&gui, oE = options.onEdit, val]() { auto fullOnEdit = [&gui, oE = options.onEdit, val]() {
oE(); oE();
gui.set_to_layout(); gui.set_to_layout();
@ -33,7 +33,7 @@ template <typename T> void color_picker_items(GUIManager& gui, const char* id, T
text_label(gui, "Hex"); text_label(gui, "Hex");
input_color_hex(gui, "h", val, { .hasAlpha = options.hasAlpha, .onEdit = fullOnEdit }); input_color_hex(gui, "h", val, { .hasAlpha = options.hasAlpha, .onEdit = fullOnEdit });
}); });
gui.pop_id(); });
} }
} } } }

View file

@ -5,7 +5,7 @@
namespace GUIStuff { namespace ElementHelpers { 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 = {}) { 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.push_id(id); gui.new_id(id, [&] {
options.onEdit = [&, oE = options.onEdit] { options.onEdit = [&, oE = options.onEdit] {
oE(); oE();
gui.set_to_layout(); gui.set_to_layout();
@ -15,6 +15,6 @@ namespace GUIStuff { namespace ElementHelpers {
input_scalar(gui, "textbox", val, min, max, options); input_scalar(gui, "textbox", val, min, max, options);
}); });
gui.element<NumberSlider<T>>("slider", val, min, max, options.onEdit); gui.element<NumberSlider<T>>("slider", val, min, max, options.onEdit);
gui.pop_id(); });
} }
}} }}

View file

@ -6,14 +6,14 @@ namespace GUIStuff { namespace ElementHelpers {
void radio_button_field(GUIManager& gui, const char* id, std::string_view name, const std::function<bool()>& isTicked, const std::function<void()>& onClick); void radio_button_field(GUIManager& gui, const char* id, std::string_view name, const std::function<bool()>& isTicked, const std::function<void()>& onClick);
template <typename T> void radio_button_selector(GUIManager& gui, const char* id, T* data, const std::vector<std::pair<std::string_view, T>>& options, const std::function<void()>& onClick = nullptr) { template <typename T> void radio_button_selector(GUIManager& gui, const char* id, T* data, const std::vector<std::pair<std::string_view, T>>& options, const std::function<void()>& onClick = nullptr) {
gui.push_id(id); gui.new_id(id, [&] {
for(size_t i = 0; i < options.size(); i++) { for(size_t i = 0; i < options.size(); i++) {
gui.push_id(i); gui.new_id(i, [&] {
auto& option = options[i]; auto& option = options[i];
radio_button_field(gui, "Option", option.first, [data, optionVal = option.second]{ return *data == optionVal; }, [data, optionVal = option.second, onClick]{ *data = optionVal; if(onClick) onClick(); }); radio_button_field(gui, "Option", option.first, [data, optionVal = option.second]{ return *data == optionVal; }, [data, optionVal = option.second, onClick]{ *data = optionVal; if(onClick) onClick(); });
gui.pop_id(); });
} }
gui.pop_id(); });
} }
}} }}

View file

@ -25,11 +25,8 @@ void scroll_area_many_entries(GUIManager& gui, const char* id, const ScrollBarMa
}) { } }) { }
} }
for(size_t i = startPoint; i < endPoint; i++) { for(size_t i = startPoint; i < endPoint; i++)
gui.push_id(i); gui.new_id(i, [&] { options.elementContent(i); });
options.elementContent(i);
gui.pop_id();
}
if(endPoint != options.entryCount) { if(endPoint != options.entryCount) {
CLAY_AUTO_ID({ CLAY_AUTO_ID({

View file

@ -13,6 +13,7 @@ void input_color_component_255(GUIManager& gui, const char* id, float* val, cons
}; };
TextBoxData<float> d = textbox_options_to_data<float>(options); TextBoxData<float> d = textbox_options_to_data<float>(options);
d.data = val;
d.textInputProps = textInputProps; d.textInputProps = textInputProps;
d.fromStr = [](const std::string& str) { d.fromStr = [](const std::string& str) {
int roundTo255; int roundTo255;
@ -41,6 +42,7 @@ void input_text(GUIManager& gui, const char* id, std::string* val, const TextBox
}; };
TextBoxData<std::string> d = textbox_options_to_data<std::string>(options); TextBoxData<std::string> d = textbox_options_to_data<std::string>(options);
d.data = val;
d.textInputProps = textInputProps; d.textInputProps = textInputProps;
d.fromStr = [](const std::string& a) { d.fromStr = [](const std::string& a) {
return a; return a;
@ -69,6 +71,7 @@ void input_scalar(GUIManager& gui, const char* id, uint8_t* val, uint8_t minVal,
}; };
TextBoxData<uint8_t> d = textbox_options_to_data<uint8_t>(options); TextBoxData<uint8_t> d = textbox_options_to_data<uint8_t>(options);
d.data = val;
d.textInputProps = textInputProps; d.textInputProps = textInputProps;
d.fromStr = [minVal, maxVal](const std::string& a) { d.fromStr = [minVal, maxVal](const std::string& a) {
if(a.empty()) if(a.empty())
@ -98,6 +101,7 @@ void input_path(GUIManager& gui, const char* id, std::filesystem::path* val, con
}; };
TextBoxData<std::filesystem::path> d = textbox_options_to_data<std::filesystem::path>(options); TextBoxData<std::filesystem::path> d = textbox_options_to_data<std::filesystem::path>(options);
d.data = val;
d.textInputProps = textInputProps; d.textInputProps = textInputProps;
d.fromStr = [fileTypeRestriction = options.fileTypeRestriction](const std::string& a) { d.fromStr = [fileTypeRestriction = options.fileTypeRestriction](const std::string& a) {
std::filesystem::path toRet = std::filesystem::path(std::u8string_view(reinterpret_cast<const char8_t*>(a.c_str()), a.length())); std::filesystem::path toRet = std::filesystem::path(std::u8string_view(reinterpret_cast<const char8_t*>(a.c_str()), a.length()));

View file

@ -67,6 +67,7 @@ template <typename T> void input_scalar(GUIManager& gui, const char* id, T* val,
textInputProps.androidInputType |= InputManager::AndroidInputType::ANDROIDTEXT_TYPE_NUMBER_FLAG_DECIMAL; textInputProps.androidInputType |= InputManager::AndroidInputType::ANDROIDTEXT_TYPE_NUMBER_FLAG_DECIMAL;
TextBoxData<T> d = textbox_options_to_data<T>(options); TextBoxData<T> d = textbox_options_to_data<T>(options);
d.data = val;
d.textInputProps = textInputProps; d.textInputProps = textInputProps;
d.fromStr = [minVal, maxVal](const std::string& a) { d.fromStr = [minVal, maxVal](const std::string& a) {
if(a.empty()) if(a.empty())
@ -94,16 +95,13 @@ template <typename T> void input_scalar(GUIManager& gui, const char* id, T* val,
} }
template <typename TContainer, typename T> void input_scalars_field(GUIManager& gui, const char* id, std::string_view name, TContainer* val, size_t elemCount, T minVal, T maxVal, const TextBoxScalarOptions& options = {}) { template <typename TContainer, typename T> void input_scalars_field(GUIManager& gui, const char* id, std::string_view name, TContainer* val, size_t elemCount, T minVal, T maxVal, const TextBoxScalarOptions& options = {}) {
gui.push_id(id); gui.new_id(id, [&] {
left_to_right_line_layout(gui, [&]() { left_to_right_line_layout(gui, [&]() {
text_label(gui, name); text_label(gui, name);
for(size_t i = 0; i < elemCount; i++) { for(size_t i = 0; i < elemCount; i++)
gui.push_id(i); gui.new_id(i, [&] { input_scalar<T>(gui, "field", &(*val)[i], minVal, maxVal, options); });
input_scalar<T>(gui, "field", &(*val)[i], minVal, maxVal, options); });
gui.pop_id();
}
}); });
gui.pop_id();
} }
template <typename T> void input_scalar_field(GUIManager& gui, const char* id, std::string_view name, T* val, T minVal, T maxVal, const TextBoxScalarOptions& options = {}) { template <typename T> void input_scalar_field(GUIManager& gui, const char* id, std::string_view name, T* val, T minVal, T maxVal, const TextBoxScalarOptions& options = {}) {
@ -123,6 +121,7 @@ template <typename T> void input_color_hex(GUIManager& gui, const char* id, T* v
}; };
TextBoxData<T> d = textbox_options_to_data<T>(options); TextBoxData<T> d = textbox_options_to_data<T>(options);
d.data = val;
d.textInputProps = textInputProps; d.textInputProps = textInputProps;
d.fromStr = [hasAlpha = options.hasAlpha](const std::string& a) { d.fromStr = [hasAlpha = options.hasAlpha](const std::string& a) {
T def; T def;

View file

@ -8,14 +8,6 @@ template <typename T> TextBox<T>::TextBox(GUIManager& gui): Element(gui) {}
template <typename T> void TextBox<T>::layout(const TextBoxData<T>& userInfo) { template <typename T> void TextBox<T>::layout(const TextBoxData<T>& userInfo) {
auto& io = *gui.io; auto& io = *gui.io;
this->userInfo = userInfo; this->userInfo = userInfo;
textbox->onUserTextEdit = [&] {
if(userInfo.immutable)
cur->pos = cur->selectionBeginPos = cur->selectionEndPos = textbox->insert({0, 0}, userInfo.toStr(*userInfo.data));
else {
if(update_data() && userInfo.onEdit)
gui.set_post_callback_func(userInfo.onEdit);
}
};
init_textbox(io); init_textbox(io);
CLAY_AUTO_ID({ CLAY_AUTO_ID({
.layout = { .layout = {
@ -118,6 +110,14 @@ template <typename T> void TextBox<T>::init_textbox(UpdateInputData& io) {
rect = std::make_shared<SCollision::AABB<float>>(); rect = std::make_shared<SCollision::AABB<float>>();
cur->pos = cur->selectionBeginPos = cur->selectionEndPos = textbox->insert({0, 0}, userInfo.toStr(*userInfo.data)); cur->pos = cur->selectionBeginPos = cur->selectionEndPos = textbox->insert({0, 0}, userInfo.toStr(*userInfo.data));
textbox->onUserTextEdit = [&] {
if(userInfo.immutable)
cur->pos = cur->selectionBeginPos = cur->selectionEndPos = textbox->insert({0, 0}, userInfo.toStr(*userInfo.data));
else {
if(update_data() && userInfo.onEdit)
gui.set_post_callback_func(userInfo.onEdit);
}
};
} }
template <typename T> bool TextBox<T>::update_data() { template <typename T> bool TextBox<T>::update_data() {

View file

@ -35,6 +35,7 @@ GUIManager::GUIManager()
clayArena = Clay_CreateArenaWithCapacityAndMemory(Clay_MinMemorySize(), malloc(Clay_MinMemorySize())); clayArena = Clay_CreateArenaWithCapacityAndMemory(Clay_MinMemorySize(), malloc(Clay_MinMemorySize()));
clayInstance = Clay_Initialize(clayArena, Clay_Dimensions(1.0f, 1.0f), (Clay_ErrorHandler)clay_error_handler); clayInstance = Clay_Initialize(clayArena, Clay_Dimensions(1.0f, 1.0f), (Clay_ErrorHandler)clay_error_handler);
Clay_SetMeasureTextFunction(clay_skia_measure_text, this); Clay_SetMeasureTextFunction(clay_skia_measure_text, this);
setToLayout = true;
} }
Clay_Dimensions GUIManager::clay_skia_measure_text(Clay_StringSlice str, Clay_TextElementConfig* config, void* userData) { Clay_Dimensions GUIManager::clay_skia_measure_text(Clay_StringSlice str, Clay_TextElementConfig* config, void* userData) {
@ -291,6 +292,18 @@ void GUIManager::clay_error_handler(Clay_ErrorData errorData) {
Logger::get().log("INFO", "[Clay Error] " + std::string(errorData.errorText.chars)); Logger::get().log("INFO", "[Clay Error] " + std::string(errorData.errorText.chars));
} }
void GUIManager::new_id(const char* id, const std::function<void()>& f) {
push_id(id);
f();
pop_id();
}
void GUIManager::new_id(int64_t id, const std::function<void()>& f) {
push_id(id);
f();
pop_id();
}
void GUIManager::push_id(int64_t id) { void GUIManager::push_id(int64_t id) {
idStack.emplace_back(id); idStack.emplace_back(id);
} }

View file

@ -28,9 +28,8 @@ class GUIManager {
GUIManagerIDStack idStack; GUIManagerIDStack idStack;
std::unordered_map<GUIManagerIDStack, ElementContainer> elements; std::unordered_map<GUIManagerIDStack, ElementContainer> elements;
void push_id(int64_t id); void new_id(const char* id, const std::function<void()>& f);
void push_id(const char* id); void new_id(int64_t id, const std::function<void()>& f);
void pop_id();
void set_post_callback_func(const std::function<void()>& f); void set_post_callback_func(const std::function<void()>& f);
@ -65,6 +64,10 @@ class GUIManager {
static void clay_error_handler(Clay_ErrorData errorData); static void clay_error_handler(Clay_ErrorData errorData);
static Clay_Dimensions clay_skia_measure_text(Clay_StringSlice str, Clay_TextElementConfig* config, void* userData); static Clay_Dimensions clay_skia_measure_text(Clay_StringSlice str, Clay_TextElementConfig* config, void* userData);
void push_id(int64_t id);
void push_id(const char* id);
void pop_id();
std::function<void()> postCallbackFunc; std::function<void()> postCallbackFunc;
Clay_Context* clayInstance; Clay_Context* clayInstance;
Clay_Arena clayArena; Clay_Arena clayArena;

View file

@ -69,6 +69,11 @@ Toolbar::Toolbar(MainProgram& initMain):
{ {
io->textTypeface = main.fonts->map["Roboto"]; io->textTypeface = main.fonts->map["Roboto"];
io->fonts = main.fonts; io->fonts = main.fonts;
io->layoutRun = [&] {
layout_run();
};
io->input = &main.input;
gui.io = io;
// NOTE: On windows, when the native file picker is open, any call to MakeFromFile fails // NOTE: On windows, when the native file picker is open, any call to MakeFromFile fails
// So, it's better to load the icons at the beginning of the program so that the icon loading doesn't fail later // So, it's better to load the icons at the beginning of the program so that the icon loading doesn't fail later
@ -412,6 +417,9 @@ void Toolbar::set_config_json(const nlohmann::json& j, VersionNumber version) {
void Toolbar::update() { void Toolbar::update() {
calculate_final_gui_scale(); calculate_final_gui_scale();
io->windowSize = main.window.size.cast<float>();
io->windowPos = {0, 0};
gui.layout_if_necessary();
} }
void Toolbar::layout_run() { void Toolbar::layout_run() {
@ -517,7 +525,7 @@ void Toolbar::close_popup_gui() {
.cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1), .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1),
.floating = {.zIndex = 1, .attachPoints = {.element = CLAY_ATTACH_POINT_CENTER_CENTER, .parent = CLAY_ATTACH_POINT_CENTER_CENTER}, .attachTo = CLAY_ATTACH_TO_PARENT} .floating = {.zIndex = 1, .attachPoints = {.element = CLAY_ATTACH_POINT_CENTER_CENTER, .parent = CLAY_ATTACH_POINT_CENTER_CENTER}, .attachTo = CLAY_ATTACH_TO_PARENT}
}) { }) {
gui.push_id("Close single file popup gui"); gui.new_id("Close single file popup gui", [&] {
text_label(gui, "Files may contain unsaved changes"); text_label(gui, "Files may contain unsaved changes");
gui.element<ScrollArea>("close file popup gui scroll area", ScrollArea::Options{ gui.element<ScrollArea>("close file popup gui scroll area", ScrollArea::Options{
.scrollVertical = true, .scrollVertical = true,
@ -545,7 +553,7 @@ void Toolbar::close_popup_gui() {
.backgroundColor = convert_vec4<Clay_Color>(io->theme->backColor2), .backgroundColor = convert_vec4<Clay_Color>(io->theme->backColor2),
.cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1), .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1),
}) { }) {
gui.push_id(i); gui.new_id(i, [&] {
checkbox_boolean(gui, "set to save checkbox", &setToSave); checkbox_boolean(gui, "set to save checkbox", &setToSave);
CLAY_AUTO_ID({ CLAY_AUTO_ID({
.layout = { .layout = {
@ -558,7 +566,7 @@ void Toolbar::close_popup_gui() {
text_label(gui, wLock->name); text_label(gui, wLock->name);
text_label_light(gui, wLock->filePath.empty() ? "Autosave in " + main.documentsPath.string() : wLock->filePath.string()); text_label_light(gui, wLock->filePath.empty() ? "Autosave in " + main.documentsPath.string() : wLock->filePath.string());
} }
gui.pop_id(); });
} }
++i; ++i;
} }
@ -600,7 +608,7 @@ void Toolbar::close_popup_gui() {
closePopupData.closeAppWhenDone = false; closePopupData.closeAppWhenDone = false;
} }
}); });
gui.pop_id(); });
} }
} }
@ -651,7 +659,7 @@ void Toolbar::top_toolbar() {
.backgroundColor = convert_vec4<Clay_Color>(io->theme->backColor1), .backgroundColor = convert_vec4<Clay_Color>(io->theme->backColor1),
.cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1) .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1)
}) { }) {
gui.push_id("menu top toolbar"); gui.new_id("menu top toolbar", [&] {
global_log(); global_log();
bool menuPopUpJustOpen = false; bool menuPopUpJustOpen = false;
bool bookmarkMenuPopUpJustOpen = false; bool bookmarkMenuPopUpJustOpen = false;
@ -840,7 +848,7 @@ void Toolbar::top_toolbar() {
} }
}); });
} }
gui.pop_id(); });
} }
} }
@ -857,7 +865,7 @@ void Toolbar::web_version_welcome() {
.cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1), .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1),
.floating = {.attachPoints = {.element = CLAY_ATTACH_POINT_CENTER_CENTER, .parent = CLAY_ATTACH_POINT_CENTER_CENTER}, .attachTo = CLAY_ATTACH_TO_PARENT} .floating = {.attachPoints = {.element = CLAY_ATTACH_POINT_CENTER_CENTER, .parent = CLAY_ATTACH_POINT_CENTER_CENTER}, .attachTo = CLAY_ATTACH_TO_PARENT}
}) { }) {
gui.push_id("web version welcome gui"); gui.new_id("web version welcome gui", [&] {
text_label_centered(gui, "Welcome to the web version of InfiniPaint!"); text_label_centered(gui, "Welcome to the web version of InfiniPaint!");
text_label(gui, text_label(gui,
R"(This version contains more known issues than the native version of the app. This includes: R"(This version contains more known issues than the native version of the app. This includes:
@ -874,7 +882,7 @@ If you like this app, consider downloading the native version for your system)")
viewWebVersionWelcome = false; viewWebVersionWelcome = false;
} }
}); });
gui.pop_id(); });
} }
} }
@ -969,7 +977,7 @@ void Toolbar::update_notification_gui() {
.cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1), .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1),
.floating = {.attachPoints = {.element = CLAY_ATTACH_POINT_CENTER_CENTER, .parent = CLAY_ATTACH_POINT_CENTER_CENTER}, .attachTo = CLAY_ATTACH_TO_PARENT} .floating = {.attachPoints = {.element = CLAY_ATTACH_POINT_CENTER_CENTER, .parent = CLAY_ATTACH_POINT_CENTER_CENTER}, .attachTo = CLAY_ATTACH_TO_PARENT}
}) { }) {
gui.push_id("update notification gui"); gui.new_id("update notification gui", [&] {
text_label_centered(gui, "Update v" + updateCheckerData.newVersionStr + " available!"); text_label_centered(gui, "Update v" + updateCheckerData.newVersionStr + " available!");
text_button(gui, "download", "Open download page in web browser", { text_button(gui, "download", "Open download page in web browser", {
.wide = true, .wide = true,
@ -991,14 +999,14 @@ void Toolbar::update_notification_gui() {
updateCheckerData.showGui = false; updateCheckerData.showGui = false;
} }
}); });
gui.pop_id(); });
} }
} }
#endif #endif
void Toolbar::grid_menu(bool justOpened) { void Toolbar::grid_menu(bool justOpened) {
if(main.world->gridMan.grids) { if(main.world->gridMan.grids) {
gui.push_id("grid menu"); gui.new_id("grid menu", [&] {
//CLAY(localId, { //CLAY(localId, {
// .layout = { // .layout = {
// .sizing = {.width = CLAY_SIZING_FIT(300), .height = CLAY_SIZING_FIT(0, 600) }, // .sizing = {.width = CLAY_SIZING_FIT(300), .height = CLAY_SIZING_FIT(0, 600) },
@ -1081,7 +1089,7 @@ void Toolbar::grid_menu(bool justOpened) {
// if(io->mouse.leftClick && !Clay_Hovered() && !justOpened && !dropdownHover) // if(io->mouse.leftClick && !Clay_Hovered() && !justOpened && !dropdownHover)
// stop_displaying_grid_menu(); // stop_displaying_grid_menu();
//} //}
gui.pop_id(); });
} }
} }
@ -1092,7 +1100,7 @@ void Toolbar::stop_displaying_grid_menu() {
} }
void Toolbar::bookmark_menu(bool justOpened) { void Toolbar::bookmark_menu(bool justOpened) {
gui.push_id("bookmark menu"); gui.new_id("bookmark menu", [&] {
//Clay_ElementId localId = CLAY_ID_LOCAL("INFINIPAINT BOOKMARK MENU"); //Clay_ElementId localId = CLAY_ID_LOCAL("INFINIPAINT BOOKMARK MENU");
//CLAY(localId, { //CLAY(localId, {
// .layout = { // .layout = {
@ -1114,11 +1122,11 @@ void Toolbar::bookmark_menu(bool justOpened) {
// main.world->bMan.refresh_gui_data(); // main.world->bMan.refresh_gui_data();
// } // }
//} //}
gui.pop_id(); });
} }
void Toolbar::layer_menu(bool justOpened) { void Toolbar::layer_menu(bool justOpened) {
gui.push_id("layer menu"); gui.new_id("layer menu", [&] {
//Clay_ElementId localId = CLAY_ID_LOCAL("INFINIPAINT LAYER MENU"); //Clay_ElementId localId = CLAY_ID_LOCAL("INFINIPAINT LAYER MENU");
//CLAY(localId, { //CLAY(localId, {
// .layout = { // .layout = {
@ -1141,7 +1149,7 @@ void Toolbar::layer_menu(bool justOpened) {
// main.world->drawProg.layerMan.listGUI.refresh_gui_data(); // main.world->drawProg.layerMan.listGUI.refresh_gui_data();
// } // }
//} //}
gui.pop_id(); });
} }
std::unique_ptr<skia::textlayout::Paragraph> Toolbar::build_paragraph_from_chat_message(const ChatMessage& message, float alpha) { std::unique_ptr<skia::textlayout::Paragraph> Toolbar::build_paragraph_from_chat_message(const ChatMessage& message, float alpha) {
@ -1410,7 +1418,7 @@ void Toolbar::drawing_program_gui() {
bool Toolbar::color_palette(const char* id, Vector4f* color, bool& hoveringOnDropdown) { bool Toolbar::color_palette(const char* id, Vector4f* color, bool& hoveringOnDropdown) {
bool isUpdating = false; bool isUpdating = false;
gui.push_id(id); gui.new_id(id, [&] {
//auto& palette = paletteData.palettes[paletteData.selectedPalette].colors; //auto& palette = paletteData.palettes[paletteData.selectedPalette].colors;
//constexpr float COLOR_BUTTON_SIZE = GUIStuff::GUIManager::BIG_BUTTON_SIZE; //constexpr float COLOR_BUTTON_SIZE = GUIStuff::GUIManager::BIG_BUTTON_SIZE;
@ -1517,7 +1525,7 @@ bool Toolbar::color_palette(const char* id, Vector4f* color, bool& hoveringOnDro
// paletteData.addingPalette = false; // paletteData.addingPalette = false;
// } // }
//} //}
gui.pop_id(); });
return isUpdating; return isUpdating;
} }
@ -1588,7 +1596,7 @@ void Toolbar::player_list() {
.cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1), .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1),
.floating = {.attachPoints = {.element = CLAY_ATTACH_POINT_CENTER_CENTER, .parent = CLAY_ATTACH_POINT_CENTER_CENTER}, .attachTo = CLAY_ATTACH_TO_PARENT} .floating = {.attachPoints = {.element = CLAY_ATTACH_POINT_CENTER_CENTER, .parent = CLAY_ATTACH_POINT_CENTER_CENTER}, .attachTo = CLAY_ATTACH_TO_PARENT}
}) { }) {
gui.push_id("client list"); gui.new_id("client list", [&] {
text_label_centered(gui, "Player List"); text_label_centered(gui, "Player List");
if(!main.world->clientStillConnecting) { if(!main.world->clientStillConnecting) {
left_to_right_line_layout(gui, [&]() { left_to_right_line_layout(gui, [&]() {
@ -1604,7 +1612,7 @@ void Toolbar::player_list() {
size_t num = 0; size_t num = 0;
for(auto& client : main.world->clients->get_data()) { for(auto& client : main.world->clients->get_data()) {
if(client != main.world->ownClientData) { if(client != main.world->ownClientData) {
gui.push_id(num++); gui.new_id(num++, [&] {
left_to_right_line_layout(gui, [&]() { left_to_right_line_layout(gui, [&]() {
CLAY_AUTO_ID({ CLAY_AUTO_ID({
.layout = { .layout = {
@ -1619,14 +1627,14 @@ void Toolbar::player_list() {
main.world->drawData.cam.smooth_move_to(*main.world, client->get_cam_coords(), client->get_window_size()); main.world->drawData.cam.smooth_move_to(*main.world, client->get_cam_coords(), client->get_window_size());
}}); }});
}); });
gui.pop_id(); });
} }
} }
} }
text_button(gui, "close list", "Done", { .wide = true, .onClick = [&] { text_button(gui, "close list", "Done", { .wide = true, .onClick = [&] {
playerMenuOpen = false; playerMenuOpen = false;
}}); }});
gui.pop_id(); });
} }
} }
@ -1856,7 +1864,7 @@ void Toolbar::general_settings_inner_gui() {
}) { }) {
switch(generalSettingsOptions) { switch(generalSettingsOptions) {
case GSETTINGS_GENERAL: { case GSETTINGS_GENERAL: {
gui.push_id("general settings"); gui.new_id("general settings", [&] {
input_text_field(gui, "display name input", "Display name", &main.displayName); input_text_field(gui, "display name input", "Display name", &main.displayName);
main.update_display_names(); main.update_display_names();
color_picker_button_field(gui, "defaultCanvasBackgroundColor", "Default canvas background color", &main.defaultCanvasBackgroundColor, { .hasAlpha = false }); color_picker_button_field(gui, "defaultCanvasBackgroundColor", "Default canvas background color", &main.defaultCanvasBackgroundColor, { .hasAlpha = false });
@ -1893,12 +1901,11 @@ void Toolbar::general_settings_inner_gui() {
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
checkbox_boolean_field(gui, "apply display scale", "Apply display scale", &main.window.applyDisplayScale); checkbox_boolean_field(gui, "apply display scale", "Apply display scale", &main.window.applyDisplayScale);
#endif #endif
});
gui.pop_id();
break; break;
} }
case GSETTINGS_TABLET: { case GSETTINGS_TABLET: {
gui.push_id("tablet settings"); gui.new_id("tablet settings", [&] {
checkbox_boolean_field(gui, "pen pressure width", "Pen pressure affects brush size", &tabletOptions.pressureAffectsBrushWidth); checkbox_boolean_field(gui, "pen pressure width", "Pen pressure affects brush size", &tabletOptions.pressureAffectsBrushWidth);
slider_scalar_field(gui, "smoothing time", "Smoothing sampling time", &tabletOptions.smoothingSamplingTime, 0.001f, 1.0f, {.decimalPrecision = 3}); slider_scalar_field(gui, "smoothing time", "Smoothing sampling time", &tabletOptions.smoothingSamplingTime, 0.001f, 1.0f, {.decimalPrecision = 3});
input_scalar_field<uint8_t>(gui, "middle click", "Middle click pen button", &tabletOptions.middleClickButton, 1, 255); input_scalar_field<uint8_t>(gui, "middle click", "Middle click pen button", &tabletOptions.middleClickButton, 1, 255);
@ -1908,11 +1915,11 @@ void Toolbar::general_settings_inner_gui() {
#ifdef _WIN32 #ifdef _WIN32
checkbox_boolean_field(gui, "mouse ignore when pen proximity", "Ignore mouse movement when pen in proximity", &tabletOptions.ignoreMouseMovementWhenPenInProximity); checkbox_boolean_field(gui, "mouse ignore when pen proximity", "Ignore mouse movement when pen in proximity", &tabletOptions.ignoreMouseMovementWhenPenInProximity);
#endif #endif
gui.pop_id(); });
break; break;
} }
case GSETTINGS_THEME: { case GSETTINGS_THEME: {
gui.push_id("theme"); gui.new_id("theme", [&] {
if(!themeData.selectedThemeIndex) if(!themeData.selectedThemeIndex)
reload_theme_list(); reload_theme_list();
@ -1979,7 +1986,7 @@ void Toolbar::general_settings_inner_gui() {
input_scalar_field<uint16_t>(gui, "childGap1", "Gap between child elements", &io->theme->childGap1, 0, 30); input_scalar_field<uint16_t>(gui, "childGap1", "Gap between child elements", &io->theme->childGap1, 0, 30);
input_scalar_field<uint16_t>(gui, "padding1", "Window padding", &io->theme->padding1, 0, 30); input_scalar_field<uint16_t>(gui, "padding1", "Window padding", &io->theme->padding1, 0, 30);
slider_scalar_field<float>(gui, "windowCorners1", "Window corner radius", &io->theme->windowCorners1, 0, 30); slider_scalar_field<float>(gui, "windowCorners1", "Window corner radius", &io->theme->windowCorners1, 0, 30);
gui.pop_id(); });
break; break;
} }
case GSETTINGS_KEYBINDS: { case GSETTINGS_KEYBINDS: {
@ -2000,9 +2007,9 @@ void Toolbar::general_settings_inner_gui() {
} }
} }
gui.push_id("keybind entries"); gui.new_id("keybind entries", [&] {
for(unsigned i = 0; i < InputManager::KEY_ASSIGNABLE_COUNT; i++) { for(unsigned i = 0; i < InputManager::KEY_ASSIGNABLE_COUNT; i++) {
gui.push_id(i); gui.new_id(i, [&] {
CLAY_AUTO_ID({ CLAY_AUTO_ID({
.layout = { .layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0) }, .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0) },
@ -2025,13 +2032,13 @@ void Toolbar::general_settings_inner_gui() {
} }
}); });
} }
gui.pop_id(); });
} }
gui.pop_id(); });
break; break;
} }
case GSETTINGS_DEBUG: { case GSETTINGS_DEBUG: {
gui.push_id("debug settings menu"); gui.new_id("debug settings menu", [&] {
checkbox_boolean_field(gui, "show performance metrics", "Show metrics", &showPerformance); checkbox_boolean_field(gui, "show performance metrics", "Show metrics", &showPerformance);
input_scalars_field(gui, "jump transition easing", "Jump easing", &jumpTransitionEasing, 4, -10.0f, 10.0f, { .decimalPrecision = 2 }); input_scalars_field(gui, "jump transition easing", "Jump easing", &jumpTransitionEasing, 4, -10.0f, 10.0f, { .decimalPrecision = 2 });
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
@ -2050,7 +2057,7 @@ void Toolbar::general_settings_inner_gui() {
input_scalar_field<size_t>(gui, "components to force cache rebuild", "Number of components to force cache rebuild", &DrawingProgramCache::MINIMUM_COMPONENTS_TO_START_REBUILD, 1, 1000000); input_scalar_field<size_t>(gui, "components to force cache rebuild", "Number of components to force cache rebuild", &DrawingProgramCache::MINIMUM_COMPONENTS_TO_START_REBUILD, 1, 1000000);
input_scalar_field<size_t>(gui, "maximum frame time to force cache rebuild", "Maximum frame time to force cache rebuild (ms)", &DrawingProgramCache::MILLISECOND_FRAME_TIME_TO_FORCE_CACHE_REFRESH, 1, 1000000); input_scalar_field<size_t>(gui, "maximum frame time to force cache rebuild", "Maximum frame time to force cache rebuild (ms)", &DrawingProgramCache::MILLISECOND_FRAME_TIME_TO_FORCE_CACHE_REFRESH, 1, 1000000);
input_scalar_field<size_t>(gui, "minimum time to force cache rebuild", "Minimum time to check cache rebuild (ms)", &DrawingProgramCache::MILLISECOND_MINIMUM_TIME_TO_CHECK_FORCE_REFRESH, 1, 1000000); input_scalar_field<size_t>(gui, "minimum time to force cache rebuild", "Minimum time to check cache rebuild (ms)", &DrawingProgramCache::MILLISECOND_MINIMUM_TIME_TO_CHECK_FORCE_REFRESH, 1, 1000000);
gui.pop_id(); });
break; break;
} }
} }
@ -2069,7 +2076,7 @@ void Toolbar::general_settings_inner_gui() {
void Toolbar::about_menu_inner_gui() { void Toolbar::about_menu_inner_gui() {
left_to_right_line_layout(gui, [&]() { left_to_right_line_layout(gui, [&]() {
gui.push_id("Menu Selector"); gui.new_id("Menu Selector", [&] {
CLAY_AUTO_ID({ CLAY_AUTO_ID({
.layout = { .layout = {
.sizing = {.width = CLAY_SIZING_FIT(200), .height = CLAY_SIZING_FIT(0) }, .sizing = {.width = CLAY_SIZING_FIT(200), .height = CLAY_SIZING_FIT(0) },
@ -2100,19 +2107,20 @@ void Toolbar::about_menu_inner_gui() {
.padding = CLAY_PADDING_ALL(1) .padding = CLAY_PADDING_ALL(1)
} }
}) { }) {
gui.push_id(i); gui.new_id(i, [&] {
text_button(gui, "noticebutton", thirdPartyLicenses[i].first, { text_button(gui, "noticebutton", thirdPartyLicenses[i].first, {
.drawType = SelectableButton::DrawType::TRANSPARENT_ALL, .drawType = SelectableButton::DrawType::TRANSPARENT_ALL,
.isSelected = selectedLicense == i, .isSelected = selectedLicense == i,
.wide = true, .wide = true,
.onClick = [&, i] { selectedLicense = i; } .onClick = [&, i] { selectedLicense = i; }
}); });
});
} }
} }
} }
}); });
} }
gui.pop_id(); });
gui.element<ScrollArea>("About Menu Text Scroll Area", ScrollArea::Options{ gui.element<ScrollArea>("About Menu Text Scroll Area", ScrollArea::Options{
.scrollVertical = true, .scrollVertical = true,