summaryrefslogtreecommitdiff
path: root/scene/gui/tabs.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/tabs.cpp')
-rw-r--r--scene/gui/tabs.cpp168
1 files changed, 148 insertions, 20 deletions
diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp
index 6d84f028b3..14cd0bee8e 100644
--- a/scene/gui/tabs.cpp
+++ b/scene/gui/tabs.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -58,7 +58,7 @@ Size2 Tabs::get_minimum_size() const {
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();
+ Size2 bms = rb->get_size();//+get_stylebox("button")->get_minimum_size();
bms.width+=get_constant("hseparation");
ms.width+=bms.width;
@@ -67,14 +67,14 @@ Size2 Tabs::get_minimum_size() const {
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();
+ Size2 bms = cb->get_size();//+get_stylebox("button")->get_minimum_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
return ms;
}
@@ -86,6 +86,23 @@ void Tabs::_input_event(const InputEvent& p_event) {
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;
hover=-1;
for(int i=0;i<tabs.size();i++) {
@@ -103,11 +120,13 @@ void Tabs::_input_event(const InputEvent& p_event) {
// test hovering right button and close button
if (tabs[i].rb_rect.has_point(pos)) {
rb_hover=i;
+ cb_hover=-1;
hover_buttons = i;
break;
}
else if (tabs[i].cb_rect.has_point(pos)) {
cb_hover=i;
+ rb_hover=-1;
hover_buttons = i;
break;
}
@@ -162,9 +181,34 @@ void Tabs::_input_event(const InputEvent& p_event) {
// clicks
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;
for(int i=0;i<tabs.size();i++) {
+ if (i<offset)
+ continue;
if (tabs[i].rb_rect.has_point(pos)) {
rb_pressing=true;
update();
@@ -224,7 +268,46 @@ void Tabs::_notification(int p_what) {
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) {
w=(get_size().width-mw)/2;
@@ -237,8 +320,19 @@ void Tabs::_notification(int p_what) {
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++) {
+ if (i<offset)
+ continue;
tabs[i].ofs_cache=w;
String s = tabs[i].text;
@@ -246,6 +340,8 @@ void Tabs::_notification(int p_what) {
int slen=font->get_string_size(s).width;
lsize+=slen;
+
+
Ref<Texture> icon;
if (tabs[i].icon.is_valid()) {
icon = tabs[i].icon;
@@ -262,9 +358,9 @@ void Tabs::_notification(int p_what) {
Ref<Texture> rb=tabs[i].right_button;
lsize+=get_constant("hseparation");
- lsize+=style->get_margin(MARGIN_LEFT);
+ //lsize+=style->get_margin(MARGIN_LEFT);
lsize+=rb->get_width();
- lsize+=style->get_margin(MARGIN_RIGHT);
+ //lsize+=style->get_margin(MARGIN_RIGHT);
}
@@ -276,9 +372,9 @@ void Tabs::_notification(int p_what) {
Ref<Texture> rb=tabs[i].close_button;
lsize+=get_constant("hseparation");
- lsize+=style->get_margin(MARGIN_LEFT);
+ //lsize+=style->get_margin(MARGIN_LEFT);
lsize+=rb->get_width();
- lsize+=style->get_margin(MARGIN_RIGHT);
+ //lsize+=style->get_margin(MARGIN_RIGHT);
}
} break;
@@ -289,9 +385,9 @@ void Tabs::_notification(int p_what) {
Ref<Texture> rb=tabs[i].close_button;
lsize+=get_constant("hseparation");
- lsize+=style->get_margin(MARGIN_LEFT);
+ //lsize+=style->get_margin(MARGIN_LEFT);
lsize+=rb->get_width();
- lsize+=style->get_margin(MARGIN_RIGHT);
+ //lsize+=style->get_margin(MARGIN_RIGHT);
}
}
@@ -303,9 +399,9 @@ void Tabs::_notification(int p_what) {
Ref<Texture> rb=tabs[i].close_button;
lsize+=get_constant("hseparation");
- lsize+=style->get_margin(MARGIN_LEFT);
+ //lsize+=style->get_margin(MARGIN_LEFT);
lsize+=rb->get_width();
- lsize+=style->get_margin(MARGIN_RIGHT);
+ //lsize+=style->get_margin(MARGIN_RIGHT);
}
}
@@ -318,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;
int va;
Color col;
@@ -404,11 +510,11 @@ void Tabs::_notification(int p_what) {
style->draw(ci,cb_rect);
}
- w+=style->get_margin(MARGIN_LEFT);
+ //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);
+ //w+=style->get_margin(MARGIN_RIGHT);
tabs[i].cb_rect=cb_rect;
}
} break;
@@ -432,11 +538,11 @@ void Tabs::_notification(int p_what) {
style->draw(ci,cb_rect);
}
- w+=style->get_margin(MARGIN_LEFT);
+ //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);
+ //w+=style->get_margin(MARGIN_RIGHT);
tabs[i].cb_rect=cb_rect;
}
}
@@ -461,11 +567,11 @@ void Tabs::_notification(int p_what) {
style->draw(ci,cb_rect);
}
- w+=style->get_margin(MARGIN_LEFT);
+ //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);
+ //w+=style->get_margin(MARGIN_RIGHT);
tabs[i].cb_rect=cb_rect;
}
}
@@ -483,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;
}
@@ -583,7 +708,7 @@ void Tabs::add_tab(const String& p_str,const Ref<Texture>& p_icon) {
t.text=p_str;
t.icon=p_icon;
- t.close_button = get_icon("Close","EditorIcons");
+ t.close_button = get_icon("close");
tabs.push_back(t);
@@ -672,8 +797,11 @@ Tabs::Tabs() {
tab_align=ALIGN_CENTER;
rb_hover=-1;
rb_pressing=false;
+ hilite_arrow=-1;
cb_hover=-1;
cb_pressing=false;
cb_displaypolicy = SHOW_NEVER; // Default : no close button
+ offset=0;
+ max_drawn_tab=0;
}