-implement arrows on tabs, when too many tabs are present, fixes #2806

This commit is contained in:
Juan Linietsky 2015-12-14 10:24:28 -03:00
parent 1312df7fdc
commit 83e0e97214
5 changed files with 141 additions and 4 deletions

View file

@ -709,7 +709,7 @@ void CanvasItem::draw_circle(const Point2& p_pos, float p_radius, const Color& p
} }
void CanvasItem::draw_texture(const Ref<Texture>& p_texture,const Point2& p_pos) { void CanvasItem::draw_texture(const Ref<Texture>& p_texture,const Point2& p_pos,const Color& p_modulate) {
if (!drawing) { if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
@ -718,7 +718,7 @@ void CanvasItem::draw_texture(const Ref<Texture>& p_texture,const Point2& p_pos)
ERR_FAIL_COND(p_texture.is_null()); ERR_FAIL_COND(p_texture.is_null());
p_texture->draw(canvas_item,p_pos); p_texture->draw(canvas_item,p_pos,p_modulate);
} }
void CanvasItem::draw_texture_rect(const Ref<Texture>& p_texture,const Rect2& p_rect, bool p_tile,const Color& p_modulate, bool p_transpose) { void CanvasItem::draw_texture_rect(const Ref<Texture>& p_texture,const Rect2& p_rect, bool p_tile,const Color& p_modulate, bool p_transpose) {

View file

@ -211,7 +211,7 @@ public:
void draw_line(const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width=1.0); void draw_line(const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width=1.0);
void draw_rect(const Rect2& p_rect, const Color& p_color); void draw_rect(const Rect2& p_rect, const Color& p_color);
void draw_circle(const Point2& p_pos, float p_radius, const Color& p_color); void draw_circle(const Point2& p_pos, float p_radius, const Color& p_color);
void draw_texture(const Ref<Texture>& p_texture,const Point2& p_pos); void draw_texture(const Ref<Texture>& p_texture, const Point2& p_pos, const Color &p_modulate=Color(1,1,1,1));
void draw_texture_rect(const Ref<Texture>& p_texture, const Rect2& p_rect, bool p_tile=false,const Color& p_modulate=Color(1,1,1), bool p_transpose=false); void draw_texture_rect(const Ref<Texture>& p_texture, const Rect2& p_rect, bool p_tile=false,const Color& p_modulate=Color(1,1,1), bool p_transpose=false);
void draw_texture_rect_region(const Ref<Texture>& p_texture,const Rect2& p_rect, const Rect2& p_src_rect,const Color& p_modulate=Color(1,1,1), bool p_transpose=false); void draw_texture_rect_region(const Ref<Texture>& p_texture,const Rect2& p_rect, const Rect2& p_src_rect,const Color& p_modulate=Color(1,1,1), bool p_transpose=false);
void draw_style_box(const Ref<StyleBox>& p_style_box,const Rect2& p_rect); void draw_style_box(const Ref<StyleBox>& p_style_box,const Rect2& p_rect);

View file

@ -74,6 +74,7 @@ Size2 Tabs::get_minimum_size() const {
} }
} }
ms.width=0; //should make this optional
return ms; return ms;
} }
@ -85,6 +86,23 @@ void Tabs::_input_event(const InputEvent& p_event) {
Point2 pos( p_event.mouse_motion.x, p_event.mouse_motion.y ); Point2 pos( p_event.mouse_motion.x, p_event.mouse_motion.y );
hilite_arrow=-1;
if (buttons_visible) {
Ref<Texture> incr = get_icon("increment");
Ref<Texture> decr = get_icon("decrement");
int limit=get_size().width-incr->get_width()-decr->get_width();
if (pos.x>limit+decr->get_width()) {
hilite_arrow=1;
} else if (pos.x>limit) {
hilite_arrow=0;
}
}
int hover_buttons=-1; int hover_buttons=-1;
hover=-1; hover=-1;
for(int i=0;i<tabs.size();i++) { for(int i=0;i<tabs.size();i++) {
@ -163,9 +181,34 @@ void Tabs::_input_event(const InputEvent& p_event) {
// clicks // clicks
Point2 pos( p_event.mouse_button.x, p_event.mouse_button.y ); Point2 pos( p_event.mouse_button.x, p_event.mouse_button.y );
if (buttons_visible) {
Ref<Texture> incr = get_icon("increment");
Ref<Texture> decr = get_icon("decrement");
int limit=get_size().width-incr->get_width()-decr->get_width();
if (pos.x>limit+decr->get_width()) {
if (missing_right) {
offset++;
update();
}
return;
} else if (pos.x>limit) {
if (offset>0) {
offset--;
update();
}
return;
}
}
int found=-1; int found=-1;
for(int i=0;i<tabs.size();i++) { for(int i=0;i<tabs.size();i++) {
if (i<offset)
continue;
if (tabs[i].rb_rect.has_point(pos)) { if (tabs[i].rb_rect.has_point(pos)) {
rb_pressing=true; rb_pressing=true;
update(); update();
@ -225,7 +268,46 @@ void Tabs::_notification(int p_what) {
int w=0; int w=0;
int mw = get_minimum_size().width; int mw = 0;
{
// h+=MIN( get_constant("label_valign_fg"), get_constant("label_valign_bg") );
for(int i=0;i<tabs.size();i++) {
Ref<Texture> tex = tabs[i].icon;
if (tex.is_valid()) {
if (tabs[i].text!="")
mw+=get_constant("hseparation");
}
mw+=font->get_string_size(tabs[i].text).width;
if (current==i)
mw+=tab_fg->get_minimum_size().width;
else
mw+=tab_bg->get_minimum_size().width;
if (tabs[i].right_button.is_valid()) {
Ref<Texture> rb=tabs[i].right_button;
Size2 bms = rb->get_size();//+get_stylebox("button")->get_minimum_size();
bms.width+=get_constant("hseparation");
mw+=bms.width;
}
if (tabs[i].close_button.is_valid()) {
Ref<Texture> cb=tabs[i].close_button;
Size2 bms = cb->get_size();//+get_stylebox("button")->get_minimum_size();
bms.width+=get_constant("hseparation");
mw+=bms.width;
}
}
}
if (tab_align==ALIGN_CENTER) { if (tab_align==ALIGN_CENTER) {
w=(get_size().width-mw)/2; w=(get_size().width-mw)/2;
@ -238,8 +320,19 @@ void Tabs::_notification(int p_what) {
w=0; w=0;
} }
Ref<Texture> incr = get_icon("increment");
Ref<Texture> decr = get_icon("decrement");
Ref<Texture> incr_hl = get_icon("increment_hilite");
Ref<Texture> decr_hl = get_icon("decrement_hilite");
int limit=get_size().width - incr->get_size().width - decr->get_size().width;
missing_right=false;
for(int i=0;i<tabs.size();i++) { for(int i=0;i<tabs.size();i++) {
if (i<offset)
continue;
tabs[i].ofs_cache=w; tabs[i].ofs_cache=w;
String s = tabs[i].text; String s = tabs[i].text;
@ -247,6 +340,8 @@ void Tabs::_notification(int p_what) {
int slen=font->get_string_size(s).width; int slen=font->get_string_size(s).width;
lsize+=slen; lsize+=slen;
Ref<Texture> icon; Ref<Texture> icon;
if (tabs[i].icon.is_valid()) { if (tabs[i].icon.is_valid()) {
icon = tabs[i].icon; icon = tabs[i].icon;
@ -319,6 +414,16 @@ void Tabs::_notification(int p_what) {
} }
if (w+lsize > limit) {
max_drawn_tab=i-1;
missing_right=true;
break;
} else {
max_drawn_tab=i;
}
Ref<StyleBox> sb; Ref<StyleBox> sb;
int va; int va;
Color col; Color col;
@ -484,6 +589,25 @@ void Tabs::_notification(int p_what) {
} }
if (offset>0 || missing_right) {
int vofs = (get_size().height-incr->get_size().height)/2;
if (offset>0)
draw_texture(hilite_arrow==0?decr_hl:decr,Point2(limit,vofs));
else
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));
else
draw_texture(incr,Point2(limit+decr->get_size().width,vofs),Color(1,1,1,0.5));
buttons_visible=true;
} else {
buttons_visible=false;
}
} break; } break;
} }
@ -673,8 +797,11 @@ Tabs::Tabs() {
tab_align=ALIGN_CENTER; tab_align=ALIGN_CENTER;
rb_hover=-1; rb_hover=-1;
rb_pressing=false; rb_pressing=false;
hilite_arrow=-1;
cb_hover=-1; cb_hover=-1;
cb_pressing=false; cb_pressing=false;
cb_displaypolicy = SHOW_NEVER; // Default : no close button cb_displaypolicy = SHOW_NEVER; // Default : no close button
offset=0;
max_drawn_tab=0;
} }

View file

@ -65,6 +65,12 @@ private:
Rect2 cb_rect; Rect2 cb_rect;
}; };
int offset;
int max_drawn_tab;
int hilite_arrow;
bool buttons_visible;
bool missing_right;
Vector<Tab> tabs; Vector<Tab> tabs;
int current; int current;
Control *_get_tab(int idx) const; Control *_get_tab(int idx) const;

View file

@ -709,6 +709,10 @@ void make_default_theme() {
t->set_stylebox("button_pressed","Tabs", make_stylebox( button_pressed_png,4,4,4,4) ); t->set_stylebox("button_pressed","Tabs", make_stylebox( button_pressed_png,4,4,4,4) );
t->set_stylebox("button","Tabs", make_stylebox( button_normal_png,4,4,4,4) ); t->set_stylebox("button","Tabs", make_stylebox( button_normal_png,4,4,4,4) );
t->set_icon("increment","Tabs",make_icon( scroll_button_right_png));
t->set_icon("increment_hilite","Tabs",make_icon( scroll_button_right_hl_png));
t->set_icon("decrement","Tabs",make_icon( scroll_button_left_png));
t->set_icon("decrement_hilite","Tabs",make_icon( scroll_button_left_hl_png));
t->set_font("font","Tabs", default_font ); t->set_font("font","Tabs", default_font );