summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2022-11-06 14:40:18 +0100
committerMatthias Melcher <github@matthiasm.com>2022-11-08 19:09:17 +0100
commitb76152cf6c0346a34a1f866ad1809ad0c6f2e6ea (patch)
tree8cd13cb8e5507c8f110f527e1d4eb8f3a7860f10
parentec47afb7eb5864e915ea89530ffb8b6a81bf230d (diff)
Fluid: widget classes can resize children on instantiation
-rw-r--r--fluid/Fl_Widget_Type.cxx2
-rw-r--r--fluid/Fl_Window_Type.cxx16
-rw-r--r--fluid/Fl_Window_Type.h2
-rw-r--r--fluid/widget_panel.cxx20
-rw-r--r--fluid/widget_panel.fl23
-rw-r--r--fluid/widget_panel.h5
6 files changed, 52 insertions, 16 deletions
diff --git a/fluid/Fl_Widget_Type.cxx b/fluid/Fl_Widget_Type.cxx
index 8a1c0c729..14bba4fd5 100644
--- a/fluid/Fl_Widget_Type.cxx
+++ b/fluid/Fl_Widget_Type.cxx
@@ -754,7 +754,7 @@ void h_cb(Fluid_Coord_Input *i, void *v) {
}
}
-void wc_relative_cb(Fl_Light_Button *i, void *v) {
+void wc_relative_cb(Fl_Choice *i, void *v) {
if (v == LOAD) {
if (!strcmp(current_widget->type_name(), "widget_class")) {
i->show();
diff --git a/fluid/Fl_Window_Type.cxx b/fluid/Fl_Window_Type.cxx
index 39a4c84b3..9138378c3 100644
--- a/fluid/Fl_Window_Type.cxx
+++ b/fluid/Fl_Window_Type.cxx
@@ -1608,12 +1608,17 @@ Fl_Type *Fl_Widget_Class_Type::make(Strategy strategy) {
void Fl_Widget_Class_Type::write_properties() {
Fl_Window_Type::write_properties();
- if (wc_relative) write_string("position_relative");
+ if (wc_relative==1)
+ write_string("position_relative");
+ else if (wc_relative==2)
+ write_string("position_relative_rescale");
}
void Fl_Widget_Class_Type::read_property(const char *c) {
if (!strcmp(c,"position_relative")) {
wc_relative = 1;
+ } else if (!strcmp(c,"position_relative_rescale")) {
+ wc_relative = 2;
} else {
Fl_Window_Type::read_property(c);
}
@@ -1684,8 +1689,10 @@ void Fl_Widget_Class_Type::write_code1() {
write_h("%s%s(int X, int Y, int W, int H, const char *L = 0);\n",
indent(1), trimclassname(name()));
write_c("%s::%s(int X, int Y, int W, int H, const char *L) :\n", name(), trimclassname(name()));
- if (wc_relative)
+ if (wc_relative==1)
write_c("%s%s(0, 0, W, H, L)\n{\n", indent(1), c);
+ else if (wc_relative==2)
+ write_c("%s%s(0, 0, %d, %d, L)\n{\n", indent(1), c, o->w(), o->h());
else
write_c("%s%s(X, Y, W, H, L)\n{\n", indent(1), c);
}
@@ -1698,7 +1705,10 @@ void Fl_Widget_Class_Type::write_code1() {
void Fl_Widget_Class_Type::write_code2() {
write_extra_code();
- if (wc_relative) write_c("%sposition(X, Y);\n", indent());
+ if (wc_relative==1)
+ write_c("%sposition(X, Y);\n", indent());
+ else if (wc_relative==2)
+ write_c("%sresize(X, Y, W, H);\n", indent());
if (modal) write_c("%sset_modal();\n", indent());
else if (non_modal) write_c("%sset_non_modal();\n", indent());
if (!((Fl_Window*)o)->border()) write_c("%sclear_border();\n", indent());
diff --git a/fluid/Fl_Window_Type.h b/fluid/Fl_Window_Type.h
index e1ddcba9c..41cf73f4b 100644
--- a/fluid/Fl_Window_Type.h
+++ b/fluid/Fl_Window_Type.h
@@ -111,7 +111,7 @@ public:
}
// state variables for output:
char write_public_state; // true when public: has been printed
- char wc_relative; // if true, reposition all child widgets in an Fl_Group
+ char wc_relative; // if 1, reposition all children, if 2, reposition and resize
virtual void write_properties();
virtual void read_property(const char *);
diff --git a/fluid/widget_panel.cxx b/fluid/widget_panel.cxx
index 3a8d270e1..1fd59d4e0 100644
--- a/fluid/widget_panel.cxx
+++ b/fluid/widget_panel.cxx
@@ -60,6 +60,13 @@ Fluid_Coord_Input *widget_w_input=(Fluid_Coord_Input *)0;
Fluid_Coord_Input *widget_h_input=(Fluid_Coord_Input *)0;
+Fl_Menu_Item menu_Children[] = {
+ {"Fixed", 0, 0, 0, 0, (uchar)FL_NORMAL_LABEL, 0, 11, 0},
+ {"Reposition", 0, 0, 0, 0, (uchar)FL_NORMAL_LABEL, 0, 11, 0},
+ {"Resize", 0, 0, 0, 0, (uchar)FL_NORMAL_LABEL, 0, 11, 0},
+ {0,0,0,0,0,0,0,0,0}
+};
+
Fl_Value_Input *widget_flex_size=(Fl_Value_Input *)0;
Fl_Check_Button *widget_flex_fixed=(Fl_Check_Button *)0;
@@ -322,12 +329,17 @@ Fl_Double_Window* make_widget_panel() {
widget_h_input->align(Fl_Align(FL_ALIGN_TOP_LEFT));
widget_h_input->when(FL_WHEN_RELEASE);
} // Fluid_Coord_Input* widget_h_input
- { Fl_Light_Button* o = new Fl_Light_Button(335, 150, 65, 20, "Relative");
- o->tooltip("If set, widgets inside a widget class of type Fl_Group are repositioned relat\
-ive to the origin at construction time");
+ { Fl_Choice* o = new Fl_Choice(335, 150, 65, 20, "Children:");
+ o->tooltip("When instantiating a widget class, the children can either be fixed in their \
+original position, automatically be repositioned, or both repsositioned and re\
+sized to fit the container.");
+ o->down_box(FL_BORDER_BOX);
o->labelsize(11);
+ o->textsize(11);
o->callback((Fl_Callback*)wc_relative_cb);
- } // Fl_Light_Button* o
+ o->align(Fl_Align(FL_ALIGN_TOP_LEFT));
+ o->menu(menu_Children);
+ } // Fl_Choice* o
{ Fl_Box* o = new Fl_Box(398, 150, 1, 20);
Fl_Group::current()->resizable(o);
} // Fl_Box* o
diff --git a/fluid/widget_panel.fl b/fluid/widget_panel.fl
index d853efc88..149902ccb 100644
--- a/fluid/widget_panel.fl
+++ b/fluid/widget_panel.fl
@@ -258,7 +258,7 @@ Use Ctrl-J for newlines.} xywh {95 40 190 20} labelfont 1 labelsize 11 when 1 te
}
Fl_Group {} {
label {Position:}
- callback position_group_cb open selected
+ callback position_group_cb open
xywh {95 150 314 20} labelfont 1 labelsize 11 align 4
} {
Fl_Input widget_x_input {
@@ -285,10 +285,23 @@ Use Ctrl-J for newlines.} xywh {95 40 190 20} labelfont 1 labelsize 11 when 1 te
tooltip {The height of the widget.} xywh {275 150 55 20} labelsize 11 align 5 textsize 11
class Fluid_Coord_Input
}
- Fl_Light_Button {} {
- label Relative
- callback wc_relative_cb
- tooltip {If set, widgets inside a widget class of type Fl_Group are repositioned relative to the origin at construction time} xywh {335 150 65 20} labelsize 11
+ Fl_Choice {} {
+ label {Children:}
+ callback wc_relative_cb open selected
+ 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 {} {
+ label Fixed
+ xywh {0 0 31 20} labelsize 11
+ }
+ MenuItem {} {
+ label Reposition
+ xywh {0 0 31 20} labelsize 11
+ }
+ MenuItem {} {
+ label Resize
+ xywh {0 0 31 20} labelsize 11
+ }
}
Fl_Box {} {
xywh {398 150 1 20} resizable
diff --git a/fluid/widget_panel.h b/fluid/widget_panel.h
index 8e3b18efe..5df114e0d 100644
--- a/fluid/widget_panel.h
+++ b/fluid/widget_panel.h
@@ -47,8 +47,7 @@ extern void w_cb(Fluid_Coord_Input*, void*);
extern Fluid_Coord_Input *widget_w_input;
extern void h_cb(Fluid_Coord_Input*, void*);
extern Fluid_Coord_Input *widget_h_input;
-#include <FL/Fl_Light_Button.H>
-extern void wc_relative_cb(Fl_Light_Button*, void*);
+extern void wc_relative_cb(Fl_Choice*, void*);
extern void flex_size_group_cb(Fl_Group*, void*);
#include <FL/Fl_Value_Input.H>
extern void flex_size_cb(Fl_Value_Input*, void*);
@@ -78,6 +77,7 @@ extern void set_max_size_cb(Fl_Button*, void*);
#include "Shortcut_Button.h"
extern void shortcut_in_cb(Shortcut_Button*, void*);
extern void xclass_cb(Fl_Input*, void*);
+#include <FL/Fl_Light_Button.H>
extern void border_cb(Fl_Light_Button*, void*);
extern void modal_cb(Fl_Light_Button*, void*);
extern void non_modal_cb(Fl_Light_Button*, void*);
@@ -126,6 +126,7 @@ extern void cancel_cb(Fl_Button*, void*);
Fl_Double_Window* make_widget_panel();
extern Fl_Menu_Item menu_[];
extern Fl_Menu_Item menu_1[];
+extern Fl_Menu_Item menu_Children[];
extern Fl_Menu_Item menu_2[];
extern Fl_Menu_Item menu_3[];
#endif