From 8b32c805298da73463d59b448097f949aec84e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Sun, 1 May 2016 16:27:33 +0200 Subject: [PATCH] Tabs: cleanup code, no functional change Some dead code removed, a few cosmetic changes. --- scene/gui/tabs.cpp | 122 +++++++++++++-------------------------------- 1 file changed, 36 insertions(+), 86 deletions(-) diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp index deba06e200e..10eee27950d 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -32,25 +32,23 @@ Size2 Tabs::get_minimum_size() const { - Ref tab_bg = get_stylebox("tab_bg"); Ref tab_fg = get_stylebox("tab_fg"); Ref font = get_font("font"); - Size2 ms(0, MAX( tab_bg->get_minimum_size().height,tab_fg->get_minimum_size().height)+font->get_height() ); - -// h+=MIN( get_constant("label_valign_fg"), get_constant("label_valign_bg") ); + Size2 ms(0, MAX(tab_bg->get_minimum_size().height, tab_fg->get_minimum_size().height)+font->get_height()); for(int i=0;i tex = tabs[i].icon; if (tex.is_valid()) { - ms.height = MAX( ms.height, tex->get_size().height ); + ms.height = MAX(ms.height, tex->get_size().height); if (tabs[i].text!="") ms.width+=get_constant("hseparation"); - } + ms.width+=font->get_string_size(tabs[i].text).width; + if (current==i) ms.width+=tab_fg->get_minimum_size().width; else @@ -58,28 +56,26 @@ Size2 Tabs::get_minimum_size() const { if (tabs[i].right_button.is_valid()) { Ref rb=tabs[i].right_button; - Size2 bms = rb->get_size();//+get_stylebox("button")->get_minimum_size(); + Size2 bms = rb->get_size(); bms.width+=get_constant("hseparation"); - ms.width+=bms.width; ms.height=MAX(bms.height+tab_bg->get_minimum_size().height,ms.height); } if (cb_displaypolicy==CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy==CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i==current)) { Ref cb=get_icon("close"); - Size2 bms = cb->get_size();//+get_stylebox("button")->get_minimum_size(); + Size2 bms = cb->get_size(); bms.width+=get_constant("hseparation"); ms.width+=bms.width; ms.height=MAX(bms.height+tab_bg->get_minimum_size().height,ms.height); } } - ms.width=0; //should make this optional + ms.width=0; //TODO: should make this optional return ms; } - void Tabs::_input_event(const InputEvent& p_event) { if (p_event.type==InputEvent::MOUSE_MOTION) { @@ -101,15 +97,14 @@ void Tabs::_input_event(const InputEvent& p_event) { } } - - + // test hovering to display right or close button int hover_buttons=-1; hover=-1; for(int i=0;i=tabs[i].ofs_cache && pos.x close=get_icon("close"); int h = get_size().height; - - int label_valign_fg = get_constant("label_valign_fg"); - int label_valign_bg = get_constant("label_valign_bg"); - - - int w=0; - + int w = 0; int mw = 0; - { - - - // h+=MIN( get_constant("label_valign_fg"), get_constant("label_valign_bg") ); - - for(int i=0;i sb; - int va; Color col; if (i==current) { sb=tab_fg; - va=label_valign_fg; col=color_fg; } else { sb=tab_bg; - va=label_valign_bg; col=color_bg; } @@ -363,6 +330,7 @@ void Tabs::_notification(int p_what) { w+=slen; if (tabs[i].right_button.is_valid()) { + Ref style = get_stylebox("button"); Ref rb=tabs[i].right_button; @@ -387,10 +355,8 @@ void Tabs::_notification(int p_what) { w+=style->get_margin(MARGIN_RIGHT); tabs[i].rb_rect=rb_rect; - } - if (cb_displaypolicy==CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy==CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i==current)) { Ref style = get_stylebox("button"); @@ -410,11 +376,8 @@ void Tabs::_notification(int p_what) { style->draw(ci,cb_rect); } - //w+=style->get_margin(MARGIN_LEFT); - cb->draw(ci,Point2i( w,cb_rect.pos.y+style->get_margin(MARGIN_TOP) )); w+=cb->get_width(); - //w+=style->get_margin(MARGIN_RIGHT); tabs[i].cb_rect=cb_rect; } @@ -429,28 +392,26 @@ void Tabs::_notification(int p_what) { int vofs = (get_size().height-incr->get_size().height)/2; if (offset>0) - draw_texture(hilite_arrow==0?decr_hl:decr,Point2(limit,vofs)); + draw_texture(hilite_arrow==0 ? decr_hl : decr, Point2(limit,vofs)); else - draw_texture(decr,Point2(limit,vofs),Color(1,1,1,0.5)); + draw_texture(decr,Point2(limit,vofs), Color(1,1,1,0.5)); if (missing_right) - draw_texture(hilite_arrow==1?incr_hl:incr,Point2(limit+decr->get_size().width,vofs)); + draw_texture(hilite_arrow==1 ? incr_hl : incr, Point2(limit+decr->get_size().width,vofs)); else - draw_texture(incr,Point2(limit+decr->get_size().width,vofs),Color(1,1,1,0.5)); + draw_texture(incr,Point2(limit+decr->get_size().width,vofs), Color(1,1,1,0.5)); buttons_visible=true; } else { buttons_visible=false; } - } break; } } int Tabs::get_tab_count() const { - return tabs.size(); } @@ -459,11 +420,9 @@ void Tabs::set_current_tab(int p_current) { ERR_FAIL_INDEX( p_current, get_tab_count() ); - //printf("DEBUG %p: set_current_tab to %i\n", this, p_current); current=p_current; _change_notify("current_tab"); - //emit_signal("tab_changed",current); update(); } @@ -487,9 +446,9 @@ String Tabs::get_tab_title(int p_tab) const{ ERR_FAIL_INDEX_V(p_tab,tabs.size(),""); return tabs[p_tab].text; - } + void Tabs::set_tab_icon(int p_tab,const Ref& p_icon){ ERR_FAIL_INDEX(p_tab,tabs.size()); @@ -498,6 +457,7 @@ void Tabs::set_tab_icon(int p_tab,const Ref& p_icon){ minimum_size_changed(); } + Ref Tabs::get_tab_icon(int p_tab) const{ ERR_FAIL_INDEX_V(p_tab,tabs.size(),Ref()); @@ -506,7 +466,6 @@ Ref Tabs::get_tab_icon(int p_tab) const{ } - void Tabs::set_tab_right_button(int p_tab,const Ref& p_right_button){ ERR_FAIL_INDEX(p_tab,tabs.size()); @@ -556,8 +515,6 @@ void Tabs::remove_tab(int p_idx) { if (current>=tabs.size()) current=tabs.size()-1; - //emit_signal("tab_changed",current); - _ensure_no_over_offset(); } @@ -581,7 +538,7 @@ int Tabs::get_tab_width(int p_idx) const { Ref tab_bg = get_stylebox("tab_bg"); Ref tab_fg = get_stylebox("tab_fg"); Ref font = get_font("font"); - Ref close=get_icon("close"); + int x=0; @@ -593,8 +550,8 @@ int Tabs::get_tab_width(int p_idx) const { } - x+=font->get_string_size(tabs[p_idx].text).width; + if (current==p_idx) x+=tab_fg->get_minimum_size().width; else @@ -602,17 +559,14 @@ int Tabs::get_tab_width(int p_idx) const { if (tabs[p_idx].right_button.is_valid()) { Ref rb=tabs[p_idx].right_button; - Size2 bms = rb->get_size();//+get_stylebox("button")->get_minimum_size(); - bms.width+=get_constant("hseparation"); - - x+=bms.width; + x+=rb->get_width(); + x+=get_constant("hseparation"); } if (cb_displaypolicy==CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy==CLOSE_BUTTON_SHOW_ACTIVE_ONLY && p_idx==current)) { - - Size2 bms = close->get_size();//+get_stylebox("button")->get_minimum_size(); - bms.width+=get_constant("hseparation"); - x+=bms.width; + Ref cb=get_icon("close"); + x+=cb->get_width(); + x+=get_constant("hseparation"); } return x; @@ -668,11 +622,9 @@ void Tabs::ensure_tab_visible(int p_idx) { Ref incr = get_icon("increment"); Ref decr = get_icon("decrement"); - int limit=get_size().width-incr->get_width()-decr->get_width(); - int x=0; for(int i=0;i