comparison src/ui.hh @ 2052:89af8495455f

remove use of Fl_Pack to avoid resizing issues CustGroup is split into CustGroupHorizontal and CustGroupVertical. CustGroupVertical is then used to replace Fl_Pack for TopGroup.
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Thu, 26 May 2011 21:12:33 +0200
parents e816e06ee901
children 8d3f28ad46c4
comparison
equal deleted inserted replaced
2051:e1c1d44e56c4 2052:89af8495455f
5 5
6 #include <FL/Fl_Window.H> 6 #include <FL/Fl_Window.H>
7 #include <FL/Fl_Widget.H> 7 #include <FL/Fl_Widget.H>
8 #include <FL/Fl_Button.H> 8 #include <FL/Fl_Button.H>
9 #include <FL/Fl_Input.H> 9 #include <FL/Fl_Input.H>
10 #include <FL/Fl_Pack.H>
11 #include <FL/Fl_Output.H> 10 #include <FL/Fl_Output.H>
12 #include <FL/Fl_Image.H> 11 #include <FL/Fl_Image.H>
13 #include <FL/Fl_Tabs.H> 12 #include <FL/Fl_Tabs.H>
14 13
15 #include "findbar.hh" 14 #include "findbar.hh"
38 class CustTabs; 37 class CustTabs;
39 38
40 39
41 // Class definition ---------------------------------------------------------- 40 // Class definition ----------------------------------------------------------
42 /* 41 /*
43 * Used to reposition group's widgets when some of them are hidden 42 * Used to reposition group's widgets when some of them are hidden.
43 * All children get the height of the group but retain their original width.
44 * The resizable child get's the remaining space.
44 */ 45 */
45 class CustGroup : public Fl_Group { 46 class CustGroupHorizontal : public Fl_Group {
46 public: 47 public:
47 CustGroup(int x,int y,int w ,int h,const char *l = 0) : 48 CustGroupHorizontal(int x,int y,int w ,int h,const char *l = 0) :
48 Fl_Group(x,y,w,h,l) { }; 49 Fl_Group(x,y,w,h,l) { };
49 void rearrange(void) {
50 int n = children(), xpos = 0, r_x1, r_i = -1, i;
51 50
51 void rearrange() {
52 Fl_Widget*const* a = array();
53 int sum = 0, _x = x();
54 int children_ = children();
55
56 for (int i=0; i < children_; i++)
57 if (a[i] != resizable() && a[i]->visible())
58 sum += a[i]->w();
59
60 for (int i=0; i < children_; i++) {
61 if (a[i] == resizable()) {
62 a[i]->resize(_x, y(), w() - sum, h());
63 } else {
64 a[i]->resize(_x, y(), a[i]->w(), h());
65 }
66 if (a[i]->visible())
67 _x += a[i]->w();
68 }
52 init_sizes(); 69 init_sizes();
53 for (i = 0; i < n; ++i) {
54 if (child(i) == resizable()) {
55 r_i = i;
56 r_x1 = xpos;
57 break;
58 }
59 if (child(i)->visible()) {
60 child(i)->position(xpos, child(i)->y());
61 xpos += child(i)->w();
62 }
63 }
64 if (r_i < 0)
65 return;
66 xpos = w();
67 for (i = n - 1; i > r_i; --i) {
68 if (child(i)->visible()) {
69 xpos -= child(i)->w();
70 child(i)->position(xpos, child(i)->y());
71 }
72 }
73 child(r_i)->resize(r_x1, child(r_i)->y(), xpos-r_x1, child(r_i)->h());
74 redraw(); 70 redraw();
75 } 71 }
76 void rearrange_y(void) { 72 };
77 int n = children(), pos = 0, r_pos, r_i = -1, i;
78 73
79 printf("children = %d\n", n); 74 class CustGroupVertical : public Fl_Group {
75 public:
76 CustGroupVertical(int x,int y,int w ,int h,const char *l = 0) :
77 Fl_Group(x,y,w,h,l) { };
78
79 void rearrange() {
80 Fl_Widget*const* a = array();
81 int sum = 0, _y = y();
82 int children_ = children();
83
84 for (int i=0; i < children_; i++)
85 if (a[i] != resizable() && a[i]->visible())
86 sum += a[i]->h();
87
88 for (int i=0; i < children_; i++) {
89 if (a[i] == resizable()) {
90 a[i]->resize(x(), _y, w(), h() - sum);
91 } else {
92 a[i]->resize(x(), _y, w(), a[i]->h());
93 }
94 if (a[i]->visible())
95 _y += a[i]->h();
96 }
80 init_sizes(); 97 init_sizes();
81 for (i = 0; i < n; ++i) {
82 if (child(i) == resizable()) {
83 r_i = i;
84 r_pos = pos;
85 break;
86 }
87 if (child(i)->visible()) {
88 printf("child[%d] x=%d y=%d w=%d h=%d\n",
89 i, child(i)->x(), pos, child(i)->w(), child(i)->h());
90 child(i)->position(child(i)->x(), pos);
91 pos += child(i)->h();
92 }
93 }
94 if (r_i < 0)
95 return;
96 pos = h();
97 for (i = n - 1; i > r_i; --i) {
98 if (child(i)->visible()) {
99 pos -= child(i)->h();
100 printf("child[%d] x=%d y=%d w=%d h=%d\n",
101 i, child(i)->x(), pos, child(i)->w(), child(i)->h());
102 child(i)->position(child(i)->x(), pos);
103 }
104 }
105 child(r_i)->resize(child(r_i)->x(), r_pos, child(r_i)->w(), pos-r_pos);
106 printf("resizable child[%d] x=%d y=%d w=%d h=%d\n",
107 r_i, child(r_i)->x(), r_pos, child(r_i)->w(), child(r_i)->h());
108 child(r_i)->hide();
109 redraw(); 98 redraw();
110 } 99 }
111 }; 100 };
112 101
113 102
114 // 103 //
115 // UI class definition ------------------------------------------------------- 104 // UI class definition -------------------------------------------------------
116 // 105 //
117 class UI : public Fl_Pack { 106 class UI : public CustGroupVertical {
118 CustTabs *Tabs; 107 CustTabs *Tabs;
119 char *TabTooltip; 108 char *TabTooltip;
120 109
121 Fl_Group *TopGroup; 110 CustGroupVertical *TopGroup;
122 Fl_Button *Back, *Forw, *Home, *Reload, *Save, *Stop, *Bookmarks, *Tools, 111 Fl_Button *Back, *Forw, *Home, *Reload, *Save, *Stop, *Bookmarks, *Tools,
123 *Clear, *Search, *Help, *FullScreen, *BugMeter, *FileButton; 112 *Clear, *Search, *Help, *FullScreen, *BugMeter, *FileButton;
124 CustGroup *MenuBar, *LocBar, *NavBar, *StatusBar; 113 CustGroupHorizontal *MenuBar, *LocBar, *NavBar, *StatusBar;
125 Fl_Input *Location; 114 Fl_Input *Location;
126 Fl_Pack *ProgBox;
127 CustProgressBox *PProg, *IProg; 115 CustProgressBox *PProg, *IProg;
128 Fl_Group *Panel, *Main; 116 Fl_Group *Panel, *Main;
129 Fl_Output *StatusOutput; 117 Fl_Output *StatusOutput;
130 Findbar *FindBar; 118 Findbar *FindBar;
131 119