Skip to content

Commit

Permalink
Expose force_update_list_size
Browse files Browse the repository at this point in the history
Rename ItemList::_check_shape_changed to force_update_list_size

`force_update_list_size` is especially useful for updating the auto_height_value early
  • Loading branch information
Spartan322 committed Sep 15, 2023
1 parent 7872594 commit 421e8c5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions doc/classes/ItemList.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
Ensure current selection is visible, adjusting the scroll position as necessary.
</description>
</method>
<method name="force_update_list_size">
<return type="void" />
<description>
Forces an update to the list size based on its items. This happens automatically whenever size of the items, or other relevant settings like [member auto_height], change. The method can be used to trigger the update ahead of next drawing pass.
</description>
</method>
<method name="get_item_at_position" qualifiers="const">
<return type="int" />
<param index="0" name="position" type="Vector2" />
Expand Down
6 changes: 4 additions & 2 deletions scene/gui/item_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ void ItemList::_notification(int p_what) {
} break;

case NOTIFICATION_DRAW: {
_check_shape_changed();
force_update_list_size();

int scroll_bar_minwidth = scroll_bar->get_minimum_size().x;
scroll_bar->set_anchor_and_offset(SIDE_LEFT, ANCHOR_END, -scroll_bar_minwidth);
Expand Down Expand Up @@ -1314,7 +1314,7 @@ void ItemList::_notification(int p_what) {
}
}

void ItemList::_check_shape_changed() {
void ItemList::force_update_list_size() {
if (!shape_changed) {
return;
}
Expand Down Expand Up @@ -1855,6 +1855,8 @@ void ItemList::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_text_overrun_behavior", "overrun_behavior"), &ItemList::set_text_overrun_behavior);
ClassDB::bind_method(D_METHOD("get_text_overrun_behavior"), &ItemList::get_text_overrun_behavior);

ClassDB::bind_method(D_METHOD("force_update_list_size"), &ItemList::force_update_list_size);

ADD_PROPERTY(PropertyInfo(Variant::INT, "select_mode", PROPERTY_HINT_ENUM, "Single,Multi"), "set_select_mode", "get_select_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_reselect"), "set_allow_reselect", "get_allow_reselect");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_rmb_select"), "set_allow_rmb_select", "get_allow_rmb_select");
Expand Down
3 changes: 2 additions & 1 deletion scene/gui/item_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ class ItemList : public Control {
} theme_cache;

void _scroll_changed(double);
void _check_shape_changed();
void _shape_text(int p_idx);
void _mouse_exited();

Expand Down Expand Up @@ -281,6 +280,8 @@ class ItemList : public Control {

void set_autoscroll_to_bottom(const bool p_enable);

void force_update_list_size();

VScrollBar *get_v_scroll_bar() { return scroll_bar; }

ItemList();
Expand Down

0 comments on commit 421e8c5

Please sign in to comment.