summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scene/gui/tabs.cpp41
-rw-r--r--scene/gui/tabs.h1
2 files changed, 42 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();
diff --git a/scene/gui/tabs.h b/scene/gui/tabs.h
index 7f85280853..5a4533c3d2 100644
--- a/scene/gui/tabs.h
+++ b/scene/gui/tabs.h
@@ -88,6 +88,7 @@ private:
int hover; // hovered tab
int get_tab_width(int p_idx) const;
+ void _ensure_no_over_offset();
protected: