summaryrefslogtreecommitdiff
path: root/scene/gui/tabs.cpp
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-01-22 20:19:57 -0300
committerJuan Linietsky <reduzio@gmail.com>2016-01-22 20:19:57 -0300
commitdfbc2dce177462506d9c41dfaa867dd76bd136a7 (patch)
tree64f03033857a052ff3f74cd01f314c9347568ef7 /scene/gui/tabs.cpp
parentfe46f0d2b2292f1cab1135b753acdeba3aa0aa38 (diff)
-Improved tab visibility, fixes #3314
Diffstat (limited to 'scene/gui/tabs.cpp')
-rw-r--r--scene/gui/tabs.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp
index a26acc9c05..ecce71bdbd 100644
--- a/scene/gui/tabs.cpp
+++ b/scene/gui/tabs.cpp
@@ -243,6 +243,10 @@ void Tabs::_notification(int p_what) {
hover=-1;
update();
} break;
+ case NOTIFICATION_RESIZED: {
+
+ _ensure_no_over_offset();
+ } break;
case NOTIFICATION_DRAW: {
RID ci = get_canvas_item();
@@ -587,6 +591,8 @@ void Tabs::remove_tab(int p_idx) {
//emit_signal("tab_changed",current);
+ _ensure_no_over_offset();
+
}
@@ -645,6 +651,39 @@ int Tabs::get_tab_width(int p_idx) const {
return x;
}
+
+void Tabs::_ensure_no_over_offset() {
+
+ if (!is_inside_tree())
+ return;
+
+ Ref<Texture> incr = get_icon("increment");
+ Ref<Texture> decr = get_icon("decrement");
+
+ int limit=get_size().width-incr->get_width()-decr->get_width();
+
+ while(offset>0) {
+
+ int total_w=0;
+ for(int i=0;i<tabs.size();i++) {
+
+ if (i<offset-1)
+ continue;
+
+ total_w+=get_tab_width(i);
+ }
+
+ if (total_w < limit) {
+ offset--;
+ update();
+ } else {
+ break;
+ }
+ }
+
+}
+
+
void Tabs::ensure_tab_visible(int p_idx) {
if (!is_inside_tree())
@@ -652,6 +691,8 @@ void Tabs::ensure_tab_visible(int p_idx) {
ERR_FAIL_INDEX(p_idx,tabs.size());
+ _ensure_no_over_offset();
+
if (p_idx<=offset) {
offset=p_idx;
update();