diff options
| author | Matthias Melcher <github@matthiasm.com> | 2022-11-01 13:30:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-01 13:30:05 +0100 |
| commit | 93ea93ee2b424ded25358d87529b1160cdb4f80c (patch) | |
| tree | a0a445a21ac71c72e4983a5ed8bf854a70dec3a8 /fluid/Fl_Widget_Type.cxx | |
| parent | 31ec6f623ab76d3f1107af9782237b8d7a089026 (diff) | |
Fluid support for Fl_Flex (#523) and some Fl_Flex improvements
* Adding Fluid support for Fl_Flex, margins, and gap.
* Fluid Fl_Flex mostly working. Fixed in Fl_Flex::set_size().
* Fluid Flex live mode works, interactive dragging works
* Fluid Flex: adding check box for fixed children
* Fluid Flex: visual flexibility indicator in guides.
* Fluid Flex: bug in generated code.
* Fix formatting
* Fixing Tooltip, fixing resize issue PR #518.
* Removing unused variables.
Co-authored-by: Albrecht Schlosser <albrechts.fltk@online.de>
Diffstat (limited to 'fluid/Fl_Widget_Type.cxx')
| -rw-r--r-- | fluid/Fl_Widget_Type.cxx | 280 |
1 files changed, 268 insertions, 12 deletions
diff --git a/fluid/Fl_Widget_Type.cxx b/fluid/Fl_Widget_Type.cxx index 5a968c1f9..8a1c0c729 100644 --- a/fluid/Fl_Widget_Type.cxx +++ b/fluid/Fl_Widget_Type.cxx @@ -1614,8 +1614,7 @@ void textcolor_cb(Fl_Button* i, void* v) { void min_w_cb(Fl_Value_Input* i, void* v) { if (v == LOAD) { - if (!current_widget->is_window()) {i->parent()->hide(); return;} - i->parent()->show(); + if (!current_widget->is_window()) return; i->value(((Fl_Window_Type*)current_widget)->sr_min_w); } else { int mod = 0; @@ -1717,10 +1716,6 @@ void set_max_size_cb(Fl_Button*, void* v) { void slider_size_cb(Fl_Value_Input* i, void* v) { if (v == LOAD) { - if (current_widget->is_window()) - i->parent()->hide(); - else - i->parent()->show(); if (current_widget->is_valuator()<2) {i->deactivate(); return;} i->activate(); i->value(((Fl_Slider*)(current_widget->o))->slider_size()); @@ -1876,6 +1871,271 @@ void value_cb(Fl_Value_Input* i, void* v) { } } +// The following three callbacks cooperate, showing only one of the groups of +// widgets that use the same space in the dialog. + +void values_group_cb(Fl_Group* g, void* v) { + if (v == LOAD) { + if (current_widget->is_flex()) { + g->hide(); + } else if (current_widget->is_window()) { + g->hide(); + } else { + g->show(); + } + propagate_load(g, v); + } +} + +void flex_margin_group_cb(Fl_Group* g, void* v) { + if (v == LOAD) { + if (current_widget->is_flex()) { + g->show(); + } else { + g->hide(); + } + propagate_load(g, v); + } +} + +void size_range_group_cb(Fl_Group* g, void* v) { + if (v == LOAD) { + if (current_widget->is_window()) { + g->show(); + } else { + g->hide(); + } + propagate_load(g, v); + } +} + + +static void flex_margin_cb(Fl_Value_Input* i, void* v, + void (*load_margin)(Fl_Flex*,Fl_Value_Input*), + int (*update_margin)(Fl_Flex*,int)) { + if (v == LOAD) { + if (current_widget->is_flex()) { + load_margin((Fl_Flex*)current_widget->o, i); + } + } else { + int mod = 0; + int new_value = (int)i->value(); + for (Fl_Type *o = Fl_Type::first; o; o = o->next) { + if (o->selected && o->is_flex()) { + Fl_Flex_Type* q = (Fl_Flex_Type*)o; + Fl_Flex* w = (Fl_Flex*)q->o; + if (update_margin(w, new_value)) { + w->layout(); + mod = 1; + } + } + } + if (mod) set_modflag(1); + } +} + +static void load_left_margin(Fl_Flex *w, Fl_Value_Input* i) +{ + int v; + w->margins(&v, NULL, NULL, NULL); + i->value((double)v); +} + +static int update_left_margin(Fl_Flex *w, int new_value) +{ + int l, t, r, b; + w->margins(&l, &t, &r, &b); + if (new_value!=l) { + w->margin(new_value, t, r, b); + return 1; + } else { + return 0; + } +} + +void flex_margin_left_cb(Fl_Value_Input* i, void* v) { + flex_margin_cb(i, v, load_left_margin, update_left_margin); +} + +static void load_top_margin(Fl_Flex *w, Fl_Value_Input* i) +{ + int v; + w->margins(NULL, &v, NULL, NULL); + i->value((double)v); +} + +static int update_top_margin(Fl_Flex *w, int new_value) +{ + int l, t, r, b; + w->margins(&l, &t, &r, &b); + if (new_value!=t) { + w->margin(l, new_value, r, b); + return 1; + } else { + return 0; + } +} + +void flex_margin_top_cb(Fl_Value_Input* i, void* v) { + flex_margin_cb(i, v, load_top_margin, update_top_margin); +} + +static void load_right_margin(Fl_Flex *w, Fl_Value_Input* i) +{ + int v; + w->margins(NULL, NULL, &v, NULL); + i->value((double)v); +} + +static int update_right_margin(Fl_Flex *w, int new_value) +{ + int l, t, r, b; + w->margins(&l, &t, &r, &b); + if (new_value!=r) { + w->margin(l, t, new_value, b); + return 1; + } else { + return 0; + } +} + +void flex_margin_right_cb(Fl_Value_Input* i, void* v) { + flex_margin_cb(i, v, load_right_margin, update_right_margin); +} + +static void load_bottom_margin(Fl_Flex *w, Fl_Value_Input* i) +{ + int v; + w->margins(NULL, NULL, NULL, &v); + i->value((double)v); +} + +static int update_bottom_margin(Fl_Flex *w, int new_value) +{ + int l, t, r, b; + w->margins(&l, &t, &r, &b); + if (new_value!=b) { + w->margin(l, t, r, new_value); + return 1; + } else { + return 0; + } +} + +void flex_margin_bottom_cb(Fl_Value_Input* i, void* v) { + flex_margin_cb(i, v, load_bottom_margin, update_bottom_margin); +} + +static void load_gap(Fl_Flex *w, Fl_Value_Input* i) +{ + int v = w->gap(); + i->value((double)v); +} + +static int update_gap(Fl_Flex *w, int new_value) +{ + int g = w->gap(); + if (new_value!=g) { + w->gap(new_value); + return 1; + } else { + return 0; + } +} + +void flex_margin_gap_cb(Fl_Value_Input* i, void* v) { + flex_margin_cb(i, v, load_gap, update_gap); +} + +void position_group_cb(Fl_Group* g, void* v) { + if (v == LOAD) { + if (Fl_Flex_Type::parent_is_flex(current_widget)) { + g->hide(); + } else { + g->show(); + } + } + propagate_load(g, v); +} + +void flex_size_group_cb(Fl_Group* g, void* v) { + if (v == LOAD) { + if (Fl_Flex_Type::parent_is_flex(current_widget)) { + g->show(); + } else { + g->hide(); + } + } + propagate_load(g, v); +} + +void flex_size_cb(Fl_Value_Input* i, void* v) { + if (v == LOAD) { + if (Fl_Flex_Type::parent_is_flex(current_widget)) { + i->value(Fl_Flex_Type::size(current_widget)); + } + } else { + int mod = 0; + int new_size = (int)i->value(); + for (Fl_Type *o = Fl_Type::first; o; o = o->next) { + if (o->selected && o->is_widget() && Fl_Flex_Type::parent_is_flex(o)) { + Fl_Widget* w = (Fl_Widget*)((Fl_Widget_Type*)o)->o; + Fl_Flex* f = (Fl_Flex*)((Fl_Flex_Type*)o->parent)->o; + int was_fixed = f->set_size(w); + if (new_size==0) { + if (was_fixed) { + f->set_size(w, 0); + f->layout(); + widget_flex_fixed->value(0); + mod = 1; + } + } else { + int old_size = Fl_Flex_Type::size(o); + if (old_size!=new_size || !was_fixed) { + f->set_size(w, new_size); + f->layout(); + widget_flex_fixed->value(1); + mod = 1; + } + } + } + } + if (mod) set_modflag(1); + } +} + +void flex_fixed_cb(Fl_Check_Button* i, void* v) { + if (v == LOAD) { + if (Fl_Flex_Type::parent_is_flex(current_widget)) { + i->value(Fl_Flex_Type::is_fixed(current_widget)); + } + } else { + int mod = 0; + int new_fixed = (int)i->value(); + for (Fl_Type *o = Fl_Type::first; o; o = o->next) { + if (o->selected && o->is_widget() && Fl_Flex_Type::parent_is_flex(o)) { + Fl_Widget* w = (Fl_Widget*)((Fl_Widget_Type*)o)->o; + Fl_Flex* f = (Fl_Flex*)((Fl_Flex_Type*)o->parent)->o; + int was_fixed = f->set_size(w); + if (new_fixed==0) { + if (was_fixed) { + f->set_size(w, 0); + f->layout(); + mod = 1; + } + } else { + if (!was_fixed) { + f->set_size(w, Fl_Flex_Type::size(o)); + f->layout(); + mod = 1; + } + } + } + } + if (mod) set_modflag(1); + } +} + //////////////////////////////////////////////////////////////// // subtypes: @@ -1918,6 +2178,8 @@ void subtype_cb(Fl_Choice* i, void* v) { if (q->subtypes()==m) { if (q->is_spinner()) ((Fl_Spinner*)q->o)->type(n); + else if (q->is_flex()) + ((Fl_Flex_Type*)q)->change_subtype_to(n); else q->o->type(n); q->redraw(); @@ -3048,9 +3310,3 @@ void Fl_Widget_Type::copy_properties() { w->parent()->resizable(o); } -void Fl_Pack_Type::copy_properties() -{ - Fl_Group_Type::copy_properties(); - Fl_Pack *d = (Fl_Pack*)live_widget, *s =(Fl_Pack*)o; - d->spacing(s->spacing()); -} |
