-Improved tab visibility, fixes #3314

This commit is contained in:
Juan Linietsky 2016-01-22 20:19:57 -03:00
parent fe46f0d2b2
commit dfbc2dce17
2 changed files with 42 additions and 0 deletions

View file

@ -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();

View file

@ -88,6 +88,7 @@ private:
int hover; // hovered tab
int get_tab_width(int p_idx) const;
void _ensure_no_over_offset();
protected: