summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2005-03-07 23:55:49 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>2005-03-07 23:55:49 +0000
commitcdcb8a50e26d958a811342ff5cd77ed501f290ce (patch)
tree1e637e7cd0fe8c654d6fd5e87cacee6dfa7ade0a
parent120dbf2c46b838de792472af39a6e76da19f544d (diff)
More guide stuff - most of the widgets that need it should have their
own custom ideal_size() function, and we now snap when showing the alignment guides. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4086 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--fluid/Fl_Type.h16
-rw-r--r--fluid/Fl_Widget_Type.cxx4
-rw-r--r--fluid/Fl_Window_Type.cxx78
-rw-r--r--fluid/factory.cxx118
4 files changed, 186 insertions, 30 deletions
diff --git a/fluid/Fl_Type.h b/fluid/Fl_Type.h
index f5fd26924..77c7ee340 100644
--- a/fluid/Fl_Type.h
+++ b/fluid/Fl_Type.h
@@ -530,6 +530,10 @@ extern Fl_Menu_Item button_type_menu[];
class Fl_Menu_Button_Type : public Fl_Menu_Type {
Fl_Menu_Item *subtypes() {return button_type_menu;}
public:
+ virtual void ideal_size(int &w, int &h) {
+ Fl_Widget_Type::ideal_size(w, h);
+ w += 20;
+ }
virtual const char *type_name() {return "Fl_Menu_Button";}
Fl_Widget *widget(int X,int Y,int W,int H) {
return new Fl_Menu_Button(X,Y,W,H,"menu");}
@@ -542,6 +546,10 @@ extern Fl_Menu_Item dummymenu[];
#include <FL/Fl_Choice.H>
class Fl_Choice_Type : public Fl_Menu_Type {
public:
+ virtual void ideal_size(int &w, int &h) {
+ Fl_Widget_Type::ideal_size(w, h);
+ w += 20;
+ }
virtual const char *type_name() {return "Fl_Choice";}
Fl_Widget *widget(int X,int Y,int W,int H) {
Fl_Choice *myo = new Fl_Choice(X,Y,W,H,"choice:");
@@ -566,6 +574,14 @@ class Fl_Input_Choice_Type : public Fl_Menu_Type {
return 1;
}
public:
+ virtual void ideal_size(int &w, int &h) {
+ Fl_Input_Choice *myo = (Fl_Input_Choice *)o;
+ fl_font(myo->textfont(), myo->textsize());
+ h = fl_height() + myo->textsize() - 6;
+ w = o->w() - 20 - Fl::box_dw(o->box());
+ int ww = (int)fl_width('m');
+ w = ((w + ww - 1) / ww) * ww + 20 + Fl::box_dw(o->box());
+ }
virtual const char *type_name() {return "Fl_Input_Choice";}
Fl_Widget *widget(int X,int Y,int W,int H) {
Fl_Input_Choice *myo = new Fl_Input_Choice(X,Y,W,H,"input choice:");
diff --git a/fluid/Fl_Widget_Type.cxx b/fluid/Fl_Widget_Type.cxx
index 8b5a965ed..1396b67c9 100644
--- a/fluid/Fl_Widget_Type.cxx
+++ b/fluid/Fl_Widget_Type.cxx
@@ -71,14 +71,14 @@ Fl_Widget_Type::ideal_size(int &w, int &h) {
h = o->labelsize();
o->measure_label(w, h);
- h += o->labelsize() - 3;
+ h += o->labelsize() - 6;
w += 2 * (o->labelsize() - 4);
}
// Return the ideal widget spacing...
void
Fl_Widget_Type::ideal_spacing(int &x, int &y) {
- if (o->labelsize() < 9)
+ if (o->labelsize() < 10)
x = y = 0;
else if (o->labelsize() < 14)
x = y = 5;
diff --git a/fluid/Fl_Window_Type.cxx b/fluid/Fl_Window_Type.cxx
index 497938698..ee7a51e35 100644
--- a/fluid/Fl_Window_Type.cxx
+++ b/fluid/Fl_Window_Type.cxx
@@ -614,33 +614,31 @@ void Fl_Window_Type::draw_overlay() {
// - check for distance to the window edge
// * FLTK suggests 10 pixels from the edge
int d;
- int xsp, xdl, ydl, ysp;
+ int xsp, ysp;
ideal_spacing(xsp, ysp);
- xdl = (xsp + 1) / 2;
- ydl = (ysp + 1) / 2;
if (drag & DRAG) {
- if (abs(d = ysp - myby) < ydl) {
+ if (abs(d = ysp - myby) < 5) {
dy += d;
mybt += d;
myby = ysp;
draw_v_arrow(mybx+5, myby, 0);
}
- if (abs(d = o->h() - ysp - mybt) < ydl) {
+ if (abs(d = o->h() - ysp - mybt) < 5) {
dy += d;
myby += d;
mybt = o->h()- ysp;
draw_v_arrow(mybx+5, mybt, o->h());
}
- if (abs(d = xsp - mybx) < xdl) {
+ if (abs(d = xsp - mybx) < 5) {
dx += d;
mybr += d;
mybx = xsp;
draw_h_arrow(mybx, myby+5, 0);
}
- if (abs(d = o->w() - xsp - mybr) < xdl) {
+ if (abs(d = o->w() - xsp - mybr) < 5) {
dx += d;
mybx += d;
mybr = o->w()- xsp;
@@ -649,12 +647,11 @@ void Fl_Window_Type::draw_overlay() {
} else if (numselected==1 && selection) {
// check for FLTK preferred sizes
Fl_Widget_Type *mysel = (Fl_Widget_Type *)selection;
- int iw, ih;
-
- mysel->ideal_size(iw, ih);
-
int w = mybr-mybx;
int h = mybt-myby;
+ int iw = w, ih = h;
+
+ mysel->ideal_size(iw, ih);
if (abs(d = h-ih) < 4) {
mybt = myby + ih;
@@ -689,21 +686,49 @@ void Fl_Window_Type::draw_overlay() {
if (!qw->o->visible_r()) continue;
qw->ideal_spacing(xsp, ysp);
- xdl = (xsp + 1) / 2;
- ydl = (ysp + 1) / 2;
// - check horizontal and vertical alignment with other widgets
- if (abs(myby - qw->o->y()) < 3) draw_top_brace(qw->o);
- if (abs(mybx - qw->o->x()) < 3) draw_left_brace(qw->o);
- if (abs(mybr - qw->o->x() - qw->o->w()) < 3) draw_right_brace(qw->o);
- if (abs(mybt - qw->o->y() - qw->o->h()) < 3) draw_bottom_brace(qw->o);
+ if (abs(d = qw->o->y() - myby) < 5) {
+ if (drag & (TOP | DRAG)) dy += d;
+ else dy -= d;
+
+ myby += d;
+ mybt += d;
+
+ draw_top_brace(qw->o);
+ }
+ if (abs(d = qw->o->x() - mybx) < 5) {
+ if (drag & (LEFT | DRAG)) dx += d;
+ else dx -= d;
+
+ mybx += d;
+ mybr += d;
+
+ draw_left_brace(qw->o);
+ }
+ if (abs(d = qw->o->x() + qw->o->w() - mybr) < 5) {
+ if (drag & (LEFT | DRAG)) dx += d;
+ else dx -= d;
+
+ mybx += d;
+ mybr += d;
+
+ draw_right_brace(qw->o);
+ }
+ if (abs(d = qw->o->y() + qw->o->h() - mybt) < 5) {
+ if (drag & (TOP | DRAG)) dy += d;
+ else dy -= d;
+
+ myby += d;
+ mybt += d;
+
+ draw_bottom_brace(qw->o);
+ }
// - check distances between widgets
- // * horizontal and vertical widget to widget is 10 pixels
- if (qw->o->y()>=myby && qw->o->y()<mybt) {
+ if ((qw->o->y()+qw->o->h())>=myby && qw->o->y()<=mybt) {
// Compare left of selected to right of current
- int xx = mybx - (qw->o->x()+qw->o->w());
- if (abs(d = xx-xsp) < xdl) {
+ if (abs(d = xsp - (mybx - qw->o->x() - qw->o->w())) < 5) {
if (drag & (LEFT | DRAG)) dx += d;
else dx -= d;
@@ -714,8 +739,7 @@ void Fl_Window_Type::draw_overlay() {
draw_h_arrow(mybx, (myby+mybt)/2, qw->o->x()+qw->o->w());
} else {
// Compare right of selected to left of current
- xx = qw->o->x() - mybr;
- if (abs(d = xx-xsp) < xdl) {
+ if (abs(d = xsp - (qw->o->x() - mybr)) < 5) {
if (drag & (LEFT | DRAG)) dx += d;
else dx -= d;
@@ -728,10 +752,9 @@ void Fl_Window_Type::draw_overlay() {
}
}
- if (qw->o->x()>=mybx && qw->o->x()<mybr) {
+ if ((qw->o->x()+qw->o->w())>=mybx && qw->o->x()<=mybr) {
// Compare top of selected to bottom of current
- int yy = myby - (qw->o->y()+qw->o->h());
- if (abs(d = yy-ysp) < ydl) {
+ if (abs(d = ysp - (myby - qw->o->y() - qw->o->h())) < 5) {
if (drag & (TOP | DRAG)) dy += d;
else dy -= d;
@@ -742,8 +765,7 @@ void Fl_Window_Type::draw_overlay() {
draw_v_arrow((mybx+mybr)/2, myby, qw->o->y()+qw->o->h());
} else {
// Compare bottom of selected to top of current
- yy = qw->o->y() - mybt;
- if (abs(d = yy-ydl) < ydl) {
+ if (abs(d = ysp - (qw->o->y() - mybt)) < 5) {
if (drag & (TOP | DRAG)) dy += d;
else dy -= d;
diff --git a/fluid/factory.cxx b/fluid/factory.cxx
index 85a150fd9..b2dac3573 100644
--- a/fluid/factory.cxx
+++ b/fluid/factory.cxx
@@ -106,6 +106,12 @@ static Fl_Button_Type Fl_Button_type;
#include <FL/Fl_Return_Button.H>
class Fl_Return_Button_Type : public Fl_Button_Type {
public:
+ virtual void ideal_size(int &w, int &h) {
+ Fl_Widget_Type::ideal_size(w, h);
+ int W = o->h();
+ if (o->w()/3 < W) W = o->w()/3;
+ w += W + 8 - o->labelsize();
+ }
virtual const char *type_name() {return "Fl_Return_Button";}
Fl_Widget *widget(int x,int y,int w,int h) {
return new Fl_Return_Button(x,y,w,h,0);}
@@ -132,6 +138,10 @@ static Fl_Repeat_Button_Type Fl_Repeat_Button_type;
#include <FL/Fl_Light_Button.H>
class Fl_Light_Button_Type : public Fl_Button_Type {
public:
+ virtual void ideal_size(int &w, int &h) {
+ Fl_Widget_Type::ideal_size(w, h);
+ w += o->labelsize() + 2 * Fl::box_dx(o->box()) + 4;
+ }
virtual const char *type_name() {return "Fl_Light_Button";}
Fl_Widget *widget(int x,int y,int w,int h) {
return new Fl_Light_Button(x,y,w,h,"button");}
@@ -145,6 +155,10 @@ static Fl_Light_Button_Type Fl_Light_Button_type;
#include <FL/Fl_Check_Button.H>
class Fl_Check_Button_Type : public Fl_Button_Type {
public:
+ virtual void ideal_size(int &w, int &h) {
+ Fl_Widget_Type::ideal_size(w, h);
+ w += o->labelsize() + 2 * Fl::box_dx(o->box()) + 4;
+ }
virtual const char *type_name() {return "Fl_Check_Button";}
Fl_Widget *widget(int x,int y,int w,int h) {
return new Fl_Check_Button(x,y,w,h,"button");}
@@ -158,6 +172,10 @@ static Fl_Check_Button_Type Fl_Check_Button_type;
#include <FL/Fl_Round_Button.H>
class Fl_Round_Button_Type : public Fl_Button_Type {
public:
+ virtual void ideal_size(int &w, int &h) {
+ Fl_Widget_Type::ideal_size(w, h);
+ w += o->labelsize() + 2 * Fl::box_dx(o->box()) + 4;
+ }
virtual const char *type_name() {return "Fl_Round_Button";}
Fl_Widget *widget(int x,int y,int w,int h) {
return new Fl_Round_Button(x,y,w,h,"button");}
@@ -184,6 +202,16 @@ class Fl_Browser_Type : public Fl_Widget_Type {
Fl_Menu_Item *subtypes() {return browser_type_menu;}
int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
public:
+ virtual void ideal_size(int &w, int &h) {
+ Fl_Browser *myo = (Fl_Browser *)o;
+ fl_font(myo->textfont(), myo->textsize());
+ h -= Fl::box_dh(o->box());
+ w -= Fl::box_dw(o->box());
+ int ww = (int)fl_width('m');
+ w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
+ h = ((h + fl_height() - 1) / fl_height()) * fl_height() +
+ Fl::box_dh(o->box());
+ }
virtual const char *type_name() {return "Fl_Browser";}
Fl_Widget *widget(int x,int y,int w,int h) {
Fl_Browser* b = new Fl_Browser(x,y,w,h);
@@ -219,6 +247,16 @@ class Fl_Check_Browser_Type : public Fl_Widget_Type {
Fl_Menu_Item *subtypes() {return browser_type_menu;}
int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
public:
+ virtual void ideal_size(int &w, int &h) {
+ Fl_Check_Browser *myo = (Fl_Check_Browser *)o;
+ fl_font(myo->textfont(), myo->textsize());
+ h -= Fl::box_dh(o->box());
+ w -= Fl::box_dw(o->box()) - fl_height();
+ int ww = (int)fl_width('m');
+ w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
+ h = ((h + fl_height() - 1) / fl_height()) * fl_height() +
+ Fl::box_dh(o->box());
+ }
virtual const char *type_name() {return "Fl_Check_Browser";}
Fl_Widget *widget(int x,int y,int w,int h) {
Fl_Check_Browser* b = new Fl_Check_Browser(x,y,w,h);
@@ -254,6 +292,16 @@ class Fl_File_Browser_Type : public Fl_Widget_Type {
Fl_Menu_Item *subtypes() {return browser_type_menu;}
int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
public:
+ virtual void ideal_size(int &w, int &h) {
+ Fl_File_Browser *myo = (Fl_File_Browser *)o;
+ fl_font(myo->textfont(), myo->textsize());
+ h -= Fl::box_dh(o->box());
+ w -= Fl::box_dw(o->box()) + fl_height();
+ int ww = (int)fl_width('m');
+ w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
+ h = ((h + fl_height() - 1) / fl_height()) * fl_height() +
+ Fl::box_dh(o->box());
+ }
virtual const char *type_name() {return "Fl_File_Browser";}
Fl_Widget *widget(int x,int y,int w,int h) {
Fl_File_Browser* b = new Fl_File_Browser(x,y,w,h);
@@ -327,6 +375,14 @@ class Fl_Input_Type : public Fl_Widget_Type {
Fl_Menu_Item *subtypes() {return input_type_menu;}
int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
public:
+ virtual void ideal_size(int &w, int &h) {
+ Fl_Input *myo = (Fl_Input *)o;
+ fl_font(myo->textfont(), myo->textsize());
+ h = fl_height() + myo->textsize() - 6;
+ w -= Fl::box_dw(o->box());
+ int ww = (int)fl_width('m');
+ w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
+ }
virtual const char *type_name() {return "Fl_Input";}
Fl_Widget *widget(int x,int y,int w,int h) {
Fl_Input *myo = new Fl_Input(x,y,w,h,"input:");
@@ -357,6 +413,14 @@ class Fl_File_Input_Type : public Fl_Widget_Type {
Fl_Menu_Item *subtypes() {return 0;}
int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
public:
+ virtual void ideal_size(int &w, int &h) {
+ Fl_File_Input *myo = (Fl_File_Input *)o;
+ fl_font(myo->textfont(), myo->textsize());
+ h = fl_height() + myo->textsize() + 4;
+ w -= Fl::box_dw(o->box());
+ int ww = (int)fl_width('m');
+ w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
+ }
virtual const char *type_name() {return "Fl_File_Input";}
Fl_Widget *widget(int x,int y,int w,int h) {
Fl_File_Input *myo = new Fl_File_Input(x,y,w,h,"file:");
@@ -386,6 +450,16 @@ int Fl_File_Input_Type::textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
class Fl_Text_Display_Type : public Fl_Widget_Type {
int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
public:
+ virtual void ideal_size(int &w, int &h) {
+ Fl_Text_Display *myo = (Fl_Text_Display *)o;
+ fl_font(myo->textfont(), myo->textsize());
+ h -= Fl::box_dh(o->box());
+ w -= Fl::box_dw(o->box());
+ int ww = (int)fl_width('m');
+ w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
+ h = ((h + fl_height() - 1) / fl_height()) * fl_height() +
+ Fl::box_dh(o->box());
+ }
virtual const char *type_name() {return "Fl_Text_Display";}
Fl_Widget *widget(int x,int y,int w,int h) {
Fl_Text_Display *myo = new Fl_Text_Display(x,y,w,h);
@@ -414,6 +488,16 @@ int Fl_Text_Display_Type::textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
class Fl_Text_Editor_Type : public Fl_Widget_Type {
int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
public:
+ virtual void ideal_size(int &w, int &h) {
+ Fl_Text_Editor *myo = (Fl_Text_Editor *)o;
+ fl_font(myo->textfont(), myo->textsize());
+ h -= Fl::box_dh(o->box());
+ w -= Fl::box_dw(o->box());
+ int ww = (int)fl_width('m');
+ w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
+ h = ((h + fl_height() - 1) / fl_height()) * fl_height() +
+ Fl::box_dh(o->box());
+ }
virtual const char *type_name() {return "Fl_Text_Editor";}
Fl_Widget *widget(int x,int y,int w,int h) {
Fl_Text_Editor *myo = new Fl_Text_Editor(x,y,w,h);
@@ -454,6 +538,16 @@ static Fl_Clock_Type Fl_Clock_type;
#include <FL/Fl_Help_View.H>
class Fl_Help_View_Type : public Fl_Widget_Type {
public:
+ virtual void ideal_size(int &w, int &h) {
+ Fl_Help_View *myo = (Fl_Help_View *)o;
+ fl_font(myo->textfont(), myo->textsize());
+ h -= Fl::box_dh(o->box());
+ w -= Fl::box_dw(o->box());
+ int ww = (int)fl_width('m');
+ w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
+ h = ((h + fl_height() - 1) / fl_height()) * fl_height() +
+ Fl::box_dh(o->box());
+ }
virtual const char *type_name() {return "Fl_Help_View";}
Fl_Widget *widget(int x,int y,int w,int h) {
Fl_Help_View *myo = new Fl_Help_View(x,y,w,h);
@@ -581,6 +675,14 @@ static Fl_Menu_Item output_type_menu[] = {
class Fl_Output_Type : public Fl_Input_Type {
Fl_Menu_Item *subtypes() {return output_type_menu;}
public:
+ virtual void ideal_size(int &w, int &h) {
+ Fl_Output *myo = (Fl_Output *)o;
+ fl_font(myo->textfont(), myo->textsize());
+ h = fl_height() + myo->textsize() - 6;
+ w -= Fl::box_dw(o->box());
+ int ww = (int)fl_width('m');
+ w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
+ }
virtual const char *type_name() {return "Fl_Output";}
Fl_Widget *widget(int x,int y,int w,int h) {
Fl_Output *myo = new Fl_Output(x,y,w,h,"output:");
@@ -597,6 +699,14 @@ static Fl_Output_Type Fl_Output_type;
#include <FL/Fl_Value_Input.H>
class Fl_Value_Input_Type : public Fl_Widget_Type {
public:
+ virtual void ideal_size(int &w, int &h) {
+ Fl_Value_Input *myo = (Fl_Value_Input *)o;
+ fl_font(myo->textfont(), myo->textsize());
+ h = fl_height() + myo->textsize() - 6;
+ w -= Fl::box_dw(o->box());
+ int ww = (int)fl_width('m');
+ w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
+ }
virtual const char *type_name() {return "Fl_Value_Input";}
int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
int is_valuator() const {return 1;}
@@ -626,6 +736,14 @@ int Fl_Value_Input_Type::textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
#include <FL/Fl_Value_Output.H>
class Fl_Value_Output_Type : public Fl_Widget_Type {
public:
+ virtual void ideal_size(int &w, int &h) {
+ Fl_Value_Output *myo = (Fl_Value_Output *)o;
+ fl_font(myo->textfont(), myo->textsize());
+ h = fl_height() + myo->textsize() - 6;
+ w = o->w() - Fl::box_dw(o->box());
+ int ww = (int)fl_width('m');
+ w = ((w + ww - 1) / ww) * ww + Fl::box_dw(o->box());
+ }
virtual const char *type_name() {return "Fl_Value_Output";}
int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c);
int is_valuator() const {return 1;}