diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2011-05-26 21:12:33 +0200 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2011-05-26 21:12:33 +0200 |
commit | f8e218199b36a728ee7523e8e6a20d088f1befbb (patch) | |
tree | 7eae8b8c62a8f6bfbec9fa6e32292f31cc78021d /src | |
parent | a1fc98c9e52a545f01df80d6844cc4e60217d333 (diff) |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/ui.cc | 43 | ||||
-rw-r--r-- | src/ui.hh | 108 | ||||
-rw-r--r-- | src/uicmd.cc | 6 |
3 files changed, 72 insertions, 85 deletions
@@ -535,7 +535,7 @@ Fl_Widget *UI::make_filemenu_button() Fl_Button *btn; int w = 0, h = 0, padding; - FileButton = btn = new Fl_Button(p_xpos,0,0,0,"W"); + FileButton = btn = new Fl_Button(p_xpos,0,bw,bh,"W"); btn->labeltype(FL_FREE_LABELTYPE); btn->measure_label(w, h); padding = w; @@ -595,7 +595,7 @@ void UI::make_panel(int ww) current(0); if (PanelSize == P_tiny) { - NavBar = new CustGroup(0,0,ww,nh); + NavBar = new CustGroupHorizontal(0,0,ww,nh); NavBar->begin(); make_toolbar(ww,bh); make_filemenu_button(); @@ -604,38 +604,42 @@ void UI::make_panel(int ww) make_progress_bars(0,1); NavBar->box(FL_THIN_UP_FRAME); NavBar->end(); + NavBar->rearrange(); TopGroup->insert(*NavBar,0); } else { if (PanelSize == P_large) { - MenuBar = new CustGroup(0,0,ww,mh); + MenuBar = new CustGroupHorizontal(0,0,ww,mh); MenuBar->begin(); MenuBar->box(FL_THIN_UP_BOX); Fl_Widget *bn = make_filemenu_button(); MenuBar->add_resizable(*new Fl_Box(bn->w(),0,ww - bn->w(),mh)); MenuBar->end(); + MenuBar->rearrange(); TopGroup->insert(*MenuBar,0); p_xpos = 0; - LocBar = new CustGroup(0,0,ww,lh); + LocBar = new CustGroupHorizontal(0,0,ww,lh); LocBar->begin(); make_location(ww); LocBar->resizable(Location); LocBar->end(); + LocBar->rearrange(); TopGroup->insert(*LocBar,1); } else { - LocBar = new CustGroup(0,0,ww,lh); + LocBar = new CustGroupHorizontal(0,0,ww,lh); LocBar->begin(); p_xpos = 0; make_filemenu_button(); make_location(ww); LocBar->resizable(Location); LocBar->end(); + LocBar->rearrange(); TopGroup->insert(*LocBar,0); } // Toolbar p_ypos = 0; - NavBar = new CustGroup(0,0,ww,bh); + NavBar = new CustGroupHorizontal(0,0,ww,bh); NavBar->begin(); make_toolbar(ww,bh); w = new Fl_Box(p_xpos,0,ww-p_xpos-2*pw,bh); @@ -648,6 +652,7 @@ void UI::make_panel(int ww) make_progress_bars(1,0); } NavBar->end(); + NavBar->rearrange(); TopGroup->insert(*NavBar,(MenuBar ? 2 : 1)); } } @@ -658,7 +663,7 @@ void UI::make_panel(int ww) void UI::make_status_bar(int ww, int wh) { const int bm_w = 20; - StatusBar = new CustGroup(0, wh-sh, ww, sh); + StatusBar = new CustGroupHorizontal(0, wh-sh, ww, sh); // Status box StatusOutput = new Fl_Output(0, wh-sh, ww-bm_w, sh); @@ -680,13 +685,14 @@ void UI::make_status_bar(int ww, int wh) StatusBar->end(); StatusBar->resizable(StatusOutput); + StatusBar->rearrange(); } /* * User Interface constructor */ UI::UI(int x, int y, int ui_w, int ui_h, const char* label, const UI *cur_ui) : - Fl_Pack(x, y, ui_w, ui_h, label) + CustGroupVertical(x, y, ui_w, ui_h, label) { PointerOnLink = FALSE; @@ -695,7 +701,6 @@ UI::UI(int x, int y, int ui_w, int ui_h, const char* label, const UI *cur_ui) : Tabs = NULL; TabTooltip = NULL; TopGroup = this; - TopGroup->type(VERTICAL); TopGroup->box(FL_NO_BOX); clear_flag(SHORTCUT_LABEL); @@ -722,8 +727,7 @@ UI::UI(int x, int y, int ui_w, int ui_h, const char* label, const UI *cur_ui) : make_panel(ui_w); // Render area - int main_h = ui_h - (mh+(LocBar?lh:0)+nh+fh+sh); - Main = new Fl_Group(0,0,0,main_h,"Welcome..."); + Main = new Fl_Group(0,0,0,0,"Welcome..."); // size is set by rearrange() Main->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE); Main->box(FL_FLAT_BOX); Main->color(FL_GRAY_RAMP + 3); @@ -743,8 +747,8 @@ UI::UI(int x, int y, int ui_w, int ui_h, const char* label, const UI *cur_ui) : // Status Panel make_status_bar(ui_w, ui_h); TopGroup->add(StatusBar); - TopGroup->end(); + TopGroup->rearrange(); // Make the full screen button (to be attached to the viewport later) // TODO: attach to the viewport @@ -1049,11 +1053,7 @@ void UI::change_panel(int new_size, int small_icons) customize(0); a_UIcmd_set_buttons_sens(a_UIcmd_get_bw_by_widget(this)); - // adjust Main's height - int main_h = h() - (mh+(LocBar?lh:0)+nh+(FindBarSpace?fh:0)+sh); - Main->size(Main->w(), main_h); - redraw(); - + TopGroup->rearrange(); Location->take_focus(); } @@ -1086,6 +1086,7 @@ void UI::set_panelmode(UIPanelmode mode) StatusBar->show(); } Panelmode = mode; + TopGroup->rearrange(); } /* @@ -1110,7 +1111,7 @@ void UI::panelmode_cb_i() void UI::set_render_layout(Fl_Group *nw) { // Resize layout widget to current height - nw->resize(0,0,0,Main->h()); + nw->resize(0,Main->y(),Main->w(),Main->h()); TopGroup->insert(*nw, Main); remove(Main); @@ -1169,7 +1170,6 @@ void UI::findbar_toggle(bool add) insert(*FindBar, StatusBar); FindBar->show(); FindBarSpace = 1; - redraw(); } else { // select text FindBar->show(); @@ -1179,8 +1179,8 @@ void UI::findbar_toggle(bool add) Main->size(Main->w(), Main->h()+FindBar->h()); remove(FindBar); FindBarSpace = 0; - redraw(); /* Main->redraw(); is not enough */ } + TopGroup->rearrange(); } /* @@ -1217,6 +1217,5 @@ void UI::fullscreen_toggle() hide ? StatusBar->hide() : StatusBar->show();; } - Main->size(Main->w(), Main->h() + (hide ? dh : -dh)); - redraw(); + TopGroup->rearrange(); } @@ -7,7 +7,6 @@ #include <FL/Fl_Widget.H> #include <FL/Fl_Button.H> #include <FL/Fl_Input.H> -#include <FL/Fl_Pack.H> #include <FL/Fl_Output.H> #include <FL/Fl_Image.H> #include <FL/Fl_Tabs.H> @@ -40,72 +39,62 @@ class CustTabs; // Class definition ---------------------------------------------------------- /* - * Used to reposition group's widgets when some of them are hidden + * Used to reposition group's widgets when some of them are hidden. + * All children get the height of the group but retain their original width. + * The resizable child get's the remaining space. */ -class CustGroup : public Fl_Group { +class CustGroupHorizontal : public Fl_Group { public: - CustGroup(int x,int y,int w ,int h,const char *l = 0) : + CustGroupHorizontal(int x,int y,int w ,int h,const char *l = 0) : Fl_Group(x,y,w,h,l) { }; - void rearrange(void) { - int n = children(), xpos = 0, r_x1, r_i = -1, i; - init_sizes(); - for (i = 0; i < n; ++i) { - if (child(i) == resizable()) { - r_i = i; - r_x1 = xpos; - break; - } - if (child(i)->visible()) { - child(i)->position(xpos, child(i)->y()); - xpos += child(i)->w(); - } - } - if (r_i < 0) - return; - xpos = w(); - for (i = n - 1; i > r_i; --i) { - if (child(i)->visible()) { - xpos -= child(i)->w(); - child(i)->position(xpos, child(i)->y()); + void rearrange() { + Fl_Widget*const* a = array(); + int sum = 0, _x = x(); + int children_ = children(); + + for (int i=0; i < children_; i++) + if (a[i] != resizable() && a[i]->visible()) + sum += a[i]->w(); + + for (int i=0; i < children_; i++) { + if (a[i] == resizable()) { + a[i]->resize(_x, y(), w() - sum, h()); + } else { + a[i]->resize(_x, y(), a[i]->w(), h()); } + if (a[i]->visible()) + _x += a[i]->w(); } - child(r_i)->resize(r_x1, child(r_i)->y(), xpos-r_x1, child(r_i)->h()); + init_sizes(); redraw(); } - void rearrange_y(void) { - int n = children(), pos = 0, r_pos, r_i = -1, i; +}; - printf("children = %d\n", n); - init_sizes(); - for (i = 0; i < n; ++i) { - if (child(i) == resizable()) { - r_i = i; - r_pos = pos; - break; - } - if (child(i)->visible()) { - printf("child[%d] x=%d y=%d w=%d h=%d\n", - i, child(i)->x(), pos, child(i)->w(), child(i)->h()); - child(i)->position(child(i)->x(), pos); - pos += child(i)->h(); - } - } - if (r_i < 0) - return; - pos = h(); - for (i = n - 1; i > r_i; --i) { - if (child(i)->visible()) { - pos -= child(i)->h(); - printf("child[%d] x=%d y=%d w=%d h=%d\n", - i, child(i)->x(), pos, child(i)->w(), child(i)->h()); - child(i)->position(child(i)->x(), pos); +class CustGroupVertical : public Fl_Group { +public: + CustGroupVertical(int x,int y,int w ,int h,const char *l = 0) : + Fl_Group(x,y,w,h,l) { }; + + void rearrange() { + Fl_Widget*const* a = array(); + int sum = 0, _y = y(); + int children_ = children(); + + for (int i=0; i < children_; i++) + if (a[i] != resizable() && a[i]->visible()) + sum += a[i]->h(); + + for (int i=0; i < children_; i++) { + if (a[i] == resizable()) { + a[i]->resize(x(), _y, w(), h() - sum); + } else { + a[i]->resize(x(), _y, w(), a[i]->h()); } + if (a[i]->visible()) + _y += a[i]->h(); } - child(r_i)->resize(child(r_i)->x(), r_pos, child(r_i)->w(), pos-r_pos); - printf("resizable child[%d] x=%d y=%d w=%d h=%d\n", - r_i, child(r_i)->x(), r_pos, child(r_i)->w(), child(r_i)->h()); - child(r_i)->hide(); + init_sizes(); redraw(); } }; @@ -114,16 +103,15 @@ public: // // UI class definition ------------------------------------------------------- // -class UI : public Fl_Pack { +class UI : public CustGroupVertical { CustTabs *Tabs; char *TabTooltip; - Fl_Group *TopGroup; + CustGroupVertical *TopGroup; Fl_Button *Back, *Forw, *Home, *Reload, *Save, *Stop, *Bookmarks, *Tools, *Clear, *Search, *Help, *FullScreen, *BugMeter, *FileButton; - CustGroup *MenuBar, *LocBar, *NavBar, *StatusBar; + CustGroupHorizontal *MenuBar, *LocBar, *NavBar, *StatusBar; Fl_Input *Location; - Fl_Pack *ProgBox; CustProgressBox *PProg, *IProg; Fl_Group *Panel, *Main; Fl_Output *StatusOutput; diff --git a/src/uicmd.cc b/src/uicmd.cc index c95054c6..a28128c8 100644 --- a/src/uicmd.cc +++ b/src/uicmd.cc @@ -83,13 +83,13 @@ public: /* * Allows fine control of the tabbed interface */ -class CustTabs : public CustGroup { +class CustTabs : public CustGroupHorizontal { int tab_w, tab_h, tab_n; Fl_Wizard *Wizard; int tabcolor_inactive, tabcolor_active, curtab_idx; public: CustTabs (int ww, int wh, int th, const char *lbl=0) : - CustGroup(0,0,ww,th,lbl) { + CustGroupHorizontal(0,0,ww,th,lbl) { tab_w = 80, tab_h = th, tab_n = 0, curtab_idx = -1; tabcolor_active = FL_DARK_CYAN; tabcolor_inactive = 206; Fl_Box *w = new Fl_Box(0,0,0,0,"i n v i s i b l e"); @@ -174,7 +174,7 @@ int CustTabs::handle(int e) } } - return (ret) ? ret : CustGroup::handle(e); + return (ret) ? ret : CustGroupHorizontal::handle(e); } /* |