diff options
| author | Matthias Melcher <github@matthiasm.com> | 2023-07-17 20:20:54 +0200 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2023-07-17 20:21:04 +0200 |
| commit | 9bdc7139daef8d9dc7b7e06503cd810d44b6d69c (patch) | |
| tree | bd4fb30d1a2c539a3eb530eb14d1780a9e04db78 | |
| parent | 9794d200b33b438feaf76c960e464b90dd911d58 (diff) | |
FLUID: better initial sizes for buttons and windows
| -rw-r--r-- | fluid/Fd_Snap_Action.cxx | 21 | ||||
| -rw-r--r-- | fluid/Fd_Snap_Action.h | 1 | ||||
| -rw-r--r-- | fluid/Fl_Window_Type.cxx | 12 | ||||
| -rw-r--r-- | fluid/Fl_Window_Type.h | 1 | ||||
| -rw-r--r-- | fluid/custom_widgets.cxx | 2 | ||||
| -rw-r--r-- | fluid/factory.cxx | 197 | ||||
| -rw-r--r-- | fluid/function_panel.cxx | 12 | ||||
| -rw-r--r-- | fluid/function_panel.fl | 5 |
8 files changed, 177 insertions, 74 deletions
diff --git a/fluid/Fd_Snap_Action.cxx b/fluid/Fd_Snap_Action.cxx index 1334b0a05..6f7531007 100644 --- a/fluid/Fd_Snap_Action.cxx +++ b/fluid/Fd_Snap_Action.cxx @@ -1071,6 +1071,27 @@ void Fd_Snap_Action::get_move_stepsize(int &x_step, int &y_step) { } } +/** Fix the given size to the same or next bigger snap position. */ +void Fd_Snap_Action::better_size(int &w, int &h) { + int x_min = 1, y_min = 1, x_inc = 1, y_inc = 1; + get_resize_stepsize(x_inc, y_inc); + if (x_inc < 1) x_inc = 1; + if (y_inc < 1) y_inc = 1; + if ((layout->widget_min_w > 1) && (layout->widget_min_h > 1)) { + x_min = layout->widget_min_w; + y_min = layout->widget_min_h; + } else if ((layout->group_grid_x > 1) && (layout->group_grid_y > 1)) { + x_min = layout->group_grid_x; + y_min = layout->group_grid_y; + } else { + x_min = x_inc; + y_min = y_inc; + } + int ww = fd_max(w - x_min, 0); w = (w - ww + x_inc - 1) / x_inc; w = w * x_inc; w = w + ww; + int hh = fd_max(h - y_min, 0); h = (h - hh + y_inc - 1) / y_inc; h = h * y_inc; h = h + hh; +} + + // ---- snapping prototypes -------------------------------------------- MARK: - /** diff --git a/fluid/Fd_Snap_Action.h b/fluid/Fd_Snap_Action.h index e15431cd1..afa8491d7 100644 --- a/fluid/Fd_Snap_Action.h +++ b/fluid/Fd_Snap_Action.h @@ -191,6 +191,7 @@ public: static void draw_all(Fd_Snap_Data &d); static void get_resize_stepsize(int &x_step, int &y_step); static void get_move_stepsize(int &x_step, int &y_step); + static void better_size(int &w, int &h); }; #endif // _FLUID_FD_SNAP_ACTION_H diff --git a/fluid/Fl_Window_Type.cxx b/fluid/Fl_Window_Type.cxx index 22f39dfc8..a5a43d0cc 100644 --- a/fluid/Fl_Window_Type.cxx +++ b/fluid/Fl_Window_Type.cxx @@ -299,6 +299,18 @@ uchar *Fl_Window_Type::read_image(int &ww, int &hh) { return idata; } +void Fl_Window_Type::ideal_size(int &w, int &h) { + w = 480, h = 320; + if (main_window) { + int sx, sy, sw, sh; + Fl_Window *win = main_window; + int screen = Fl::screen_num(win->x(), win->y()); + Fl::screen_work_area(sx, sy, sw, sh, screen); + w = fd_min(w, sw*3/4); h = fd_min(h, sh*3/4); + Fd_Snap_Action::better_size(w, h); + } +} + // control panel items: diff --git a/fluid/Fl_Window_Type.h b/fluid/Fl_Window_Type.h index cc993f37b..3e662f076 100644 --- a/fluid/Fl_Window_Type.h +++ b/fluid/Fl_Window_Type.h @@ -96,6 +96,7 @@ public: const char *alt_type_name() FL_OVERRIDE {return "fltk::Window";} void open() FL_OVERRIDE; + void ideal_size(int &w, int &h) FL_OVERRIDE; void fix_overlay(); // Update the bounding box, etc uchar *read_image(int &ww, int &hh); // Read an image of the window diff --git a/fluid/custom_widgets.cxx b/fluid/custom_widgets.cxx index f1a12a474..f3b374314 100644 --- a/fluid/custom_widgets.cxx +++ b/fluid/custom_widgets.cxx @@ -92,7 +92,7 @@ int Widget_Bin_Window_Button::handle(int inEvent) return ret; if (!Fl::event_is_click()) { if (!drag_win) { - drag_win = new Fl_Window(0, 0, 100, 100); + drag_win = new Fl_Window(0, 0, 480, 320); drag_win->border(0); drag_win->set_non_modal(); } diff --git a/fluid/factory.cxx b/fluid/factory.cxx index 297814ce7..6fc28ec72 100644 --- a/fluid/factory.cxx +++ b/fluid/factory.cxx @@ -32,6 +32,8 @@ #include "undo.h" #include <FL/Fl.H> +#include <FL/Fl_Box.H> +#include <FL/Fl_Clock.H> #include <FL/Fl_Window.H> #include <FL/Fl_Button.H> #include <FL/Fl_Return_Button.H> @@ -42,6 +44,7 @@ #include <FL/Fl_Group.H> #include <FL/Fl_Menu_Item.H> #include <FL/Fl_Pixmap.H> +#include <FL/Fl_Progress.H> #include <FL/Fl_Tree.H> #include <FL/Fl_Flex.H> #include "../src/flstring.h" @@ -49,21 +52,82 @@ #include <stdio.h> #include <stdlib.h> -//////////////////////////////////////////////////////////////// -#include <FL/Fl_Box.H> -class Fl_Box_Type : public Fl_Widget_Type { + +// ---- Other Types --------------------------------------------------- MARK: - + + +// ---- Box ---- + +class Fl_Box_Type : public Fl_Widget_Type +{ + typedef Fl_Widget_Type super; public: - const char *type_name() FL_OVERRIDE {return "Fl_Box";} - const char *alt_type_name() FL_OVERRIDE {return "fltk::Widget";} - Fl_Widget *widget(int x,int y,int w, int h) FL_OVERRIDE { - return new Fl_Box(x,y,w,h,"label");} - Fl_Widget_Type *_make() FL_OVERRIDE {return new Fl_Box_Type();} + void ideal_size(int &w, int &h) FL_OVERRIDE { + w = 100; h = 100; + Fd_Snap_Action::better_size(w, h); + } + const char *type_name() FL_OVERRIDE { return "Fl_Box"; } + const char *alt_type_name() FL_OVERRIDE { return "fltk::Widget"; } + Fl_Widget *widget(int x, int y, int w, int h) FL_OVERRIDE { + return new Fl_Box(x, y, w, h, "label"); + } + Fl_Widget_Type *_make() FL_OVERRIDE { return new Fl_Box_Type(); } ID id() const FL_OVERRIDE { return ID::Box; } + bool is_a(ID inID) FL_OVERRIDE { return (inID==ID::Box) ? true : super::is_a(inID); } }; + static Fl_Box_Type Fl_Box_type; +// ---- Clock ---- + +class Fl_Clock_Type : public Fl_Widget_Type +{ + typedef Fl_Widget_Type super; +public: + void ideal_size(int &w, int &h) FL_OVERRIDE { + w = 80; h = 80; + Fd_Snap_Action::better_size(w, h); + } + const char *type_name() FL_OVERRIDE { return "Fl_Clock"; } + const char *alt_type_name() FL_OVERRIDE { return "fltk::Clock"; } + Fl_Widget *widget(int x, int y, int w, int h) FL_OVERRIDE { + return new Fl_Clock(x, y, w, h); + } + Fl_Widget_Type *_make() FL_OVERRIDE { return new Fl_Clock_Type(); } + ID id() const FL_OVERRIDE { return ID::Clock; } + bool is_a(ID inID) FL_OVERRIDE { return (inID==ID::Clock) ? true : super::is_a(inID); } +}; + +static Fl_Clock_Type Fl_Clock_type; + + +// ---- Progress ---- + +class Fl_Progress_Type : public Fl_Widget_Type +{ + typedef Fl_Widget_Type super; +public: + void ideal_size(int &w, int &h) FL_OVERRIDE { + w = 120; h = 24; + Fd_Snap_Action::better_size(w, h); + } + const char *type_name() FL_OVERRIDE { return "Fl_Progress"; } + const char *alt_type_name() FL_OVERRIDE { return "fltk::ProgressBar"; } + Fl_Widget *widget(int x, int y, int w, int h) FL_OVERRIDE { + Fl_Progress *myo = new Fl_Progress(x, y, w, h, "label"); + myo->value(50); + return myo; + } + Fl_Widget_Type *_make() FL_OVERRIDE { return new Fl_Progress_Type(); } + ID id() const FL_OVERRIDE { return ID::Progress; } + bool is_a(ID inID) FL_OVERRIDE { return (inID==ID::Progress) ? true : super::is_a(inID); } +}; + +static Fl_Progress_Type Fl_Progress_type; + + // ---- Button Types --------------------------------------------------- MARK: - @@ -86,15 +150,14 @@ class Fl_Button_Type : public Fl_Widget_Type Fl_Menu_Item *subtypes() FL_OVERRIDE { return buttontype_menu; } public: void ideal_size(int &w, int &h) FL_OVERRIDE { - // TODO: this is a really bad size suggestion - Fl_Widget_Type::ideal_size(w, h); - w += 2 * (o->labelsize() - 4); - h = (h / 5) * 5; + h = layout->labelsize + 8; + w = layout->labelsize * 4 + 8; + Fd_Snap_Action::better_size(w, h); } const char *type_name() FL_OVERRIDE { return "Fl_Button"; } const char *alt_type_name() FL_OVERRIDE { return "fltk::Button"; } Fl_Widget *widget(int x, int y, int w, int h) FL_OVERRIDE { - return new Fl_Button(x, y, w, h, "button"); + return new Fl_Button(x, y, w, h, "Button"); } Fl_Widget_Type *_make() FL_OVERRIDE { return new Fl_Button_Type(); } int is_button() const FL_OVERRIDE { return 1; } @@ -115,16 +178,14 @@ class Fl_Return_Button_Type : public Fl_Button_Type typedef Fl_Button_Type super; public: void ideal_size(int &w, int &h) FL_OVERRIDE { - // TODO: this is a really bad size suggestion - Fl_Button_Type::ideal_size(w, h); - int W = o->h(); - if (o->w()/3 < W) W = o->w()/3; - w += W + 8 - o->labelsize(); + h = layout->labelsize + 8; + w = layout->labelsize * 4 + 8 + h; // make room for the symbol + Fd_Snap_Action::better_size(w, h); } const char *type_name() FL_OVERRIDE { return "Fl_Return_Button"; } const char *alt_type_name() FL_OVERRIDE { return "fltk::ReturnButton"; } Fl_Widget *widget(int x, int y, int w, int h) FL_OVERRIDE { - return new Fl_Return_Button(x, y, w, h, "button"); + return new Fl_Return_Button(x, y, w, h, "Button"); } Fl_Widget_Type *_make() FL_OVERRIDE { return new Fl_Return_Button_Type(); } ID id() const FL_OVERRIDE { return ID::Return_Button; } @@ -149,7 +210,7 @@ public: const char *type_name() FL_OVERRIDE { return "Fl_Repeat_Button"; } const char *alt_type_name() FL_OVERRIDE { return "fltk::RepeatButton"; } Fl_Widget *widget(int x, int y, int w, int h) FL_OVERRIDE { - return new Fl_Repeat_Button(x, y, w, h, "button"); + return new Fl_Repeat_Button(x, y, w, h, "Button"); } Fl_Widget_Type *_make() FL_OVERRIDE { return new Fl_Repeat_Button_Type(); } ID id() const FL_OVERRIDE { return ID::Repeat_Button; } @@ -166,14 +227,14 @@ class Fl_Light_Button_Type : public Fl_Button_Type typedef Fl_Button_Type super; public: void ideal_size(int &w, int &h) FL_OVERRIDE { - // TODO: improve this - Fl_Button_Type::ideal_size(w, h); - w += 4; + h = layout->labelsize + 8; + w = layout->labelsize * 4 + 8 + layout->labelsize; // make room for the light + Fd_Snap_Action::better_size(w, h); } const char *type_name() FL_OVERRIDE { return "Fl_Light_Button"; } const char *alt_type_name() FL_OVERRIDE { return "fltk::LightButton"; } Fl_Widget *widget(int x, int y, int w, int h) FL_OVERRIDE { - return new Fl_Light_Button(x, y, w, h, "button"); + return new Fl_Light_Button(x, y, w, h, "Button"); } Fl_Widget_Type *_make() FL_OVERRIDE { return new Fl_Light_Button_Type(); } ID id() const FL_OVERRIDE { return ID::Light_Button; } @@ -190,14 +251,14 @@ class Fl_Check_Button_Type : public Fl_Button_Type typedef Fl_Button_Type super; public: void ideal_size(int &w, int &h) FL_OVERRIDE { - // TODO: fix this - Fl_Button_Type::ideal_size(w, h); - w += 4; + h = layout->labelsize + 8; + w = layout->labelsize * 4 + 8 + layout->labelsize; // make room for the symbol + Fd_Snap_Action::better_size(w, h); } const char *type_name() FL_OVERRIDE { return "Fl_Check_Button"; } const char *alt_type_name() FL_OVERRIDE { return "fltk::CheckButton"; } Fl_Widget *widget(int x, int y, int w, int h) FL_OVERRIDE { - return new Fl_Check_Button(x, y, w, h, "button"); + return new Fl_Check_Button(x, y, w, h, "Button"); } Fl_Widget_Type *_make() FL_OVERRIDE { return new Fl_Check_Button_Type(); } ID id() const FL_OVERRIDE { return ID::Check_Button; } @@ -214,14 +275,14 @@ class Fl_Round_Button_Type : public Fl_Button_Type typedef Fl_Button_Type super; public: void ideal_size(int &w, int &h) FL_OVERRIDE { - // TODO: ideas? - Fl_Button_Type::ideal_size(w, h); - w += 4; + h = layout->labelsize + 8; + w = layout->labelsize * 4 + 8 + layout->labelsize; // make room for the symbol + Fd_Snap_Action::better_size(w, h); } const char *type_name() FL_OVERRIDE { return "Fl_Round_Button"; } const char *alt_type_name() FL_OVERRIDE { return "fltk::RadioButton"; } Fl_Widget *widget(int x, int y, int w, int h) FL_OVERRIDE { - return new Fl_Round_Button(x, y, w, h, "button"); + return new Fl_Round_Button(x, y, w, h, "Button"); } Fl_Widget_Type *_make() FL_OVERRIDE { return new Fl_Round_Button_Type(); } ID id() const FL_OVERRIDE { return ID::Round_Button; } @@ -688,19 +749,6 @@ public: }; static Fl_Simple_Terminal_Type Fl_Simple_Terminal_type; -//////////////////////////////////////////////////////////////// - -#include <FL/Fl_Clock.H> -class Fl_Clock_Type : public Fl_Widget_Type { -public: - const char *type_name() FL_OVERRIDE {return "Fl_Clock";} - const char *alt_type_name() FL_OVERRIDE {return "fltk::Clock";} - Fl_Widget *widget(int x,int y,int w,int h) FL_OVERRIDE { - return new Fl_Clock(x,y,w,h);} - Fl_Widget_Type *_make() FL_OVERRIDE {return new Fl_Clock_Type();} - ID id() const FL_OVERRIDE { return ID::Clock; } -}; -static Fl_Clock_Type Fl_Clock_type; //////////////////////////////////////////////////////////////// @@ -732,21 +780,6 @@ public: }; static Fl_Help_View_Type Fl_Help_View_type; -//////////////////////////////////////////////////////////////// - -#include <FL/Fl_Progress.H> -class Fl_Progress_Type : public Fl_Widget_Type { -public: - const char *type_name() FL_OVERRIDE {return "Fl_Progress";} - const char *alt_type_name() FL_OVERRIDE {return "fltk::ProgressBar";} - Fl_Widget *widget(int x,int y,int w,int h) FL_OVERRIDE { - Fl_Progress *myo = new Fl_Progress(x,y,w,h,"label"); - myo->value(50); - return myo;} - Fl_Widget_Type *_make() FL_OVERRIDE {return new Fl_Progress_Type();} - ID id() const FL_OVERRIDE { return ID::Progress; } -}; -static Fl_Progress_Type Fl_Progress_type; //////////////////////////////////////////////////////////////// @@ -1154,6 +1187,20 @@ Fl_Type *add_new_widget_from_user(Fl_Type *inPrototype, Strategy strategy) { } } } + if (t->is_window()) { + int x = 0, y = 0, w = 480, h = 320; + Fl_Window_Type *wt = (Fl_Window_Type *)t; + wt->ideal_size(w, h); + if (main_window) { + int sx, sy, sw, sh; + Fl_Window *win = main_window; + int screen = Fl::screen_num(win->x(), win->y()); + Fl::screen_work_area(sx, sy, sw, sh, screen); + x = sx + sw/2 - w/2; + y = sy + sh/2 - h/2; + } + wt->o->resize(x, y, w, h); + } // make the new widget visible select_only(t); set_modflag(1); @@ -1186,7 +1233,7 @@ Fl_Type *add_new_widget_from_user(const char *inName, Strategy strategy) { /** Callback for all menu items. */ -static void cb(Fl_Widget *, void *v) { +static void cbf(Fl_Widget *, void *v) { Fl_Type *t = NULL; if (Fl_Type::current && Fl_Type::current->is_group()) t = ((Fl_Type*)v)->make(kAddAsLastChild); @@ -1195,17 +1242,29 @@ static void cb(Fl_Widget *, void *v) { select_only(t); } +/** + Callback for all menu items. + */ +static void cb(Fl_Widget *, void *v) { + Fl_Type *t = NULL; + if (Fl_Type::current && Fl_Type::current->is_group()) + t = add_new_widget_from_user((Fl_Type*)v, kAddAsLastChild); + else + t = add_new_widget_from_user((Fl_Type*)v, kAddAfterCurrent); + select_only(t); +} + Fl_Menu_Item New_Menu[] = { {"Code",0,0,0,FL_SUBMENU}, - {"Function/Method",0,cb,(void*)&Fl_Function_type}, - {"Code",0,cb,(void*)&Fl_Code_type}, - {"Code Block",0,cb,(void*)&Fl_CodeBlock_type}, - {"Declaration",0,cb,(void*)&Fl_Decl_type}, - {"Declaration Block",0,cb,(void*)&Fl_DeclBlock_type}, - {"Class",0,cb,(void*)&Fl_Class_type}, + {"Function/Method",0,cbf,(void*)&Fl_Function_type}, + {"Code",0,cbf,(void*)&Fl_Code_type}, + {"Code Block",0,cbf,(void*)&Fl_CodeBlock_type}, + {"Declaration",0,cbf,(void*)&Fl_Decl_type}, + {"Declaration Block",0,cbf,(void*)&Fl_DeclBlock_type}, + {"Class",0,cbf,(void*)&Fl_Class_type}, {"Widget Class",0,cb,(void*)&Fl_Widget_Class_type}, - {"Comment",0,cb,(void*)&Fl_Comment_type}, - {"Inlined Data",0,cb,(void*)&Fl_Data_type}, + {"Comment",0,cbf,(void*)&Fl_Comment_type}, + {"Inlined Data",0,cbf,(void*)&Fl_Data_type}, {0}, {"Group",0,0,0,FL_SUBMENU}, {0,0,cb,(void*)&Fl_Window_type}, diff --git a/fluid/function_panel.cxx b/fluid/function_panel.cxx index 9200e231a..9a0039f0c 100644 --- a/fluid/function_panel.cxx +++ b/fluid/function_panel.cxx @@ -753,12 +753,20 @@ Fl_Window* make_widgetbin() { o->callback((Fl_Callback*)type_make_cb, (void*)("CodeBlock")); o->image(pixmap[Fl_Type::ID::CodeBlock]); } // Fl_Button* o - { Fl_Button* o = new Fl_Button(55, 46, 24, 24); + { Widget_Bin_Window_Button* o = new Widget_Bin_Window_Button(55, 46, 24, 24); o->tooltip("Widget Class"); o->box(FL_THIN_UP_BOX); + o->color(FL_BACKGROUND_COLOR); + o->selection_color(FL_BACKGROUND_COLOR); + o->labeltype(FL_NORMAL_LABEL); + o->labelfont(0); + o->labelsize(14); + o->labelcolor(FL_FOREGROUND_COLOR); o->callback((Fl_Callback*)type_make_cb, (void*)("widget_class")); + o->align(Fl_Align(FL_ALIGN_CENTER)); + o->when(FL_WHEN_RELEASE); o->image(pixmap[Fl_Type::ID::Widget_Class]); - } // Fl_Button* o + } // Widget_Bin_Window_Button* o { Fl_Button* o = new Fl_Button(5, 71, 24, 24); o->tooltip("Declaration"); o->box(FL_THIN_UP_BOX); diff --git a/fluid/function_panel.fl b/fluid/function_panel.fl index 177eb4ea2..de97d4be5 100644 --- a/fluid/function_panel.fl +++ b/fluid/function_panel.fl @@ -589,9 +589,10 @@ else } Fl_Button {} { user_data {"widget_class"} - callback type_make_cb + callback type_make_cb selected tooltip {Widget Class} xywh {55 46 24 24} box THIN_UP_BOX code0 {o->image(pixmap[Fl_Type::ID::Widget_Class]);} + class Widget_Bin_Window_Button } Fl_Button {} { user_data {"decl"} @@ -747,7 +748,7 @@ else } Fl_Button {} { user_data {"Fl_Value_Output"} - callback type_make_cb selected + callback type_make_cb tooltip {Value Output} xywh {307 21 24 24} box THIN_UP_BOX code0 {o->image(pixmap[Fl_Type::ID::Value_Output]);} class Widget_Bin_Button |
