FLUD: This fixes the problem that the children of a Widget_Class_Type are positioned with absolute coordintes. The patch adds another button to the FLUID interface named 'Relative' to the right of the widget position. It is only visible if a Widget_Class_Type is selected. If checked, code will be added that creates an Fl_Group at 0, 0 and later repositions it and all its children into the final position.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4554 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Matthias Melcher 2005-08-30 21:57:23 +00:00
parent aa897faeb3
commit 09783875e4
6 changed files with 65 additions and 7 deletions

View File

@ -520,8 +520,16 @@ public:
class Fl_Widget_Class_Type : private Fl_Window_Type {
public:
Fl_Widget_Class_Type() {
write_public_state = 0;
wc_relative = 0;
}
// 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
virtual void write_properties();
virtual void read_property(const char *);
void write_code1();
void write_code2();

View File

@ -558,6 +558,27 @@ void h_cb(Fl_Value_Input *i, void *v) {
}
}
void wc_relative_cb(Fl_Light_Button *i, void *v) {
if (v == LOAD) {
if (!strcmp(current_widget->type_name(), "widget_class")) {
i->show();
i->value(((Fl_Widget_Class_Type *)current_widget)->wc_relative);
} else {
i->hide();
}
} else {
int mod = 0;
for (Fl_Type *o = Fl_Type::first; o; o = o->next) {
if (o->selected && !strcmp(current_widget->type_name(), "widget_class")) {
Fl_Widget_Class_Type *t = (Fl_Widget_Class_Type *)o;
t->wc_relative = i->value();
mod = 1;
}
}
if (mod) set_modflag(1);
}
}
////////////////////////////////////////////////////////////////
// turn number to string or string to number for saving to file:

View File

@ -1355,10 +1355,23 @@ Fl_Type *Fl_Widget_Class_Type::make() {
myo->add(p);
myo->modal = 0;
myo->non_modal = 0;
myo->wc_relative = 0;
return myo;
}
void Fl_Widget_Class_Type::write_properties() {
Fl_Window_Type::write_properties();
if (wc_relative) write_string("position_relative");
}
void Fl_Widget_Class_Type::read_property(const char *c) {
if (!strcmp(c,"position_relative")) {
wc_relative = 1;
} else {
Fl_Window_Type::read_property(c);
}
}
void Fl_Widget_Class_Type::write_code1() {
#if 0
@ -1399,7 +1412,10 @@ void Fl_Widget_Class_Type::write_code1() {
write_h(" %s(int X, int Y, int W, int H, const char *L = 0);\n", name());
write_c("%s::%s(int X, int Y, int W, int H, const char *L)\n", name(), name());
write_c(" : %s(X, Y, W, H, L) {\n", c);
if (wc_relative)
write_c(" : %s(0, 0, W, H, L) {\n", c);
else
write_c(" : %s(X, Y, W, H, L) {\n", c);
}
write_c(" %s *o = this;\n", name());
@ -1409,6 +1425,7 @@ 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 (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());

View File

@ -241,7 +241,13 @@ Fl_Double_Window* make_widget_panel() {
o->callback((Fl_Callback*)h_cb);
o->align(FL_ALIGN_TOP_LEFT);
}
{ Fl_Box* o = new Fl_Box(330, 145, 60, 20);
{ Fl_Light_Button* o = new Fl_Light_Button(330, 145, 55, 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");
o->labelsize(11);
o->callback((Fl_Callback*)wc_relative_cb);
}
{ Fl_Box* o = new Fl_Box(389, 145, 1, 20);
Fl_Group::current()->resizable(o);
}
o->end();

View File

@ -43,7 +43,7 @@ Function {make_widget_panel()} {open
} {
Fl_Group {} {
label GUI
callback propagate_load
callback propagate_load selected
xywh {5 25 400 290} labelsize 11 when 0 resizable
} {
Fl_Group {} {
@ -151,7 +151,7 @@ Function {make_widget_panel()} {open
}
Fl_Group {} {
label {Position:}
callback propagate_load
callback propagate_load open
xywh {90 145 300 20} labelfont 1 labelsize 11 align 4
} {
Fl_Value_Input widget_x_input {
@ -174,8 +174,13 @@ Function {make_widget_panel()} {open
callback h_cb
tooltip {The height of the widget.} xywh {270 145 55 20} labelsize 11 align 5 maximum 2048 step 1 textsize 11
}
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 {330 145 55 20} labelsize 11
}
Fl_Box {} {
xywh {330 145 60 20} resizable
xywh {389 145 1 20} resizable
}
}
Fl_Group {} {
@ -530,7 +535,7 @@ Function {make_widget_panel()} {open
}
Fl_Button wLiveMode {
label {Live &Mode}
callback live_mode_cb selected
callback live_mode_cb
tooltip {Create a live duplicate of the selected widgets to test resizing and menu behavior.} xywh {142 325 84 20} type Toggle labelsize 11 labelcolor 0
}
}

View File

@ -55,6 +55,8 @@ extern void w_cb(Fl_Value_Input*, void*);
extern Fl_Value_Input *widget_w_input;
extern void h_cb(Fl_Value_Input*, void*);
extern Fl_Value_Input *widget_h_input;
#include <FL/Fl_Light_Button.H>
extern void wc_relative_cb(Fl_Light_Button*, void*);
extern void slider_size_cb(Fl_Value_Input*, void*);
extern void min_cb(Fl_Value_Input*, void*);
extern void max_cb(Fl_Value_Input*, void*);
@ -69,7 +71,6 @@ 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*);