From 60de05a50b1ae65f01751c6ed68262feeefa4ebe Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Thu, 13 Feb 2025 11:41:58 +0530 Subject: [PATCH 1/3] improvement: toggle buttons changed to check boxes --- src/live_effects/lpe-simplify.h | 1 + src/live_effects/lpe-transform_2pts.cpp | 36 +++++++------------------ src/live_effects/lpe-transform_2pts.h | 14 +++++----- 3 files changed, 18 insertions(+), 33 deletions(-) diff --git a/src/live_effects/lpe-simplify.h b/src/live_effects/lpe-simplify.h index 9356d4808b..2d981c2af8 100644 --- a/src/live_effects/lpe-simplify.h +++ b/src/live_effects/lpe-simplify.h @@ -9,6 +9,7 @@ */ #include "live_effects/effect.h" #include "live_effects/parameter/togglebutton.h" +#include "live_effects/parameter/bool.h" #include "live_effects/lpegroupbbox.h" namespace Inkscape { diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index ac5a4cd731..066a9ebaeb 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -31,12 +31,12 @@ namespace Inkscape::LivePathEffect { LPETransform2Pts::LPETransform2Pts(LivePathEffectObject *lpeobject) : Effect(lpeobject), - elastic(_("Elastic"), _("Elastic transform mode"), "elastic", &wr, this, false,"", INKSCAPE_ICON("on-outline"), INKSCAPE_ICON("off-outline")), - from_original_width(_("From original width"), _("From original width"), "from_original_width", &wr, this, false,"", INKSCAPE_ICON("on-outline"), INKSCAPE_ICON("off-outline")), - lock_length(_("Lock length"), _("Lock length to current distance"), "lock_length", &wr, this, false,"", INKSCAPE_ICON("on-outline"), INKSCAPE_ICON("off-outline")), - lock_angle(_("Lock angle"), _("Lock angle"), "lock_angle", &wr, this, false,"", INKSCAPE_ICON("on-outline"), INKSCAPE_ICON("off-outline")), - flip_horizontal(_("Flip horizontal"), _("Flip horizontal"), "flip_horizontal", &wr, this, false,"", INKSCAPE_ICON("on-outline"), INKSCAPE_ICON("off-outline")), - flip_vertical(_("Flip vertical"), _("Flip vertical"), "flip_vertical", &wr, this, false,"", INKSCAPE_ICON("on-outline"), INKSCAPE_ICON("off-outline")), + elastic(_("Elastic"), _("Elastic transform mode"), "elastic", &wr, this, false), + from_original_width(_("From original width"), _("From original width"), "from_original_width", &wr, this, false), + lock_length(_("Lock length"), _("Lock length to current distance"), "lock_length", &wr, this, false), + lock_angle(_("Lock angle"), _("Lock angle"), "lock_angle", &wr, this, false), + flip_horizontal(_("Flip horizontal"), _("Flip horizontal"), "flip_horizontal", &wr, this, false), + flip_vertical(_("Flip vertical"), _("Flip vertical"), "flip_vertical", &wr, this, false), start(_("Start"), _("Start point"), "start", &wr, this, "Start point"), end(_("End"), _("End point"), "end", &wr, this, "End point"), stretch(_("Stretch"), _("Stretch the result"), "stretch", &wr, this, 1), @@ -292,34 +292,21 @@ Gtk::Widget *LPETransform2Pts::newWidget() auto const vbox = Gtk::make_managed(Gtk::Orientation::VERTICAL, 6); vbox->set_margin(5); - auto const button1 = Gtk::make_managed(Gtk::Orientation::HORIZONTAL,0); - auto const button2 = Gtk::make_managed(Gtk::Orientation::HORIZONTAL,0); - auto const button3 = Gtk::make_managed(Gtk::Orientation::HORIZONTAL,0); - auto const button4 = Gtk::make_managed(Gtk::Orientation::HORIZONTAL,0); - for (auto const param: param_vector) { if (!param->widget_is_visible) continue; auto const widg = param->param_newWidget(); if (!widg) continue; - auto parent = vbox; - if (param->param_key == "first_knot" || param->param_key == "last_knot") { auto &scalar = dynamic_cast(*widg); Gtk::manage(&scalar); scalar.signal_value_changed().connect(sigc::mem_fun(*this, &LPETransform2Pts::updateIndex)); scalar.getSpinButton().set_width_chars(3); - } else if (param->param_key == "from_original_width" || param->param_key == "elastic") { - parent = button1; - } else if (param->param_key == "flip_horizontal" || param->param_key == "flip_vertical") { - parent = button2; - } else if (param->param_key == "lock_angle" || param->param_key == "lock_length") { - parent = button3; } - g_assert(parent); - UI::pack_start(*parent, *widg, true, true, 2); + g_assert(vbox); + UI::pack_start(*vbox, *widg, true, true, 2); if (auto const tip = param->param_getTooltip()) { widg->set_tooltip_markup(*tip); @@ -329,14 +316,11 @@ Gtk::Widget *LPETransform2Pts::newWidget() } } + // Add Reset button at the bottom auto const reset = Gtk::make_managed(Glib::ustring(_("Reset"))); reset->signal_clicked().connect(sigc::mem_fun(*this, &LPETransform2Pts::reset)); - UI::pack_start(*button4, *reset, true, true, 2); + UI::pack_start(*vbox, *reset, true, true, 2); - UI::pack_start(*vbox, *button1, true, true, 2); - UI::pack_start(*vbox, *button2, true, true, 2); - UI::pack_start(*vbox, *button3, true, true, 2); - UI::pack_start(*vbox, *button4, true, true, 2); return vbox; } diff --git a/src/live_effects/lpe-transform_2pts.h b/src/live_effects/lpe-transform_2pts.h index d72e69a6c3..d9f0bc4904 100644 --- a/src/live_effects/lpe-transform_2pts.h +++ b/src/live_effects/lpe-transform_2pts.h @@ -17,7 +17,7 @@ #include "live_effects/effect.h" #include "live_effects/lpegroupbbox.h" #include "live_effects/parameter/parameter.h" -#include "live_effects/parameter/togglebutton.h" +#include "live_effects/parameter/bool.h" #include "live_effects/parameter/point.h" namespace Inkscape { @@ -52,12 +52,12 @@ protected: void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec) override; private: - ToggleButtonParam elastic; - ToggleButtonParam from_original_width; - ToggleButtonParam lock_length; - ToggleButtonParam lock_angle; - ToggleButtonParam flip_horizontal; - ToggleButtonParam flip_vertical; + BoolParam elastic; + BoolParam from_original_width; + BoolParam lock_length; + BoolParam lock_angle; + BoolParam flip_horizontal; + BoolParam flip_vertical; PointParam start; PointParam end; ScalarParam stretch; -- GitLab From d84c4b5b12236bb5ea8414c89461c1ccd38cefbf Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Mon, 17 Feb 2025 08:51:07 +0530 Subject: [PATCH 2/3] created a grid for checkboxes with 2 columns --- src/live_effects/lpe-transform_2pts.cpp | 40 +++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index 066a9ebaeb..1d9a9cc075 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -14,6 +14,7 @@ #include #include +#include #include "display/curve.h" #include "helper/geom.h" @@ -292,6 +293,14 @@ Gtk::Widget *LPETransform2Pts::newWidget() auto const vbox = Gtk::make_managed(Gtk::Orientation::VERTICAL, 6); vbox->set_margin(5); + // Create a grid for checkboxes + auto const grid = Gtk::make_managed(); + grid->set_row_spacing(10); + grid->set_column_spacing(30); + grid->set_margin_top(5); + + int row = 0, col = 0; + for (auto const param: param_vector) { if (!param->widget_is_visible) continue; @@ -304,9 +313,33 @@ Gtk::Widget *LPETransform2Pts::newWidget() scalar.signal_value_changed().connect(sigc::mem_fun(*this, &LPETransform2Pts::updateIndex)); scalar.getSpinButton().set_width_chars(3); } + else if (param->param_key == "elastic" || + param->param_key == "from_original_width" || + param->param_key == "lock_length" || + param->param_key == "lock_angle" || + param->param_key == "flip_horizontal" || + param->param_key == "flip_vertical") + { + grid->attach(*widg, col, row, 1, 1); + + row++; + if (row == 3) { + row = 0, col = 1; + } + continue; + } + + if(param->param_key != "elastic" && + param->param_key != "from_original_width" && + param->param_key != "lock_length" && + param->param_key != "lock_angle" && + param->param_key != "flip_horizontal" && + param->param_key != "flip_vertical") + { - g_assert(vbox); - UI::pack_start(*vbox, *widg, true, true, 2); + g_assert(vbox); + UI::pack_start(*vbox, *widg, true, true, 2); + } if (auto const tip = param->param_getTooltip()) { widg->set_tooltip_markup(*tip); @@ -316,6 +349,9 @@ Gtk::Widget *LPETransform2Pts::newWidget() } } + // Add the grid to the vbox + UI::pack_start(*vbox, *grid, true, true, 2); + // Add Reset button at the bottom auto const reset = Gtk::make_managed(Glib::ustring(_("Reset"))); reset->signal_clicked().connect(sigc::mem_fun(*this, &LPETransform2Pts::reset)); -- GitLab From f725b7d928bfc23e6d0dcefaf03b4adf5cd2d037 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Thu, 20 Feb 2025 11:47:30 +0530 Subject: [PATCH 3/3] toggle buttons revamp using grid approach --- src/live_effects/lpe-transform_2pts.cpp | 51 +++++++++---------------- 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index 1d9a9cc075..9b3c9b5734 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -293,13 +293,15 @@ Gtk::Widget *LPETransform2Pts::newWidget() auto const vbox = Gtk::make_managed(Gtk::Orientation::VERTICAL, 6); vbox->set_margin(5); - // Create a grid for checkboxes auto const grid = Gtk::make_managed(); - grid->set_row_spacing(10); - grid->set_column_spacing(30); - grid->set_margin_top(5); + grid->set_column_spacing(50); + grid->set_row_spacing(6); - int row = 0, col = 0; + std::map> widget_positions = { + {"elastic", {0, 0}}, {"from_original_width", {1, 0}}, + {"flip_vertical", {0, 1}}, {"flip_horizontal", {1, 1}}, + {"lock_length", {0, 2}}, {"lock_angle", {1, 2}} + }; for (auto const param: param_vector) { if (!param->widget_is_visible) continue; @@ -307,37 +309,21 @@ Gtk::Widget *LPETransform2Pts::newWidget() auto const widg = param->param_newWidget(); if (!widg) continue; + auto parent = vbox; + if (param->param_key == "first_knot" || param->param_key == "last_knot") { auto &scalar = dynamic_cast(*widg); Gtk::manage(&scalar); scalar.signal_value_changed().connect(sigc::mem_fun(*this, &LPETransform2Pts::updateIndex)); scalar.getSpinButton().set_width_chars(3); - } - else if (param->param_key == "elastic" || - param->param_key == "from_original_width" || - param->param_key == "lock_length" || - param->param_key == "lock_angle" || - param->param_key == "flip_horizontal" || - param->param_key == "flip_vertical") - { + } else if (widget_positions.find(param->param_key) != widget_positions.end()) { + auto [col, row] = widget_positions[param->param_key]; grid->attach(*widg, col, row, 1, 1); + parent = nullptr; // To avoid adding it to vbox later + } - row++; - if (row == 3) { - row = 0, col = 1; - } - continue; - } - - if(param->param_key != "elastic" && - param->param_key != "from_original_width" && - param->param_key != "lock_length" && - param->param_key != "lock_angle" && - param->param_key != "flip_horizontal" && - param->param_key != "flip_vertical") - { - - g_assert(vbox); + // Add to vbox only if it's not in the grid + if(parent) { UI::pack_start(*vbox, *widg, true, true, 2); } @@ -349,13 +335,10 @@ Gtk::Widget *LPETransform2Pts::newWidget() } } - // Add the grid to the vbox - UI::pack_start(*vbox, *grid, true, true, 2); - - // Add Reset button at the bottom auto const reset = Gtk::make_managed(Glib::ustring(_("Reset"))); reset->signal_clicked().connect(sigc::mem_fun(*this, &LPETransform2Pts::reset)); - UI::pack_start(*vbox, *reset, true, true, 2); + UI::pack_start(*vbox, *grid, true, true, 2); // Add grid to vbox + UI::pack_start(*vbox, *reset, true, true, 2); // Add reset button to vbox return vbox; } -- GitLab