Fixed multiple segfaults
This commit is contained in:
parent
b4c35124c3
commit
2ad5684594
32 changed files with 1035 additions and 1010 deletions
|
|
@ -329,49 +329,50 @@ void DrawingProgram::toolbar_gui() {
|
|||
using namespace ElementHelpers;
|
||||
|
||||
Toolbar& t = world.main.toolbar;
|
||||
t.gui.push_id("Drawing Program Toolbar GUI");
|
||||
t.gui.element<LayoutElement>("Drawing Program Toolbar GUI", [&] {
|
||||
CLAY_AUTO_ID({
|
||||
.layout = {
|
||||
.sizing = {.width = CLAY_SIZING_FIT(0), .height = CLAY_SIZING_FIT(0)},
|
||||
.padding = CLAY_PADDING_ALL(static_cast<uint16_t>(t.io->theme->padding1 / 2)),
|
||||
.childGap = static_cast<uint16_t>(t.io->theme->childGap1 / 2),
|
||||
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP},
|
||||
.layoutDirection = CLAY_TOP_TO_BOTTOM
|
||||
},
|
||||
.backgroundColor = convert_vec4<Clay_Color>(t.io->theme->backColor1),
|
||||
.cornerRadius = CLAY_CORNER_RADIUS(t.io->theme->windowCorners1)
|
||||
}) {
|
||||
t.gui.new_id("Drawing Program Toolbar GUI", [&] {
|
||||
t.gui.element<LayoutElement>("Drawing Program Toolbar GUI", [&] {
|
||||
CLAY_AUTO_ID({
|
||||
.layout = {
|
||||
.sizing = {.width = CLAY_SIZING_FIT(0), .height = CLAY_SIZING_FIT(0)},
|
||||
.padding = CLAY_PADDING_ALL(static_cast<uint16_t>(t.io->theme->padding1 / 2)),
|
||||
.childGap = static_cast<uint16_t>(t.io->theme->childGap1 / 2),
|
||||
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP},
|
||||
.layoutDirection = CLAY_TOP_TO_BOTTOM
|
||||
},
|
||||
.backgroundColor = convert_vec4<Clay_Color>(t.io->theme->backColor1),
|
||||
.cornerRadius = CLAY_CORNER_RADIUS(t.io->theme->windowCorners1)
|
||||
}) {
|
||||
|
||||
auto tool_button = [&](const char* id, const std::string& svgPath, DrawingProgramToolType toolType) {
|
||||
svg_icon_button(t.gui, id, svgPath, {
|
||||
.drawType = SelectableButton::DrawType::TRANSPARENT_ALL,
|
||||
.isSelected = drawTool->get_type() == toolType,
|
||||
.onClick = [&, toolType] {
|
||||
switch_to_tool(toolType);
|
||||
}
|
||||
auto tool_button = [&](const char* id, const std::string& svgPath, DrawingProgramToolType toolType) {
|
||||
svg_icon_button(t.gui, id, svgPath, {
|
||||
.drawType = SelectableButton::DrawType::TRANSPARENT_ALL,
|
||||
.isSelected = drawTool->get_type() == toolType,
|
||||
.onClick = [&, toolType] {
|
||||
switch_to_tool(toolType);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
tool_button("Brush Toolbar Button", "data/icons/brush.svg", DrawingProgramToolType::BRUSH);
|
||||
tool_button("Eraser Toolbar Button", "data/icons/eraser.svg", DrawingProgramToolType::ERASER);
|
||||
tool_button("Line Toolbar Button", "data/icons/line.svg", DrawingProgramToolType::LINE);
|
||||
tool_button("Text Toolbar Button", "data/icons/text.svg", DrawingProgramToolType::TEXTBOX);
|
||||
tool_button("Ellipse Toolbar Button", "data/icons/circle.svg", DrawingProgramToolType::ELLIPSE);
|
||||
tool_button("Rect Toolbar Button", "data/icons/rectangle.svg", DrawingProgramToolType::RECTANGLE);
|
||||
tool_button("RectSelect Toolbar Button", "data/icons/rectselect.svg", DrawingProgramToolType::RECTSELECT);
|
||||
tool_button("LassoSelect Toolbar Button", "data/icons/lassoselect.svg", DrawingProgramToolType::LASSOSELECT);
|
||||
tool_button("Edit Toolbar Button", "data/icons/cursor.svg", DrawingProgramToolType::EDIT);
|
||||
tool_button("Eyedropper Toolbar Button", "data/icons/eyedropper.svg", DrawingProgramToolType::EYEDROPPER);
|
||||
tool_button("Zoom Canvas Toolbar Button", "data/icons/zoom.svg", DrawingProgramToolType::ZOOM);
|
||||
tool_button("Pan Canvas Toolbar Button", "data/icons/hand.svg", DrawingProgramToolType::PAN);
|
||||
|
||||
std::shared_ptr<double> oldRotationAngle = std::make_shared<double>(world.drawData.cam.c.rotation);
|
||||
t.gui.element<RotateWheel>("Canvas Rotate Wheel", &world.drawData.cam.c.rotation, [&, oldRotationAngle] {
|
||||
world.drawData.cam.c.rotate_about(world.drawData.cam.c.from_space(world.main.window.size.cast<float>() * 0.5f), world.drawData.cam.c.rotation - *oldRotationAngle);
|
||||
*oldRotationAngle = world.drawData.cam.c.rotation;
|
||||
});
|
||||
};
|
||||
|
||||
tool_button("Brush Toolbar Button", "data/icons/brush.svg", DrawingProgramToolType::BRUSH);
|
||||
tool_button("Eraser Toolbar Button", "data/icons/eraser.svg", DrawingProgramToolType::ERASER);
|
||||
tool_button("Line Toolbar Button", "data/icons/line.svg", DrawingProgramToolType::LINE);
|
||||
tool_button("Text Toolbar Button", "data/icons/text.svg", DrawingProgramToolType::TEXTBOX);
|
||||
tool_button("Ellipse Toolbar Button", "data/icons/circle.svg", DrawingProgramToolType::ELLIPSE);
|
||||
tool_button("Rect Toolbar Button", "data/icons/rectangle.svg", DrawingProgramToolType::RECTANGLE);
|
||||
tool_button("RectSelect Toolbar Button", "data/icons/rectselect.svg", DrawingProgramToolType::RECTSELECT);
|
||||
tool_button("LassoSelect Toolbar Button", "data/icons/lassoselect.svg", DrawingProgramToolType::LASSOSELECT);
|
||||
tool_button("Edit Toolbar Button", "data/icons/cursor.svg", DrawingProgramToolType::EDIT);
|
||||
tool_button("Eyedropper Toolbar Button", "data/icons/eyedropper.svg", DrawingProgramToolType::EYEDROPPER);
|
||||
tool_button("Zoom Canvas Toolbar Button", "data/icons/zoom.svg", DrawingProgramToolType::ZOOM);
|
||||
tool_button("Pan Canvas Toolbar Button", "data/icons/hand.svg", DrawingProgramToolType::PAN);
|
||||
|
||||
std::shared_ptr<double> oldRotationAngle = std::make_shared<double>(world.drawData.cam.c.rotation);
|
||||
t.gui.element<RotateWheel>("Canvas Rotate Wheel", &world.drawData.cam.c.rotation, [&, oldRotationAngle] {
|
||||
world.drawData.cam.c.rotate_about(world.drawData.cam.c.from_space(world.main.window.size.cast<float>() * 0.5f), world.drawData.cam.c.rotation - *oldRotationAngle);
|
||||
*oldRotationAngle = world.drawData.cam.c.rotation;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -422,9 +423,9 @@ void DrawingProgram::selection_action_menu(Vector2f popupPos) {
|
|||
|
||||
void DrawingProgram::right_click_popup_gui(Vector2f popupPos) {
|
||||
Toolbar& t = world.main.toolbar;
|
||||
t.gui.push_id("Drawing Program right click GUI");
|
||||
drawTool->right_click_popup_gui(popupPos);
|
||||
t.gui.pop_id();
|
||||
t.gui.new_id("Drawing Program right click GUI", [&] {
|
||||
drawTool->right_click_popup_gui(popupPos);
|
||||
});
|
||||
}
|
||||
|
||||
void DrawingProgram::tool_options_gui() {
|
||||
|
|
|
|||
|
|
@ -36,24 +36,24 @@ void DrawingProgramSelection::selection_gui() {
|
|||
using namespace ElementHelpers;
|
||||
|
||||
auto& t = drawP.world.main.toolbar;
|
||||
t.gui.push_id("general selection gui");
|
||||
text_label(t.gui, "Select from:");
|
||||
radio_button_selector(t.gui, "layer selector", &drawP.controls.layerSelector, {
|
||||
{"Layer being edited", DrawingProgramLayerManager::LayerSelector::LAYER_BEING_EDITED},
|
||||
{"All visible layers", DrawingProgramLayerManager::LayerSelector::ALL_VISIBLE_LAYERS}
|
||||
});
|
||||
if(is_something_selected()) {
|
||||
left_to_right_line_layout(t.gui, [&]() {
|
||||
//if(t.gui.color_button_big("Stroke Color Button", &strokeColorChangeData.newColor, &strokeColorChangeData.newColor == t.colorRight)) {
|
||||
// if(strokeColorChangeData.newColor.w() == 0.0f)
|
||||
// strokeColorChangeData.newColor.w() = 1.0f;
|
||||
// t.color_selector_right(&strokeColorChangeData.newColor == t.colorRight ? nullptr : &strokeColorChangeData.newColor);
|
||||
//}
|
||||
text_label(t.gui, "Stroke Color");
|
||||
t.gui.new_id("general selection gui", [&] {
|
||||
text_label(t.gui, "Select from:");
|
||||
radio_button_selector(t.gui, "layer selector", &drawP.controls.layerSelector, {
|
||||
{"Layer being edited", DrawingProgramLayerManager::LayerSelector::LAYER_BEING_EDITED},
|
||||
{"All visible layers", DrawingProgramLayerManager::LayerSelector::ALL_VISIBLE_LAYERS}
|
||||
});
|
||||
update_selection_stroke_color();
|
||||
}
|
||||
t.gui.pop_id();
|
||||
if(is_something_selected()) {
|
||||
left_to_right_line_layout(t.gui, [&]() {
|
||||
//if(t.gui.color_button_big("Stroke Color Button", &strokeColorChangeData.newColor, &strokeColorChangeData.newColor == t.colorRight)) {
|
||||
// if(strokeColorChangeData.newColor.w() == 0.0f)
|
||||
// strokeColorChangeData.newColor.w() = 1.0f;
|
||||
// t.color_selector_right(&strokeColorChangeData.newColor == t.colorRight ? nullptr : &strokeColorChangeData.newColor);
|
||||
//}
|
||||
text_label(t.gui, "Stroke Color");
|
||||
});
|
||||
update_selection_stroke_color();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void DrawingProgramSelection::update_selection_stroke_color() {
|
||||
|
|
|
|||
|
|
@ -172,11 +172,11 @@ void BrushTool::gui_toolbox() {
|
|||
using namespace ElementHelpers;
|
||||
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
t.gui.push_id("brush tool");
|
||||
text_label_centered(t.gui, "Brush");
|
||||
checkbox_boolean_field(t.gui, "hasroundcaps", "Round Caps", &drawP.world.main.toolConfig.brush.hasRoundCaps);
|
||||
drawP.world.main.toolConfig.relative_width_gui(drawP, "Size");
|
||||
t.gui.pop_id();
|
||||
t.gui.new_id("brush tool", [&] {
|
||||
text_label_centered(t.gui, "Brush");
|
||||
checkbox_boolean_field(t.gui, "hasroundcaps", "Round Caps", &drawP.world.main.toolConfig.brush.hasRoundCaps);
|
||||
drawP.world.main.toolConfig.relative_width_gui(drawP, "Size");
|
||||
});
|
||||
}
|
||||
|
||||
void BrushTool::right_click_popup_gui(Vector2f popupPos) {
|
||||
|
|
|
|||
|
|
@ -33,9 +33,9 @@ void EditTool::gui_toolbox() {
|
|||
if(objInfoBeingEdited)
|
||||
compEditTool->edit_gui(objInfoBeingEdited);
|
||||
else {
|
||||
t.gui.push_id("edit tool");
|
||||
text_label_centered(t.gui, "Edit");
|
||||
t.gui.pop_id();
|
||||
t.gui.new_id("edit tool", [&] {
|
||||
text_label_centered(t.gui, "Edit");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,14 +16,14 @@ void BrushEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
|
|||
using namespace ElementHelpers;
|
||||
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
t.gui.push_id("edit tool brush");
|
||||
text_label_centered(t.gui, "Edit Brush Stroke");
|
||||
left_to_right_line_layout(t.gui, [&]() {
|
||||
//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);
|
||||
text_label(t.gui, "Outline Color");
|
||||
t.gui.new_id("edit tool brush", [&] {
|
||||
text_label_centered(t.gui, "Edit Brush Stroke");
|
||||
left_to_right_line_layout(t.gui, [&]() {
|
||||
//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);
|
||||
text_label(t.gui, "Outline Color");
|
||||
});
|
||||
});
|
||||
t.gui.pop_id();
|
||||
}
|
||||
|
||||
void BrushEditTool::edit_start(EditTool& editTool, CanvasComponentContainer::ObjInfo* comp, std::any& prevData) {
|
||||
|
|
|
|||
|
|
@ -23,29 +23,29 @@ void EllipseDrawEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
|
|||
auto& a = static_cast<EllipseCanvasComponent&>(comp->obj->get_comp());
|
||||
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
t.gui.push_id("edit tool ellipse");
|
||||
text_label_centered(t.gui, "Edit Ellipse");
|
||||
radio_button_selector(t.gui, "Fill selector", &a.d.fillStrokeMode, {
|
||||
{"Fill only", 0},
|
||||
{"Outline only", 1},
|
||||
{"Fill and outline", 2}
|
||||
t.gui.new_id("edit tool ellipse", [&] {
|
||||
text_label_centered(t.gui, "Edit Ellipse");
|
||||
radio_button_selector(t.gui, "Fill selector", &a.d.fillStrokeMode, {
|
||||
{"Fill only", 0},
|
||||
{"Outline only", 1},
|
||||
{"Fill and outline", 2}
|
||||
});
|
||||
if(a.d.fillStrokeMode == 0 || a.d.fillStrokeMode == 2) {
|
||||
left_to_right_line_layout(t.gui, [&] {
|
||||
//if(t.gui.color_button_big("Fill Color", &a.d.fillColor, &a.d.fillColor == t.colorRight))
|
||||
// t.color_selector_right(&a.d.fillColor == t.colorRight ? nullptr : &a.d.fillColor);
|
||||
text_label(t.gui, "Fill Color");
|
||||
});
|
||||
}
|
||||
if(a.d.fillStrokeMode == 1 || a.d.fillStrokeMode == 2) {
|
||||
slider_scalar_field(t.gui, "relstrokewidth", "Outline Size", &a.d.strokeWidth, 3.0f, 40.0f);
|
||||
left_to_right_line_layout(t.gui, [&] {
|
||||
//if(t.gui.color_button_big("Outline Color", &a.d.strokeColor, &a.d.strokeColor == t.colorRight))
|
||||
// t.color_selector_right(&a.d.strokeColor == t.colorRight ? nullptr : &a.d.strokeColor);
|
||||
text_label(t.gui, "Outline Color");
|
||||
});
|
||||
}
|
||||
});
|
||||
if(a.d.fillStrokeMode == 0 || a.d.fillStrokeMode == 2) {
|
||||
left_to_right_line_layout(t.gui, [&] {
|
||||
//if(t.gui.color_button_big("Fill Color", &a.d.fillColor, &a.d.fillColor == t.colorRight))
|
||||
// t.color_selector_right(&a.d.fillColor == t.colorRight ? nullptr : &a.d.fillColor);
|
||||
text_label(t.gui, "Fill Color");
|
||||
});
|
||||
}
|
||||
if(a.d.fillStrokeMode == 1 || a.d.fillStrokeMode == 2) {
|
||||
slider_scalar_field(t.gui, "relstrokewidth", "Outline Size", &a.d.strokeWidth, 3.0f, 40.0f);
|
||||
left_to_right_line_layout(t.gui, [&] {
|
||||
//if(t.gui.color_button_big("Outline Color", &a.d.strokeColor, &a.d.strokeColor == t.colorRight))
|
||||
// t.color_selector_right(&a.d.strokeColor == t.colorRight ? nullptr : &a.d.strokeColor);
|
||||
text_label(t.gui, "Outline Color");
|
||||
});
|
||||
}
|
||||
t.gui.pop_id();
|
||||
}
|
||||
|
||||
void EllipseDrawEditTool::edit_start(EditTool& editTool, CanvasComponentContainer::ObjInfo* comp, std::any& prevData) {
|
||||
|
|
|
|||
|
|
@ -51,29 +51,29 @@ void ImageEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
|
|||
|
||||
ImageCanvasComponent& a = static_cast<ImageCanvasComponent&>(comp->obj->get_comp());
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
t.gui.push_id("edit tool image");
|
||||
text_label_centered(t.gui, "File Properties");
|
||||
auto resourceData = drawP.world.netObjMan.get_obj_temporary_ref_from_id<ResourceData>(a.d.imageID);
|
||||
t.gui.new_id("edit tool image", [&] {
|
||||
text_label_centered(t.gui, "File Properties");
|
||||
auto resourceData = drawP.world.netObjMan.get_obj_temporary_ref_from_id<ResourceData>(a.d.imageID);
|
||||
|
||||
if(resourceData) {
|
||||
text_label(t.gui, "Name: " + resourceData->name);
|
||||
text_button(t.gui, "file download", "Download file", {
|
||||
.wide = true,
|
||||
.onClick = [&] {
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_browser_file::download(
|
||||
resourceData->name,
|
||||
"application/octet-binary",
|
||||
*resourceData->data
|
||||
);
|
||||
#endif
|
||||
t.open_file_selector("Download File", {{"Any File", "*"}}, [resourceData](const std::filesystem::path& p, const auto& e) {
|
||||
SDL_SaveFile(p.c_str(), resourceData->data->c_str(), resourceData->data->size());
|
||||
}, resourceData->name, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
text_label_centered(t.gui, "Loading resource...");
|
||||
t.gui.pop_id();
|
||||
if(resourceData) {
|
||||
text_label(t.gui, "Name: " + resourceData->name);
|
||||
text_button(t.gui, "file download", "Download file", {
|
||||
.wide = true,
|
||||
.onClick = [&] {
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_browser_file::download(
|
||||
resourceData->name,
|
||||
"application/octet-binary",
|
||||
*resourceData->data
|
||||
);
|
||||
#endif
|
||||
t.open_file_selector("Download File", {{"Any File", "*"}}, [resourceData](const std::filesystem::path& p, const auto& e) {
|
||||
SDL_SaveFile(p.c_str(), resourceData->data->c_str(), resourceData->data->size());
|
||||
}, resourceData->name, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
text_label_centered(t.gui, "Loading resource...");
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,30 +19,30 @@ void RectDrawEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
|
|||
|
||||
auto& a = static_cast<RectangleCanvasComponent&>(comp->obj->get_comp());
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
t.gui.push_id("edit tool rectangle");
|
||||
text_label_centered(t.gui, "Edit Rectangle");
|
||||
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, {
|
||||
{"Fill only", 0},
|
||||
{"Outline only", 1},
|
||||
{"Fill and outline", 2}
|
||||
t.gui.new_id("edit tool rectangle", [&] {
|
||||
text_label_centered(t.gui, "Edit Rectangle");
|
||||
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, {
|
||||
{"Fill only", 0},
|
||||
{"Outline only", 1},
|
||||
{"Fill and outline", 2}
|
||||
});
|
||||
if(a.d.fillStrokeMode == 0 || a.d.fillStrokeMode == 2) {
|
||||
left_to_right_line_layout(t.gui, [&] {
|
||||
//if(t.gui.color_button_big("Fill Color", &a.d.fillColor, &a.d.fillColor == t.colorRight))
|
||||
// t.color_selector_right(&a.d.fillColor == t.colorRight ? nullptr : &a.d.fillColor);
|
||||
text_label(t.gui, "Fill Color");
|
||||
});
|
||||
}
|
||||
if(a.d.fillStrokeMode == 1 || a.d.fillStrokeMode == 2) {
|
||||
slider_scalar_field(t.gui, "relstrokewidth", "Outline Size", &a.d.strokeWidth, 3.0f, 40.0f);
|
||||
left_to_right_line_layout(t.gui, [&] {
|
||||
//if(t.gui.color_button_big("Outline Color", &a.d.strokeColor, &a.d.strokeColor == t.colorRight))
|
||||
// t.color_selector_right(&a.d.strokeColor == t.colorRight ? nullptr : &a.d.strokeColor);
|
||||
text_label(t.gui, "Outline Color");
|
||||
});
|
||||
}
|
||||
});
|
||||
if(a.d.fillStrokeMode == 0 || a.d.fillStrokeMode == 2) {
|
||||
left_to_right_line_layout(t.gui, [&] {
|
||||
//if(t.gui.color_button_big("Fill Color", &a.d.fillColor, &a.d.fillColor == t.colorRight))
|
||||
// t.color_selector_right(&a.d.fillColor == t.colorRight ? nullptr : &a.d.fillColor);
|
||||
text_label(t.gui, "Fill Color");
|
||||
});
|
||||
}
|
||||
if(a.d.fillStrokeMode == 1 || a.d.fillStrokeMode == 2) {
|
||||
slider_scalar_field(t.gui, "relstrokewidth", "Outline Size", &a.d.strokeWidth, 3.0f, 40.0f);
|
||||
left_to_right_line_layout(t.gui, [&] {
|
||||
//if(t.gui.color_button_big("Outline Color", &a.d.strokeColor, &a.d.strokeColor == t.colorRight))
|
||||
// t.color_selector_right(&a.d.strokeColor == t.colorRight ? nullptr : &a.d.strokeColor);
|
||||
text_label(t.gui, "Outline Color");
|
||||
});
|
||||
}
|
||||
t.gui.pop_id();
|
||||
}
|
||||
|
||||
void RectDrawEditTool::edit_start(EditTool& editTool, CanvasComponentContainer::ObjInfo* comp, std::any& prevData) {
|
||||
|
|
|
|||
|
|
@ -33,122 +33,122 @@ void TextBoxEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
|
|||
|
||||
auto& currentMods = *currentModsPtr;
|
||||
|
||||
t.gui.push_id("edit tool text");
|
||||
text_label_centered(t.gui, "Edit Text");
|
||||
t.gui.new_id("edit tool text", [&] {
|
||||
text_label_centered(t.gui, "Edit Text");
|
||||
|
||||
left_to_right_line_layout(t.gui, [&] {
|
||||
text_label(t.gui, "Font");
|
||||
//if(t.gui.font_picker("font picker", &newFontName)) {
|
||||
// currentMods[TextStyleModifier::ModifierType::FONT_FAMILIES] = std::make_shared<FontFamiliesTextStyleModifier>(std::vector<SkString>{SkString{newFontName.c_str(), newFontName.size()}});
|
||||
// add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::FONT_FAMILIES]);});
|
||||
left_to_right_line_layout(t.gui, [&] {
|
||||
text_label(t.gui, "Font");
|
||||
//if(t.gui.font_picker("font picker", &newFontName)) {
|
||||
// currentMods[TextStyleModifier::ModifierType::FONT_FAMILIES] = std::make_shared<FontFamiliesTextStyleModifier>(std::vector<SkString>{SkString{newFontName.c_str(), newFontName.size()}});
|
||||
// add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::FONT_FAMILIES]);});
|
||||
//}
|
||||
});
|
||||
|
||||
//left_to_right_line_centered_layout(t.gui, [&] {
|
||||
// if(svg_icon_button("Bold button", "data/icons/RemixIcon/bold.svg", newIsBold)) {
|
||||
// newIsBold = !newIsBold;
|
||||
// currentMods[TextStyleModifier::ModifierType::WEIGHT] = std::make_shared<WeightTextStyleModifier>(newIsBold ? SkFontStyle::Weight::kBold_Weight : SkFontStyle::Weight::kNormal_Weight);
|
||||
// add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::WEIGHT]);});
|
||||
// }
|
||||
|
||||
// if(t.gui.svg_icon_button("Italic button", "data/icons/RemixIcon/italic.svg", newIsItalic)) {
|
||||
// newIsItalic = !newIsItalic;
|
||||
// currentMods[TextStyleModifier::ModifierType::SLANT] = std::make_shared<SlantTextStyleModifier>(newIsItalic ? SkFontStyle::Slant::kItalic_Slant : SkFontStyle::Slant::kUpright_Slant);
|
||||
// add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::SLANT]);});
|
||||
// }
|
||||
|
||||
// bool decorationEdited = false;
|
||||
// if(t.gui.svg_icon_button("Underline button", "data/icons/RemixIcon/underline.svg", newIsUnderlined)) {
|
||||
// newIsUnderlined = !newIsUnderlined;
|
||||
// decorationEdited = true;
|
||||
// }
|
||||
// if(t.gui.svg_icon_button("Strikethrough button", "data/icons/RemixIcon/strikethrough.svg", newIsLinethrough)) {
|
||||
// newIsLinethrough = !newIsLinethrough;
|
||||
// decorationEdited = true;
|
||||
// }
|
||||
// if(t.gui.svg_icon_button("Overline button", "data/icons/RemixIcon/overline.svg", newIsOverline)) {
|
||||
// newIsOverline = !newIsOverline;
|
||||
// decorationEdited = true;
|
||||
// }
|
||||
// if(decorationEdited) {
|
||||
// currentMods[TextStyleModifier::ModifierType::DECORATION] = std::make_shared<DecorationTextStyleModifier>(get_new_decoration_value());
|
||||
// add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::DECORATION]);});
|
||||
// }
|
||||
//});
|
||||
|
||||
//t.gui.left_to_right_line_centered_layout([&]() {
|
||||
// if(t.gui.svg_icon_button("Align left button", "data/icons/RemixIcon/align-left.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kLeft))
|
||||
// add_undo([&](){a.textBox->set_text_alignment_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextAlign::kLeft);});
|
||||
// if(t.gui.svg_icon_button("Align center button", "data/icons/RemixIcon/align-center.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kCenter))
|
||||
// add_undo([&](){a.textBox->set_text_alignment_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextAlign::kCenter);});
|
||||
// if(t.gui.svg_icon_button("Align right button", "data/icons/RemixIcon/align-right.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kRight))
|
||||
// add_undo([&](){a.textBox->set_text_alignment_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextAlign::kRight);});
|
||||
// if(t.gui.svg_icon_button("Align justify button", "data/icons/RemixIcon/align-justify.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kJustify))
|
||||
// add_undo([&](){a.textBox->set_text_alignment_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextAlign::kJustify);});
|
||||
// if(t.gui.svg_icon_button("Text direction left", "data/icons/RemixIcon/text-direction-l.svg", currentPStyle.textDirection == skia::textlayout::TextDirection::kLtr))
|
||||
// add_undo([&](){a.textBox->set_text_direction_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextDirection::kLtr);});
|
||||
// if(t.gui.svg_icon_button("Text direction right", "data/icons/RemixIcon/text-direction-r.svg", currentPStyle.textDirection == skia::textlayout::TextDirection::kRtl))
|
||||
// add_undo([&](){a.textBox->set_text_direction_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextDirection::kRtl);});
|
||||
//});
|
||||
|
||||
//if(t.gui.slider_scalar_field<uint32_t>("Font Size Slider", "Font Size", &newFontSize, 3, 100)) {
|
||||
// hold_undo_data("Font Size", a);
|
||||
// currentMods[TextStyleModifier::ModifierType::SIZE] = std::make_shared<SizeTextStyleModifier>(newFontSize);
|
||||
// a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::SIZE]);
|
||||
//}
|
||||
//else
|
||||
// release_undo_data("Font Size");
|
||||
|
||||
//// Text color
|
||||
//t.gui.left_to_right_line_layout([&]() {
|
||||
// if(t.gui.color_button_big("Text Color", &newTextColor, &newTextColor == t.colorRight))
|
||||
// t.color_selector_right(&newTextColor == t.colorRight ? nullptr : &newTextColor);
|
||||
// t.gui.text_label("Text Color");
|
||||
//});
|
||||
|
||||
//if(&newTextColor == t.colorRight)
|
||||
// hold_undo_data("Text Color", a);
|
||||
//else
|
||||
// release_undo_data("Text Color");
|
||||
|
||||
//if((&newTextColor == t.colorRight) && t.isUpdatingColorRight) {
|
||||
// currentMods[TextStyleModifier::ModifierType::COLOR] = std::make_shared<ColorTextStyleModifier>(newTextColor);
|
||||
// a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::COLOR]);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
//// Highlight color
|
||||
//t.gui.left_to_right_line_layout([&]() {
|
||||
// if(t.gui.color_button_big("Highlight Color", &newHighlightColor, &newHighlightColor == t.colorRight)) {
|
||||
// if(newHighlightColor.w() == 0.0f) { // Make highlight appear when the button is pressed
|
||||
// newHighlightColor.w() = 1.0f;
|
||||
// currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR] = std::make_shared<HighlightColorTextStyleModifier>(newHighlightColor);
|
||||
// add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR]);});
|
||||
// }
|
||||
// t.color_selector_right(&newHighlightColor == t.colorRight ? nullptr : &newHighlightColor);
|
||||
// }
|
||||
// if(newHighlightColor.w() != 0.0f) {
|
||||
// if(t.gui.svg_icon_button("Remove Highlight Color", "data/icons/close.svg")) {
|
||||
// newHighlightColor = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
// currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR] = std::make_shared<HighlightColorTextStyleModifier>(newHighlightColor);
|
||||
// add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR]);});
|
||||
// }
|
||||
// }
|
||||
// t.gui.text_label("Highlight Color");
|
||||
//});
|
||||
|
||||
//if(&newHighlightColor == t.colorRight)
|
||||
// hold_undo_data("Highlight Color", a);
|
||||
//else
|
||||
// release_undo_data("Highlight Color");
|
||||
|
||||
//if((&newHighlightColor == t.colorRight) && t.isUpdatingColorRight) {
|
||||
// currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR] = std::make_shared<HighlightColorTextStyleModifier>(newHighlightColor);
|
||||
// a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR]);
|
||||
//}
|
||||
|
||||
});
|
||||
|
||||
//left_to_right_line_centered_layout(t.gui, [&] {
|
||||
// if(svg_icon_button("Bold button", "data/icons/RemixIcon/bold.svg", newIsBold)) {
|
||||
// newIsBold = !newIsBold;
|
||||
// currentMods[TextStyleModifier::ModifierType::WEIGHT] = std::make_shared<WeightTextStyleModifier>(newIsBold ? SkFontStyle::Weight::kBold_Weight : SkFontStyle::Weight::kNormal_Weight);
|
||||
// add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::WEIGHT]);});
|
||||
// }
|
||||
|
||||
// if(t.gui.svg_icon_button("Italic button", "data/icons/RemixIcon/italic.svg", newIsItalic)) {
|
||||
// newIsItalic = !newIsItalic;
|
||||
// currentMods[TextStyleModifier::ModifierType::SLANT] = std::make_shared<SlantTextStyleModifier>(newIsItalic ? SkFontStyle::Slant::kItalic_Slant : SkFontStyle::Slant::kUpright_Slant);
|
||||
// add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::SLANT]);});
|
||||
// }
|
||||
|
||||
// bool decorationEdited = false;
|
||||
// if(t.gui.svg_icon_button("Underline button", "data/icons/RemixIcon/underline.svg", newIsUnderlined)) {
|
||||
// newIsUnderlined = !newIsUnderlined;
|
||||
// decorationEdited = true;
|
||||
// }
|
||||
// if(t.gui.svg_icon_button("Strikethrough button", "data/icons/RemixIcon/strikethrough.svg", newIsLinethrough)) {
|
||||
// newIsLinethrough = !newIsLinethrough;
|
||||
// decorationEdited = true;
|
||||
// }
|
||||
// if(t.gui.svg_icon_button("Overline button", "data/icons/RemixIcon/overline.svg", newIsOverline)) {
|
||||
// newIsOverline = !newIsOverline;
|
||||
// decorationEdited = true;
|
||||
// }
|
||||
// if(decorationEdited) {
|
||||
// currentMods[TextStyleModifier::ModifierType::DECORATION] = std::make_shared<DecorationTextStyleModifier>(get_new_decoration_value());
|
||||
// add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::DECORATION]);});
|
||||
// }
|
||||
//});
|
||||
|
||||
//t.gui.left_to_right_line_centered_layout([&]() {
|
||||
// if(t.gui.svg_icon_button("Align left button", "data/icons/RemixIcon/align-left.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kLeft))
|
||||
// add_undo([&](){a.textBox->set_text_alignment_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextAlign::kLeft);});
|
||||
// if(t.gui.svg_icon_button("Align center button", "data/icons/RemixIcon/align-center.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kCenter))
|
||||
// add_undo([&](){a.textBox->set_text_alignment_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextAlign::kCenter);});
|
||||
// if(t.gui.svg_icon_button("Align right button", "data/icons/RemixIcon/align-right.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kRight))
|
||||
// add_undo([&](){a.textBox->set_text_alignment_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextAlign::kRight);});
|
||||
// if(t.gui.svg_icon_button("Align justify button", "data/icons/RemixIcon/align-justify.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kJustify))
|
||||
// add_undo([&](){a.textBox->set_text_alignment_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextAlign::kJustify);});
|
||||
// if(t.gui.svg_icon_button("Text direction left", "data/icons/RemixIcon/text-direction-l.svg", currentPStyle.textDirection == skia::textlayout::TextDirection::kLtr))
|
||||
// add_undo([&](){a.textBox->set_text_direction_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextDirection::kLtr);});
|
||||
// if(t.gui.svg_icon_button("Text direction right", "data/icons/RemixIcon/text-direction-r.svg", currentPStyle.textDirection == skia::textlayout::TextDirection::kRtl))
|
||||
// add_undo([&](){a.textBox->set_text_direction_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextDirection::kRtl);});
|
||||
//});
|
||||
|
||||
//if(t.gui.slider_scalar_field<uint32_t>("Font Size Slider", "Font Size", &newFontSize, 3, 100)) {
|
||||
// hold_undo_data("Font Size", a);
|
||||
// currentMods[TextStyleModifier::ModifierType::SIZE] = std::make_shared<SizeTextStyleModifier>(newFontSize);
|
||||
// a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::SIZE]);
|
||||
//}
|
||||
//else
|
||||
// release_undo_data("Font Size");
|
||||
|
||||
//// Text color
|
||||
//t.gui.left_to_right_line_layout([&]() {
|
||||
// if(t.gui.color_button_big("Text Color", &newTextColor, &newTextColor == t.colorRight))
|
||||
// t.color_selector_right(&newTextColor == t.colorRight ? nullptr : &newTextColor);
|
||||
// t.gui.text_label("Text Color");
|
||||
//});
|
||||
|
||||
//if(&newTextColor == t.colorRight)
|
||||
// hold_undo_data("Text Color", a);
|
||||
//else
|
||||
// release_undo_data("Text Color");
|
||||
|
||||
//if((&newTextColor == t.colorRight) && t.isUpdatingColorRight) {
|
||||
// currentMods[TextStyleModifier::ModifierType::COLOR] = std::make_shared<ColorTextStyleModifier>(newTextColor);
|
||||
// a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::COLOR]);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
//// Highlight color
|
||||
//t.gui.left_to_right_line_layout([&]() {
|
||||
// if(t.gui.color_button_big("Highlight Color", &newHighlightColor, &newHighlightColor == t.colorRight)) {
|
||||
// if(newHighlightColor.w() == 0.0f) { // Make highlight appear when the button is pressed
|
||||
// newHighlightColor.w() = 1.0f;
|
||||
// currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR] = std::make_shared<HighlightColorTextStyleModifier>(newHighlightColor);
|
||||
// add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR]);});
|
||||
// }
|
||||
// t.color_selector_right(&newHighlightColor == t.colorRight ? nullptr : &newHighlightColor);
|
||||
// }
|
||||
// if(newHighlightColor.w() != 0.0f) {
|
||||
// if(t.gui.svg_icon_button("Remove Highlight Color", "data/icons/close.svg")) {
|
||||
// newHighlightColor = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
// currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR] = std::make_shared<HighlightColorTextStyleModifier>(newHighlightColor);
|
||||
// add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR]);});
|
||||
// }
|
||||
// }
|
||||
// t.gui.text_label("Highlight Color");
|
||||
//});
|
||||
|
||||
//if(&newHighlightColor == t.colorRight)
|
||||
// hold_undo_data("Highlight Color", a);
|
||||
//else
|
||||
// release_undo_data("Highlight Color");
|
||||
|
||||
//if((&newHighlightColor == t.colorRight) && t.isUpdatingColorRight) {
|
||||
// currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR] = std::make_shared<HighlightColorTextStyleModifier>(newHighlightColor);
|
||||
// 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)
|
||||
// set_styles_at_selection(a);
|
||||
|
|
|
|||
|
|
@ -27,16 +27,16 @@ void EllipseDrawTool::gui_toolbox() {
|
|||
Toolbar& t = drawP.world.main.toolbar;
|
||||
auto& toolConfig = drawP.world.main.toolConfig;
|
||||
auto& fillStrokeMode = toolConfig.ellipseDraw.fillStrokeMode;
|
||||
t.gui.push_id("ellipse draw tool");
|
||||
text_label_centered(t.gui, "Draw Ellipse");
|
||||
radio_button_selector(t.gui, "fill type", &fillStrokeMode, {
|
||||
{"Fill only", 0},
|
||||
{"Outline only", 1},
|
||||
{"Fill and Outline", 2}
|
||||
t.gui.new_id("ellipse draw tool", [&] {
|
||||
text_label_centered(t.gui, "Draw Ellipse");
|
||||
radio_button_selector(t.gui, "fill type", &fillStrokeMode, {
|
||||
{"Fill only", 0},
|
||||
{"Outline only", 1},
|
||||
{"Fill and Outline", 2}
|
||||
});
|
||||
if(fillStrokeMode == 1 || fillStrokeMode == 2)
|
||||
toolConfig.relative_width_gui(drawP, "Outline Size");
|
||||
});
|
||||
if(fillStrokeMode == 1 || fillStrokeMode == 2)
|
||||
toolConfig.relative_width_gui(drawP, "Outline Size");
|
||||
t.gui.pop_id();
|
||||
}
|
||||
|
||||
void EllipseDrawTool::input_mouse_button_on_canvas_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||
|
|
|
|||
|
|
@ -21,15 +21,15 @@ void EraserTool::gui_toolbox() {
|
|||
using namespace ElementHelpers;
|
||||
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
t.gui.push_id("eraser tool");
|
||||
text_label_centered(t.gui, "Eraser");
|
||||
drawP.world.main.toolConfig.relative_width_gui(drawP, "Size");
|
||||
text_label(t.gui, "Erase from:");
|
||||
radio_button_selector(t.gui, "layer selector", &drawP.controls.layerSelector, {
|
||||
{"Layer being edited", DrawingProgramLayerManager::LayerSelector::LAYER_BEING_EDITED},
|
||||
{"All visible layers", DrawingProgramLayerManager::LayerSelector::ALL_VISIBLE_LAYERS}
|
||||
t.gui.new_id("eraser tool", [&] {
|
||||
text_label_centered(t.gui, "Eraser");
|
||||
drawP.world.main.toolConfig.relative_width_gui(drawP, "Size");
|
||||
text_label(t.gui, "Erase from:");
|
||||
radio_button_selector(t.gui, "layer selector", &drawP.controls.layerSelector, {
|
||||
{"Layer being edited", DrawingProgramLayerManager::LayerSelector::LAYER_BEING_EDITED},
|
||||
{"All visible layers", DrawingProgramLayerManager::LayerSelector::ALL_VISIBLE_LAYERS}
|
||||
});
|
||||
});
|
||||
t.gui.pop_id();
|
||||
}
|
||||
|
||||
void EraserTool::right_click_popup_gui(Vector2f popupPos) {
|
||||
|
|
|
|||
|
|
@ -32,14 +32,14 @@ void EyeDropperTool::gui_toolbox() {
|
|||
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
auto& selectingStrokeColor = drawP.world.main.toolConfig.eyeDropper.selectingStrokeColor;
|
||||
t.gui.push_id("Color select tool");
|
||||
text_label_centered(t.gui, "Color Select");
|
||||
t.gui.new_id("Color select tool", [&] {
|
||||
text_label_centered(t.gui, "Color Select");
|
||||
|
||||
radio_button_selector<bool>(t.gui, "Stroke type", &selectingStrokeColor, {
|
||||
{"Stroke Color", true},
|
||||
{"Fill Color", false}
|
||||
radio_button_selector<bool>(t.gui, "Stroke type", &selectingStrokeColor, {
|
||||
{"Stroke Color", true},
|
||||
{"Fill Color", false}
|
||||
});
|
||||
});
|
||||
t.gui.pop_id();
|
||||
}
|
||||
|
||||
void EyeDropperTool::right_click_popup_gui(Vector2f popupPos) {
|
||||
|
|
|
|||
|
|
@ -118,51 +118,51 @@ void GridModifyTool::gui_toolbox() {
|
|||
using namespace ElementHelpers;
|
||||
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
t.gui.push_id("Grid modify tool");
|
||||
text_label_centered(t.gui, "Edit Grid");
|
||||
NetworkingObjects::NetObjTemporaryPtr<WorldGrid> gLock = grid.lock();
|
||||
if(gLock) {
|
||||
WorldGrid& g = *gLock;
|
||||
input_text_field(t.gui, "grid name", "Name", &g.name);
|
||||
checkbox_boolean_field(t.gui, "Visible", "Visible", &g.visible);
|
||||
checkbox_boolean_field(t.gui, "Display in Front", "Display in front of canvas", &g.displayInFront);
|
||||
size_t typeSelected = static_cast<size_t>(g.gridType);
|
||||
std::vector<std::string> listOfGridTypes = {
|
||||
"Circle Points",
|
||||
"Square Points",
|
||||
"Square Lines",
|
||||
"Horizontal Lines"
|
||||
};
|
||||
left_to_right_line_layout(t.gui, [&]() {
|
||||
text_label(t.gui, "Type");
|
||||
t.gui.element<DropDown<size_t>>("filepicker select type", &typeSelected, listOfGridTypes);
|
||||
});
|
||||
g.gridType = static_cast<WorldGrid::GridType>(typeSelected);
|
||||
uint32_t sDiv = g.subdivisions;
|
||||
input_scalar_field<uint32_t>(t.gui, "Subdivisions", "Subdivisions", &sDiv, 1, 10);
|
||||
g.set_subdivisions(sDiv);
|
||||
bool divOut = g.removeDivisionsOutwards;
|
||||
checkbox_boolean_field(t.gui, "Subdivide outwards", "Subdivide when zooming out", &divOut);
|
||||
g.set_remove_divisions_outwards(divOut);
|
||||
left_to_right_line_layout(t.gui, [&]() {
|
||||
//if(t.gui.color_button_big("Grid Color", &g.color, &g.color == t.colorRight))
|
||||
// t.color_selector_right(&g.color == t.colorRight ? nullptr : &g.color);
|
||||
text_label(t.gui, "Grid Color");
|
||||
});
|
||||
bool bounded = g.bounds.has_value();
|
||||
bool prevBoundedValue = bounded;
|
||||
checkbox_boolean_field(t.gui, "Bounded", "Bounded", &bounded);
|
||||
if(bounded && !prevBoundedValue) {
|
||||
SCollision::AABB<WorldScalar> newBounds;
|
||||
newBounds.min = g.offset - drawP.world.drawData.cam.c.dir_from_space(drawP.world.main.window.size.cast<float>() * 0.3f);
|
||||
newBounds.max = g.offset + drawP.world.drawData.cam.c.dir_from_space(drawP.world.main.window.size.cast<float>() * 0.3f);
|
||||
g.bounds = newBounds;
|
||||
t.gui.new_id("Grid modify tool", [&] {
|
||||
text_label_centered(t.gui, "Edit Grid");
|
||||
NetworkingObjects::NetObjTemporaryPtr<WorldGrid> gLock = grid.lock();
|
||||
if(gLock) {
|
||||
WorldGrid& g = *gLock;
|
||||
input_text_field(t.gui, "grid name", "Name", &g.name);
|
||||
checkbox_boolean_field(t.gui, "Visible", "Visible", &g.visible);
|
||||
checkbox_boolean_field(t.gui, "Display in Front", "Display in front of canvas", &g.displayInFront);
|
||||
size_t typeSelected = static_cast<size_t>(g.gridType);
|
||||
std::vector<std::string> listOfGridTypes = {
|
||||
"Circle Points",
|
||||
"Square Points",
|
||||
"Square Lines",
|
||||
"Horizontal Lines"
|
||||
};
|
||||
left_to_right_line_layout(t.gui, [&]() {
|
||||
text_label(t.gui, "Type");
|
||||
t.gui.element<DropDown<size_t>>("filepicker select type", &typeSelected, listOfGridTypes);
|
||||
});
|
||||
g.gridType = static_cast<WorldGrid::GridType>(typeSelected);
|
||||
uint32_t sDiv = g.subdivisions;
|
||||
input_scalar_field<uint32_t>(t.gui, "Subdivisions", "Subdivisions", &sDiv, 1, 10);
|
||||
g.set_subdivisions(sDiv);
|
||||
bool divOut = g.removeDivisionsOutwards;
|
||||
checkbox_boolean_field(t.gui, "Subdivide outwards", "Subdivide when zooming out", &divOut);
|
||||
g.set_remove_divisions_outwards(divOut);
|
||||
left_to_right_line_layout(t.gui, [&]() {
|
||||
//if(t.gui.color_button_big("Grid Color", &g.color, &g.color == t.colorRight))
|
||||
// t.color_selector_right(&g.color == t.colorRight ? nullptr : &g.color);
|
||||
text_label(t.gui, "Grid Color");
|
||||
});
|
||||
bool bounded = g.bounds.has_value();
|
||||
bool prevBoundedValue = bounded;
|
||||
checkbox_boolean_field(t.gui, "Bounded", "Bounded", &bounded);
|
||||
if(bounded && !prevBoundedValue) {
|
||||
SCollision::AABB<WorldScalar> newBounds;
|
||||
newBounds.min = g.offset - drawP.world.drawData.cam.c.dir_from_space(drawP.world.main.window.size.cast<float>() * 0.3f);
|
||||
newBounds.max = g.offset + drawP.world.drawData.cam.c.dir_from_space(drawP.world.main.window.size.cast<float>() * 0.3f);
|
||||
g.bounds = newBounds;
|
||||
}
|
||||
else if(!bounded && prevBoundedValue)
|
||||
g.bounds = std::nullopt;
|
||||
checkbox_boolean_field(t.gui, "Show Coordinates", "Show Coordinates (visible\nwhen canvas isn't rotated)", &g.showCoordinates);
|
||||
}
|
||||
else if(!bounded && prevBoundedValue)
|
||||
g.bounds = std::nullopt;
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -42,10 +42,10 @@ DrawingProgramToolType LassoSelectTool::get_type() {
|
|||
|
||||
void LassoSelectTool::gui_toolbox() {
|
||||
auto& t = drawP.world.main.toolbar;
|
||||
t.gui.push_id("lasso select tool");
|
||||
GUIStuff::ElementHelpers::text_label_centered(t.gui, "Lasso Select");
|
||||
drawP.selection.selection_gui();
|
||||
t.gui.pop_id();
|
||||
t.gui.new_id("lasso select tool", [&] {
|
||||
GUIStuff::ElementHelpers::text_label_centered(t.gui, "Lasso Select");
|
||||
drawP.selection.selection_gui();
|
||||
});
|
||||
}
|
||||
|
||||
void LassoSelectTool::right_click_popup_gui(Vector2f popupPos) {
|
||||
|
|
|
|||
|
|
@ -24,11 +24,11 @@ void LineDrawTool::gui_toolbox() {
|
|||
using namespace ElementHelpers;
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
auto& toolConfig = drawP.world.main.toolConfig;
|
||||
t.gui.push_id("rect draw tool");
|
||||
text_label_centered(t.gui, "Draw Line");
|
||||
toolConfig.relative_width_gui(drawP, "Size");
|
||||
checkbox_boolean_field(t.gui, "hasroundcaps", "Round Caps", &toolConfig.lineDraw.hasRoundCaps);
|
||||
t.gui.pop_id();
|
||||
t.gui.new_id("rect draw tool", [&] {
|
||||
text_label_centered(t.gui, "Draw Line");
|
||||
toolConfig.relative_width_gui(drawP, "Size");
|
||||
checkbox_boolean_field(t.gui, "hasroundcaps", "Round Caps", &toolConfig.lineDraw.hasRoundCaps);
|
||||
});
|
||||
}
|
||||
|
||||
void LineDrawTool::input_mouse_button_on_canvas_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ DrawingProgramToolType PanCanvasTool::get_type() {
|
|||
|
||||
void PanCanvasTool::gui_toolbox() {
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
t.gui.push_id("Pan canvas tool");
|
||||
GUIStuff::ElementHelpers::text_label_centered(t.gui, "Pan tool");
|
||||
t.gui.pop_id();
|
||||
t.gui.new_id("Pan canvas tool", [&] {
|
||||
GUIStuff::ElementHelpers::text_label_centered(t.gui, "Pan tool");
|
||||
});
|
||||
}
|
||||
|
||||
void PanCanvasTool::right_click_popup_gui(Vector2f popupPos) {
|
||||
|
|
|
|||
|
|
@ -26,17 +26,17 @@ void RectDrawTool::gui_toolbox() {
|
|||
auto& toolConfig = drawP.world.main.toolConfig;
|
||||
auto& fillStrokeMode = toolConfig.rectDraw.fillStrokeMode;
|
||||
auto& relativeRadiusWidth = toolConfig.rectDraw.relativeRadiusWidth;
|
||||
t.gui.push_id("rect draw tool");
|
||||
text_label_centered(t.gui, "Draw Rectangle");
|
||||
slider_scalar_field(t.gui, "relradiuswidth", "Corner Radius", &relativeRadiusWidth, 0.0f, 40.0f);
|
||||
radio_button_selector(t.gui, "fill type", &fillStrokeMode, {
|
||||
{"Fill only", 0},
|
||||
{"Outline only", 1},
|
||||
{"Fill and Outline", 2}
|
||||
t.gui.new_id("rect draw tool", [&] {
|
||||
text_label_centered(t.gui, "Draw Rectangle");
|
||||
slider_scalar_field(t.gui, "relradiuswidth", "Corner Radius", &relativeRadiusWidth, 0.0f, 40.0f);
|
||||
radio_button_selector(t.gui, "fill type", &fillStrokeMode, {
|
||||
{"Fill only", 0},
|
||||
{"Outline only", 1},
|
||||
{"Fill and Outline", 2}
|
||||
});
|
||||
if(fillStrokeMode == 1 || fillStrokeMode == 2)
|
||||
toolConfig.relative_width_gui(drawP, "Outline Size");
|
||||
});
|
||||
if(fillStrokeMode == 1 || fillStrokeMode == 2)
|
||||
toolConfig.relative_width_gui(drawP, "Outline Size");
|
||||
t.gui.pop_id();
|
||||
}
|
||||
|
||||
void RectDrawTool::input_mouse_button_on_canvas_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@ DrawingProgramToolType RectSelectTool::get_type() {
|
|||
|
||||
void RectSelectTool::gui_toolbox() {
|
||||
auto& t = drawP.world.main.toolbar;
|
||||
t.gui.push_id("rectangle select tool");
|
||||
GUIStuff::ElementHelpers::text_label_centered(t.gui, "Rectangle Select");
|
||||
drawP.selection.selection_gui();
|
||||
t.gui.pop_id();
|
||||
t.gui.new_id("rectangle select tool", [&] {
|
||||
GUIStuff::ElementHelpers::text_label_centered(t.gui, "Rectangle Select");
|
||||
drawP.selection.selection_gui();
|
||||
});
|
||||
}
|
||||
|
||||
void RectSelectTool::input_key_callback(const InputManager::KeyCallbackArgs& key) {
|
||||
|
|
|
|||
|
|
@ -58,71 +58,71 @@ void ScreenshotTool::gui_toolbox() {
|
|||
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
auto& screenshotConfig = drawP.world.main.toolConfig.screenshot;
|
||||
t.gui.push_id("screenshot tool");
|
||||
text_label_centered(t.gui, "Screenshot");
|
||||
auto oldImgSize = controls.imageSize;
|
||||
if(controls.selectionMode == ScreenshotControls::SelectionMode::NO_SELECTION)
|
||||
text_label(t.gui, "Select an area on the canvas...");
|
||||
if(controls.selectionMode != ScreenshotControls::SelectionMode::NO_SELECTION && screenshotConfig.selectedType != SCREENSHOT_SVG)
|
||||
input_scalars_field(t.gui, "Image Size", "Image Size", &controls.imageSize, 2, 0, 999999999);
|
||||
if(controls.selectionMode == ScreenshotControls::SelectionMode::SELECTION_EXISTS) {
|
||||
left_to_right_line_layout(t.gui, [&]() {
|
||||
text_label(t.gui, "Image Type");
|
||||
t.gui.element<DropDown<size_t>>("image type select", (size_t*)(&screenshotConfig.selectedType), controls.typeSelections);
|
||||
});
|
||||
if(screenshotConfig.selectedType != SCREENSHOT_SVG)
|
||||
checkbox_boolean_field(t.gui, "Display Grid", "Display Grid", &controls.displayGrid);
|
||||
else
|
||||
text_label(t.gui, "Note: Screenshot will ignore blend\nmodes and layer alpha");
|
||||
if(screenshotConfig.selectedType != 0)
|
||||
checkbox_boolean_field(t.gui, "Transparent Background", "Transparent Background", &controls.transparentBackground);
|
||||
if(controls.imageSize.x() != oldImgSize.x()) {
|
||||
screenshotConfig.setDimensionSize = controls.imageSize.x();
|
||||
screenshotConfig.setDimensionIsX = true;
|
||||
controls.imageSize.y() = controls.imageSize.x() * (controls.rectY2 - controls.rectY1) / (controls.rectX2 - controls.rectX1);
|
||||
}
|
||||
else if(controls.imageSize.y() != oldImgSize.y()) {
|
||||
screenshotConfig.setDimensionSize = controls.imageSize.y();
|
||||
screenshotConfig.setDimensionIsX = false;
|
||||
controls.imageSize.x() = controls.imageSize.y() * (controls.rectX2 - controls.rectX1) / (controls.rectY2 - controls.rectY1);
|
||||
}
|
||||
text_button(t.gui, "Take Screenshot", "Take Screenshot", {
|
||||
.wide = true,
|
||||
.onClick = [&] {
|
||||
controls.selectionMode = ScreenshotControls::SelectionMode::NO_SELECTION;
|
||||
#ifdef __EMSCRIPTEN__
|
||||
take_screenshot("a" + controls.typeSelections[screenshotConfig.selectedType], screenshotConfig.selectedType);
|
||||
#else
|
||||
// We can't actually use the extension from the callback, so we have to set the extension of choice beforehand
|
||||
Toolbar::ExtensionFilter setExtensionFilter;
|
||||
switch(screenshotConfig.selectedType) {
|
||||
case SCREENSHOT_JPG:
|
||||
setExtensionFilter = {"JPEG", "jpg;jpeg"};
|
||||
break;
|
||||
case SCREENSHOT_PNG:
|
||||
setExtensionFilter = {"PNG", "png"};
|
||||
break;
|
||||
case SCREENSHOT_WEBP:
|
||||
setExtensionFilter = {"WEBP", "webp"};
|
||||
break;
|
||||
case SCREENSHOT_SVG:
|
||||
setExtensionFilter = {"SVG", "svg"};
|
||||
break;
|
||||
}
|
||||
t.open_file_selector("Export", {setExtensionFilter}, [setExtensionFilter, w = make_weak_ptr(drawP.world.main.world)](const std::filesystem::path& p, const auto& e) {
|
||||
auto world = w.lock();
|
||||
if(world && world->drawProg.drawTool->get_type() == DrawingProgramToolType::SCREENSHOT) {
|
||||
ScreenshotTool* screenshotTool = static_cast<ScreenshotTool*>(world->drawProg.drawTool.get());
|
||||
screenshotTool->controls.screenshotSavePath = p;
|
||||
screenshotTool->controls.screenshotSaveType = world->main.toolConfig.screenshot.selectedType;
|
||||
screenshotTool->controls.setToTakeScreenshot = true;
|
||||
}
|
||||
}, "screenshot", true);
|
||||
#endif
|
||||
t.gui.new_id("screenshot tool", [&] {
|
||||
text_label_centered(t.gui, "Screenshot");
|
||||
auto oldImgSize = controls.imageSize;
|
||||
if(controls.selectionMode == ScreenshotControls::SelectionMode::NO_SELECTION)
|
||||
text_label(t.gui, "Select an area on the canvas...");
|
||||
if(controls.selectionMode != ScreenshotControls::SelectionMode::NO_SELECTION && screenshotConfig.selectedType != SCREENSHOT_SVG)
|
||||
input_scalars_field(t.gui, "Image Size", "Image Size", &controls.imageSize, 2, 0, 999999999);
|
||||
if(controls.selectionMode == ScreenshotControls::SelectionMode::SELECTION_EXISTS) {
|
||||
left_to_right_line_layout(t.gui, [&]() {
|
||||
text_label(t.gui, "Image Type");
|
||||
t.gui.element<DropDown<size_t>>("image type select", (size_t*)(&screenshotConfig.selectedType), controls.typeSelections);
|
||||
});
|
||||
if(screenshotConfig.selectedType != SCREENSHOT_SVG)
|
||||
checkbox_boolean_field(t.gui, "Display Grid", "Display Grid", &controls.displayGrid);
|
||||
else
|
||||
text_label(t.gui, "Note: Screenshot will ignore blend\nmodes and layer alpha");
|
||||
if(screenshotConfig.selectedType != 0)
|
||||
checkbox_boolean_field(t.gui, "Transparent Background", "Transparent Background", &controls.transparentBackground);
|
||||
if(controls.imageSize.x() != oldImgSize.x()) {
|
||||
screenshotConfig.setDimensionSize = controls.imageSize.x();
|
||||
screenshotConfig.setDimensionIsX = true;
|
||||
controls.imageSize.y() = controls.imageSize.x() * (controls.rectY2 - controls.rectY1) / (controls.rectX2 - controls.rectX1);
|
||||
}
|
||||
});
|
||||
}
|
||||
t.gui.pop_id();
|
||||
else if(controls.imageSize.y() != oldImgSize.y()) {
|
||||
screenshotConfig.setDimensionSize = controls.imageSize.y();
|
||||
screenshotConfig.setDimensionIsX = false;
|
||||
controls.imageSize.x() = controls.imageSize.y() * (controls.rectX2 - controls.rectX1) / (controls.rectY2 - controls.rectY1);
|
||||
}
|
||||
text_button(t.gui, "Take Screenshot", "Take Screenshot", {
|
||||
.wide = true,
|
||||
.onClick = [&] {
|
||||
controls.selectionMode = ScreenshotControls::SelectionMode::NO_SELECTION;
|
||||
#ifdef __EMSCRIPTEN__
|
||||
take_screenshot("a" + controls.typeSelections[screenshotConfig.selectedType], screenshotConfig.selectedType);
|
||||
#else
|
||||
// We can't actually use the extension from the callback, so we have to set the extension of choice beforehand
|
||||
Toolbar::ExtensionFilter setExtensionFilter;
|
||||
switch(screenshotConfig.selectedType) {
|
||||
case SCREENSHOT_JPG:
|
||||
setExtensionFilter = {"JPEG", "jpg;jpeg"};
|
||||
break;
|
||||
case SCREENSHOT_PNG:
|
||||
setExtensionFilter = {"PNG", "png"};
|
||||
break;
|
||||
case SCREENSHOT_WEBP:
|
||||
setExtensionFilter = {"WEBP", "webp"};
|
||||
break;
|
||||
case SCREENSHOT_SVG:
|
||||
setExtensionFilter = {"SVG", "svg"};
|
||||
break;
|
||||
}
|
||||
t.open_file_selector("Export", {setExtensionFilter}, [setExtensionFilter, w = make_weak_ptr(drawP.world.main.world)](const std::filesystem::path& p, const auto& e) {
|
||||
auto world = w.lock();
|
||||
if(world && world->drawProg.drawTool->get_type() == DrawingProgramToolType::SCREENSHOT) {
|
||||
ScreenshotTool* screenshotTool = static_cast<ScreenshotTool*>(world->drawProg.drawTool.get());
|
||||
screenshotTool->controls.screenshotSavePath = p;
|
||||
screenshotTool->controls.screenshotSaveType = world->main.toolConfig.screenshot.selectedType;
|
||||
screenshotTool->controls.setToTakeScreenshot = true;
|
||||
}
|
||||
}, "screenshot", true);
|
||||
#endif
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void ScreenshotTool::right_click_popup_gui(Vector2f popupPos) {
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ DrawingProgramToolType TextBoxTool::get_type() {
|
|||
|
||||
void TextBoxTool::gui_toolbox() {
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
t.gui.push_id("textbox tool");
|
||||
GUIStuff::ElementHelpers::text_label_centered(t.gui, "Zoom tool");
|
||||
t.gui.pop_id();
|
||||
t.gui.new_id("textbox tool", [&] {
|
||||
GUIStuff::ElementHelpers::text_label_centered(t.gui, "Zoom tool");
|
||||
});
|
||||
}
|
||||
|
||||
void TextBoxTool::input_mouse_button_on_canvas_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ DrawingProgramToolType ZoomCanvasTool::get_type() {
|
|||
|
||||
void ZoomCanvasTool::gui_toolbox() {
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
t.gui.push_id("Zoom canvas tool");
|
||||
GUIStuff::ElementHelpers::text_label_centered(t.gui, "Zoom tool");
|
||||
t.gui.pop_id();
|
||||
t.gui.new_id("Zoom canvas tool", [&] {
|
||||
GUIStuff::ElementHelpers::text_label_centered(t.gui, "Zoom tool");
|
||||
});
|
||||
}
|
||||
|
||||
void ZoomCanvasTool::right_click_popup_gui(Vector2f popupPos) {
|
||||
|
|
|
|||
|
|
@ -47,20 +47,20 @@ 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 = {});
|
||||
|
||||
template <typename T> void color_button(GUIManager& gui, const char* id, T* val, const FixedSizeColorButtonOptions& options = {}) {
|
||||
gui.push_id(id);
|
||||
SelectableButton::Data d = selectable_button_options_to_data(options);
|
||||
d.innerContent = [&] (const SelectableButton::InnerContentCallbackParameters&) {
|
||||
gui.element<ColorRectangleDisplay>("color display", [val, hasAlpha = options.hasAlpha] {
|
||||
if(hasAlpha)
|
||||
return SkColor4f{(*val)[0], (*val)[1], (*val)[2], 1.0f};
|
||||
else
|
||||
return SkColor4f{(*val)[0], (*val)[1], (*val)[2], (*val)[3]};
|
||||
});
|
||||
};
|
||||
CLAY_AUTO_ID({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(options.size), .height = CLAY_SIZING_FIXED(options.size) } } }) {
|
||||
gui.element<SelectableButton>("button", d);
|
||||
}
|
||||
gui.pop_id();
|
||||
gui.new_id(id, [&] {
|
||||
SelectableButton::Data d = selectable_button_options_to_data(options);
|
||||
d.innerContent = [&] (const SelectableButton::InnerContentCallbackParameters&) {
|
||||
gui.element<ColorRectangleDisplay>("color display", [val, hasAlpha = options.hasAlpha] {
|
||||
if(hasAlpha)
|
||||
return SkColor4f{(*val)[0], (*val)[1], (*val)[2], 1.0f};
|
||||
else
|
||||
return SkColor4f{(*val)[0], (*val)[1], (*val)[2], (*val)[3]};
|
||||
});
|
||||
};
|
||||
CLAY_AUTO_ID({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(options.size), .height = CLAY_SIZING_FIXED(options.size) } } }) {
|
||||
gui.element<SelectableButton>("button", d);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}}
|
||||
|
|
|
|||
|
|
@ -11,29 +11,29 @@ struct ColorPickerItemsOptions {
|
|||
};
|
||||
|
||||
template <typename T> void color_picker_items(GUIManager& gui, const char* id, T* val, const ColorPickerItemsOptions& options = {}) {
|
||||
gui.push_id(id);
|
||||
auto fullOnEdit = [&gui, oE = options.onEdit, val]() {
|
||||
oE();
|
||||
gui.set_to_layout();
|
||||
};
|
||||
gui.element<ColorPicker<T>>("c", val, options.hasAlpha, fullOnEdit);
|
||||
left_to_right_line_layout(gui, [&]() {
|
||||
text_label(gui, "R");
|
||||
input_color_component_255(gui, "r", &(*val)[0], { .onEdit = fullOnEdit });
|
||||
text_label(gui, "G");
|
||||
input_color_component_255(gui, "g", &(*val)[1], { .onEdit = fullOnEdit });
|
||||
text_label(gui, "B");
|
||||
input_color_component_255(gui, "b", &(*val)[2], { .onEdit = fullOnEdit });
|
||||
if(options.hasAlpha) {
|
||||
text_label(gui, "A");
|
||||
input_color_component_255(gui, "a", &(*val)[3], { .onEdit = fullOnEdit });
|
||||
}
|
||||
gui.new_id(id, [&] {
|
||||
auto fullOnEdit = [&gui, oE = options.onEdit, val]() {
|
||||
oE();
|
||||
gui.set_to_layout();
|
||||
};
|
||||
gui.element<ColorPicker<T>>("c", val, options.hasAlpha, fullOnEdit);
|
||||
left_to_right_line_layout(gui, [&]() {
|
||||
text_label(gui, "R");
|
||||
input_color_component_255(gui, "r", &(*val)[0], { .onEdit = fullOnEdit });
|
||||
text_label(gui, "G");
|
||||
input_color_component_255(gui, "g", &(*val)[1], { .onEdit = fullOnEdit });
|
||||
text_label(gui, "B");
|
||||
input_color_component_255(gui, "b", &(*val)[2], { .onEdit = fullOnEdit });
|
||||
if(options.hasAlpha) {
|
||||
text_label(gui, "A");
|
||||
input_color_component_255(gui, "a", &(*val)[3], { .onEdit = fullOnEdit });
|
||||
}
|
||||
});
|
||||
left_to_right_line_layout(gui, [&]() {
|
||||
text_label(gui, "Hex");
|
||||
input_color_hex(gui, "h", val, { .hasAlpha = options.hasAlpha, .onEdit = fullOnEdit });
|
||||
});
|
||||
});
|
||||
left_to_right_line_layout(gui, [&]() {
|
||||
text_label(gui, "Hex");
|
||||
input_color_hex(gui, "h", val, { .hasAlpha = options.hasAlpha, .onEdit = fullOnEdit });
|
||||
});
|
||||
gui.pop_id();
|
||||
}
|
||||
|
||||
} }
|
||||
|
|
|
|||
|
|
@ -5,16 +5,16 @@
|
|||
|
||||
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.push_id(id);
|
||||
options.onEdit = [&, oE = options.onEdit] {
|
||||
oE();
|
||||
gui.set_to_layout();
|
||||
};
|
||||
left_to_right_line_layout(gui, [&]() {
|
||||
text_label(gui, name);
|
||||
input_scalar(gui, "textbox", val, min, max, options);
|
||||
gui.new_id(id, [&] {
|
||||
options.onEdit = [&, oE = options.onEdit] {
|
||||
oE();
|
||||
gui.set_to_layout();
|
||||
};
|
||||
left_to_right_line_layout(gui, [&]() {
|
||||
text_label(gui, name);
|
||||
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();
|
||||
}
|
||||
}}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
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);
|
||||
for(size_t i = 0; i < options.size(); i++) {
|
||||
gui.push_id(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(); });
|
||||
gui.pop_id();
|
||||
}
|
||||
gui.pop_id();
|
||||
gui.new_id(id, [&] {
|
||||
for(size_t i = 0; i < options.size(); i++) {
|
||||
gui.new_id(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(); });
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}}
|
||||
|
|
|
|||
|
|
@ -25,11 +25,8 @@ void scroll_area_many_entries(GUIManager& gui, const char* id, const ScrollBarMa
|
|||
}) { }
|
||||
}
|
||||
|
||||
for(size_t i = startPoint; i < endPoint; i++) {
|
||||
gui.push_id(i);
|
||||
options.elementContent(i);
|
||||
gui.pop_id();
|
||||
}
|
||||
for(size_t i = startPoint; i < endPoint; i++)
|
||||
gui.new_id(i, [&] { options.elementContent(i); });
|
||||
|
||||
if(endPoint != options.entryCount) {
|
||||
CLAY_AUTO_ID({
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
d.data = val;
|
||||
d.textInputProps = textInputProps;
|
||||
d.fromStr = [](const std::string& str) {
|
||||
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);
|
||||
d.data = val;
|
||||
d.textInputProps = textInputProps;
|
||||
d.fromStr = [](const std::string& 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);
|
||||
d.data = val;
|
||||
d.textInputProps = textInputProps;
|
||||
d.fromStr = [minVal, maxVal](const std::string& a) {
|
||||
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);
|
||||
d.data = val;
|
||||
d.textInputProps = textInputProps;
|
||||
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()));
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
TextBoxData<T> d = textbox_options_to_data<T>(options);
|
||||
d.data = val;
|
||||
d.textInputProps = textInputProps;
|
||||
d.fromStr = [minVal, maxVal](const std::string& a) {
|
||||
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 = {}) {
|
||||
gui.push_id(id);
|
||||
left_to_right_line_layout(gui, [&]() {
|
||||
text_label(gui, name);
|
||||
for(size_t i = 0; i < elemCount; i++) {
|
||||
gui.push_id(i);
|
||||
input_scalar<T>(gui, "field", &(*val)[i], minVal, maxVal, options);
|
||||
gui.pop_id();
|
||||
}
|
||||
gui.new_id(id, [&] {
|
||||
left_to_right_line_layout(gui, [&]() {
|
||||
text_label(gui, name);
|
||||
for(size_t i = 0; i < elemCount; i++)
|
||||
gui.new_id(i, [&] { input_scalar<T>(gui, "field", &(*val)[i], minVal, maxVal, options); });
|
||||
});
|
||||
});
|
||||
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 = {}) {
|
||||
|
|
@ -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);
|
||||
d.data = val;
|
||||
d.textInputProps = textInputProps;
|
||||
d.fromStr = [hasAlpha = options.hasAlpha](const std::string& a) {
|
||||
T def;
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
auto& io = *gui.io;
|
||||
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);
|
||||
CLAY_AUTO_ID({
|
||||
.layout = {
|
||||
|
|
@ -118,6 +110,14 @@ template <typename T> void TextBox<T>::init_textbox(UpdateInputData& io) {
|
|||
rect = std::make_shared<SCollision::AABB<float>>();
|
||||
|
||||
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() {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ GUIManager::GUIManager()
|
|||
clayArena = Clay_CreateArenaWithCapacityAndMemory(Clay_MinMemorySize(), malloc(Clay_MinMemorySize()));
|
||||
clayInstance = Clay_Initialize(clayArena, Clay_Dimensions(1.0f, 1.0f), (Clay_ErrorHandler)clay_error_handler);
|
||||
Clay_SetMeasureTextFunction(clay_skia_measure_text, this);
|
||||
setToLayout = true;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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) {
|
||||
idStack.emplace_back(id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,9 +28,8 @@ class GUIManager {
|
|||
GUIManagerIDStack idStack;
|
||||
std::unordered_map<GUIManagerIDStack, ElementContainer> elements;
|
||||
|
||||
void push_id(int64_t id);
|
||||
void push_id(const char* id);
|
||||
void pop_id();
|
||||
void new_id(const char* id, const std::function<void()>& f);
|
||||
void new_id(int64_t id, 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 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;
|
||||
Clay_Context* clayInstance;
|
||||
Clay_Arena clayArena;
|
||||
|
|
|
|||
1028
src/Toolbar.cpp
1028
src/Toolbar.cpp
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue