From 2dae18da096e52ea0e9a274b73781d8de80ec619 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Thu, 17 Nov 2022 00:43:16 +0100 Subject: Fluid: Add Undo to formula input fields. (#547) --- documentation/src/fluid.dox | 19 +++++++++++++++++++ fluid/Fl_Widget_Type.cxx | 5 +++++ fluid/widget_panel.cxx | 12 ++++++++---- fluid/widget_panel.fl | 20 ++++++++++++++------ 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/documentation/src/fluid.dox b/documentation/src/fluid.dox index b0682be9b..fc020f7d7 100644 --- a/documentation/src/fluid.dox +++ b/documentation/src/fluid.dox @@ -1028,6 +1028,25 @@ the image. The position fields show the current position and size of the widget box. Enter new values to move and/or resize a widget. +\par +These fields understand basic math and variables. +Appending +10 to the X coordinate will move a widget 10 units +to the right without having to reenter the value. +Entering the formula w+3 in the Width field will widen all +selected Widgets by 3 units. +The formula py+i*20 in the Y field will order all selected +widgets vertically in their group by increments of 20 units. + +\par + + + + + + + +
NameValue
`i` zero based counter of selected widgets
`x`, `y`, `w`, `h` position and size of the current widget
`px`, `py`, `pw`, `ph` dimensions of the parent widget
`sx`, `sy`, `sw`, `sh` dimensions of the previous sibling
`cx`, `cy`, `cw`, `ch` bounding box of all children
+ \par Values (text fields) \par diff --git a/fluid/Fl_Widget_Type.cxx b/fluid/Fl_Widget_Type.cxx index 14bba4fd5..12772eabe 100644 --- a/fluid/Fl_Widget_Type.cxx +++ b/fluid/Fl_Widget_Type.cxx @@ -26,6 +26,7 @@ #include "Fluid_Image.h" #include "alignment_panel.h" #include "widget_panel.h" +#include "undo.h" #include #include @@ -666,6 +667,7 @@ void x_cb(Fluid_Coord_Input *i, void *v) { x_input->activate(); } else x_input->deactivate(); } else { + undo_checkpoint(); widget_i = 0; int mod = 0; for (Fl_Type *o = Fl_Type::first; o; o = o->next) { @@ -690,6 +692,7 @@ void y_cb(Fluid_Coord_Input *i, void *v) { y_input->activate(); } else y_input->deactivate(); } else { + undo_checkpoint(); widget_i = 0; int mod = 0; for (Fl_Type *o = Fl_Type::first; o; o = o->next) { @@ -714,6 +717,7 @@ void w_cb(Fluid_Coord_Input *i, void *v) { w_input->activate(); } else w_input->deactivate(); } else { + undo_checkpoint(); widget_i = 0; int mod = 0; for (Fl_Type *o = Fl_Type::first; o; o = o->next) { @@ -738,6 +742,7 @@ void h_cb(Fluid_Coord_Input *i, void *v) { h_input->activate(); } else h_input->deactivate(); } else { + undo_checkpoint(); widget_i = 0; int mod = 0; for (Fl_Type *o = Fl_Type::first; o; o = o->next) { diff --git a/fluid/widget_panel.cxx b/fluid/widget_panel.cxx index 1fd59d4e0..df21f7d67 100644 --- a/fluid/widget_panel.cxx +++ b/fluid/widget_panel.cxx @@ -274,7 +274,8 @@ Fl_Double_Window* make_widget_panel() { o->callback((Fl_Callback*)position_group_cb); o->align(Fl_Align(FL_ALIGN_LEFT)); { widget_x_input = new Fluid_Coord_Input(95, 150, 55, 20, "X:"); - widget_x_input->tooltip("The X position of the widget."); + widget_x_input->tooltip("The X position of the widget as a number or formula.\nFormulas can be simple \ +math, including the variables\nx, px, sx, cx, and i"); widget_x_input->box(FL_DOWN_BOX); widget_x_input->color(FL_BACKGROUND2_COLOR); widget_x_input->selection_color(FL_SELECTION_COLOR); @@ -288,7 +289,8 @@ Fl_Double_Window* make_widget_panel() { widget_x_input->when(FL_WHEN_RELEASE); } // Fluid_Coord_Input* widget_x_input { widget_y_input = new Fluid_Coord_Input(155, 150, 55, 20, "Y:"); - widget_y_input->tooltip("The Y position of the widget."); + widget_y_input->tooltip("The Y position of the widget as a number or formula.\nFormulas can be simple \ +math, including the variables\ny, py, sy, cy, and i"); widget_y_input->box(FL_DOWN_BOX); widget_y_input->color(FL_BACKGROUND2_COLOR); widget_y_input->selection_color(FL_SELECTION_COLOR); @@ -302,7 +304,8 @@ Fl_Double_Window* make_widget_panel() { widget_y_input->when(FL_WHEN_RELEASE); } // Fluid_Coord_Input* widget_y_input { widget_w_input = new Fluid_Coord_Input(215, 150, 55, 20, "Width:"); - widget_w_input->tooltip("The width of the widget."); + widget_w_input->tooltip("The width of the widget as a number or formula.\nFormulas can be simple math,\ + including the variables\nw, pw, sw, cw, and i"); widget_w_input->box(FL_DOWN_BOX); widget_w_input->color(FL_BACKGROUND2_COLOR); widget_w_input->selection_color(FL_SELECTION_COLOR); @@ -316,7 +319,8 @@ Fl_Double_Window* make_widget_panel() { widget_w_input->when(FL_WHEN_RELEASE); } // Fluid_Coord_Input* widget_w_input { widget_h_input = new Fluid_Coord_Input(275, 150, 55, 20, "Height:"); - widget_h_input->tooltip("The height of the widget."); + widget_h_input->tooltip("The height of the widget as a number or formula.\nFormulas can be simple math\ +, including the variables\nh, ph, sh, ch, and i"); widget_h_input->box(FL_DOWN_BOX); widget_h_input->color(FL_BACKGROUND2_COLOR); widget_h_input->selection_color(FL_SELECTION_COLOR); diff --git a/fluid/widget_panel.fl b/fluid/widget_panel.fl index 149902ccb..798a386ac 100644 --- a/fluid/widget_panel.fl +++ b/fluid/widget_panel.fl @@ -264,30 +264,38 @@ Use Ctrl-J for newlines.} xywh {95 40 190 20} labelfont 1 labelsize 11 when 1 te Fl_Input widget_x_input { label {X:} callback x_cb - tooltip {The X position of the widget.} xywh {95 150 55 20} labelsize 11 align 5 textsize 11 + tooltip {The X position of the widget as a number or formula. +Formulas can be simple math, including the variables +x, px, sx, cx, and i} xywh {95 150 55 20} labelsize 11 align 5 textsize 11 class Fluid_Coord_Input } Fl_Input widget_y_input { label {Y:} callback y_cb - tooltip {The Y position of the widget.} xywh {155 150 55 20} labelsize 11 align 5 textsize 11 + tooltip {The Y position of the widget as a number or formula. +Formulas can be simple math, including the variables +y, py, sy, cy, and i} xywh {155 150 55 20} labelsize 11 align 5 textsize 11 class Fluid_Coord_Input } Fl_Input widget_w_input { label {Width:} callback w_cb - tooltip {The width of the widget.} xywh {215 150 55 20} labelsize 11 align 5 textsize 11 + tooltip {The width of the widget as a number or formula. +Formulas can be simple math, including the variables +w, pw, sw, cw, and i} xywh {215 150 55 20} labelsize 11 align 5 textsize 11 class Fluid_Coord_Input } Fl_Input widget_h_input { label {Height:} - callback h_cb - tooltip {The height of the widget.} xywh {275 150 55 20} labelsize 11 align 5 textsize 11 + callback h_cb selected + tooltip {The height of the widget as a number or formula. +Formulas can be simple math, including the variables +h, ph, sh, ch, and i} xywh {275 150 55 20} labelsize 11 align 5 textsize 11 class Fluid_Coord_Input } Fl_Choice {} { label {Children:} - callback wc_relative_cb open selected + callback wc_relative_cb open tooltip {When instantiating a widget class, the children can either be fixed in their original position, automatically be repositioned, or both repsositioned and resized to fit the container.} xywh {335 150 65 20} down_box BORDER_BOX labelsize 11 align 5 textsize 11 } { MenuItem {} { -- cgit v1.2.3