Skip to content

Commit

Permalink
Merge pull request #222 from WhalesState/dev
Browse files Browse the repository at this point in the history
Make `FoldableContainer` function names more consistent.
  • Loading branch information
jss2a98aj authored Jan 8, 2025
2 parents 187bb36 + e5eaa02 commit ad90fbe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
31 changes: 15 additions & 16 deletions doc/classes/FoldableContainer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
Buttons can have tooltips associated with them, which can be retrieved with [method get_button_tooltip] and set with [method set_button_tooltip].
Buttons can have an ID associated with them, which can be retrieved with [method get_button_id] and set with [method set_button_id].
Buttons only support icons not text, and it can be retrieved with [method get_button_icon] and changed with [method set_button_icon].
Buttons can be retrieved by their position with [method get_button_at_position] and by their ID with [method get_button_position].
</description>
<tutorials>
</tutorials>
Expand Down Expand Up @@ -55,20 +54,20 @@
Returns the ID of the button at the given index.
</description>
</method>
<method name="get_button_index" qualifiers="const">
<return type="int" />
<param index="0" name="id" type="int" />
<description>
Returns the position of the button with the given ID.
</description>
</method>
<method name="get_button_metadata" qualifiers="const">
<return type="Variant" />
<param index="0" name="index" type="int" />
<description>
Returns the metadata for the button at the given index.
</description>
</method>
<method name="get_button_position" qualifiers="const">
<return type="int" />
<param index="0" name="id" type="int" />
<description>
Returns the position of the button with the given ID.
</description>
</method>
<method name="get_button_rect" qualifiers="const">
<return type="Rect2" />
<param index="0" name="index" type="int" />
Expand Down Expand Up @@ -111,6 +110,14 @@
Returns whether the button at the given index is toggled on/off.
</description>
</method>
<method name="move_button">
<return type="int" />
<param index="0" name="from" type="int" />
<param index="1" name="to" type="int" />
<description>
Changes the button's position ie. index.
</description>
</method>
<method name="remove_button">
<return type="void" />
<param index="0" name="index" type="int" />
Expand Down Expand Up @@ -158,14 +165,6 @@
Set the metadata for the button at the given index.
</description>
</method>
<method name="set_button_position">
<return type="int" />
<param index="0" name="index" type="int" />
<param index="1" name="position" type="int" />
<description>
Changes the button's position ie. index.
</description>
</method>
<method name="set_button_toggle_mode">
<return type="void" />
<param index="0" name="index" type="int" />
Expand Down
22 changes: 11 additions & 11 deletions scene/gui/foldable_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,22 +226,22 @@ int FoldableContainer::get_button_id(int p_index) const {
return buttons[p_index].id;
}

int FoldableContainer::set_button_position(int p_index, int p_position) {
int FoldableContainer::move_button(int p_from, int p_to) {
int arr_size = buttons.size();
ERR_FAIL_INDEX_V(p_index, arr_size, -1);
ERR_FAIL_INDEX_V(p_from, arr_size, -1);
ERR_FAIL_COND_V(arr_size < 2, -1);
p_position = p_position == -1 ? arr_size - 1 : CLAMP(p_position, 0, arr_size - 1);
ERR_FAIL_COND_V(p_index == p_position, -1);
p_to = p_to == -1 ? arr_size - 1 : CLAMP(p_to, 0, arr_size - 1);
ERR_FAIL_COND_V(p_from == p_to, -1);

Button button = buttons[p_index];
buttons.remove_at(p_index);
Button button = buttons[p_from];
buttons.remove_at(p_from);
arr_size--;
p_position = CLAMP(p_position, 0, arr_size);
p_to = CLAMP(p_to, 0, arr_size);

return buttons.insert(p_position, button) == OK ? p_position : -1;
return buttons.insert(p_to, button) == OK ? p_to : -1;
}

int FoldableContainer::get_button_position(int p_id) const {
int FoldableContainer::get_button_index(int p_id) const {
for (int i = 0; i < buttons.size(); i++) {
if (buttons[i].id == p_id) {
return i;
Expand Down Expand Up @@ -708,8 +708,8 @@ void FoldableContainer::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_button_rect", "index"), &FoldableContainer::get_button_rect);
ClassDB::bind_method(D_METHOD("set_button_id", "index", "id"), &FoldableContainer::set_button_id);
ClassDB::bind_method(D_METHOD("get_button_id", "index"), &FoldableContainer::get_button_id);
ClassDB::bind_method(D_METHOD("set_button_position", "index", "position"), &FoldableContainer::set_button_position);
ClassDB::bind_method(D_METHOD("get_button_position", "id"), &FoldableContainer::get_button_position);
ClassDB::bind_method(D_METHOD("move_button", "from", "to"), &FoldableContainer::move_button);
ClassDB::bind_method(D_METHOD("get_button_index", "id"), &FoldableContainer::get_button_index);
ClassDB::bind_method(D_METHOD("set_button_toggle_mode", "index", "enabled"), &FoldableContainer::set_button_toggle_mode);
ClassDB::bind_method(D_METHOD("get_button_toggle_mode", "index"), &FoldableContainer::get_button_toggle_mode);
ClassDB::bind_method(D_METHOD("set_button_toggled", "index", "toggled_on"), &FoldableContainer::set_button_toggled);
Expand Down
4 changes: 2 additions & 2 deletions scene/gui/foldable_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ class FoldableContainer : public Container {
void set_button_id(int p_index, int p_id);
int get_button_id(int p_index) const;

int set_button_position(int p_index, int p_position);
int get_button_position(int p_id) const;
int move_button(int p_from, int p_to);
int get_button_index(int p_id) const;

void set_button_toggle_mode(int p_index, bool p_mode);
int get_button_toggle_mode(int p_index) const;
Expand Down

0 comments on commit ad90fbe

Please sign in to comment.