Skip to content

SBSpinButton

Nikita Yudin edited this page Feb 13, 2024 · 3 revisions

SBSpinButton icon SBSpinButton

Inherits: SBButton

A spin button that represents a selectable items with prev and next buttons.

Description

Think of it as a drop-down list, but navigated using the next and previous controls.

Properties

Let's look on list of all available properties:

Name Type Default Description
items Array[String] [] The items to display in the spin button.
selected int -1 The index of the currently selected item, or -1 if no item is selected.
item_count int 0 The number of items in the spin button.
loop bool false Set to true to enable continuous loop mode. When enabled, clicking next navigation button, when on last item will spin back to the first item. Clicking prev navigation button, when on first item will spin forward to the last item.
is_show_popup bool false Set to true to show the popup when clicking on the button.
popup_allow_reselect bool false Set to true to allow selecting the same item again.
open_popup_button bool false Set to true to open the popup by button click, not just by value.
navigation bool true Set to true to enable navigation using next and prev buttons.
focus_nav bool false Should the naviation only appear when the button is in focus.
nav_separation int 0 Sets the separation between navigation buttons.
nav_theme Theme The theme used for the navigation buttons.
nav_button_flat bool true The theme used for the navigation buttons.
next_icon Texture2D The texture used for the next navigation button.
prev_icon Texture2D The texture used for the previous navigation button.
pagination bool false Set to true to enable pagination.
clickable_bullets bool false If true then clicking on pagination button will cause transition to appropriate item.
fill_bullets bool false Whether the bullets have to fill all the available space.
focus_bullets bool false Should bullets be displayed when the button has focus.
bullet_size Vector2 Vector2(4, 4) The size of each bullet.
bullet_separation int 4 The separation between each bullet.
bullet_margin int 0 The separation between each bullet.
bullet_style StyleBox The style of active bullet.
bullet_inactive_style StyleBox The style of inactive bullet.
bullet_hover StyleBox The style of hovered active bullet.
bullet_inactive_hover StyleBox The style of hovered inactive bullet.
keyboard bool true Enables navigation through items using keyboard or controller.
keyboard_page_up_down bool true When enabled it will enable keyboard navigation by Page Up and Page Down keys.
keyboard_input_handled bool true Stops the input from propagating further down the SceneTree. If true then does not allow scrolling in ScrollContainer.
keyboard_release_on_edges bool false Set to true and will release input event and allow page left/right when on edge positions (in the beginning or in the end).
keyboard_threshold_strength float 0.5 Minimum input strength to trigger item change. See more: method Input.get_action_strength.
keyboard_next_action_name String ui_right Action name for next item.
keyboard_prev_action_name String ui_left Action name for previous item.
mousewheel bool false Enables navigation through items using mouse wheel. By default, moving the mouse down selects the previous item, and moving the mouse up selects the next item.
mousewheel_invert bool false Set to true to invert spining direction.
mousewheel_focus bool true Will spining with the mouse wheel only in focus work.
mousewheel_input_handled bool true Stops the input from propagating further down the SceneTree. If true then does not allow scrolling in ScrollContainer.
mousewheel_release_on_edges bool false Set to true and will release mousewheel event and allow page scrolling when on edge positions (in the beginning or in the end).
mousewheel_events_target MousewheelTargets ALL Node containing the element of the container that accepts mouse wheel events. By default it is SpinButton.
previous_selected int -1 Index number of previously selected item.

Methods

After we initialize we have its initialized instance in variable with helpful methods:

Name Return Description
set_items(value: Array[String]) void Set the items of the list.
get_items() Array[String] Get the items of the list.
get_selected() int Get the selected index. Returns -1 if no item is selected.
get_selected_item() String Get the selected item. Returns an empty string if no item is selected.
set_item_count(value: int) void Set the number of items.
get_item_count() int Get the number of items.
select(index: int) void Selects an item by index and makes it the current item. Passing -1 as the index deselects any currently selected item.
deselect() void Deselects the currently selected item.
spin_prev() void Spin to the previous item.
spin_next() void Spin to the next item.
append_item(items) void Add new items to the beginning. Items could be new item or array with such items.
add_item(items, idx: int) void Add new items to the required index. Items could be new item or array with such items.
remove_all_items() void Remove all items.
remove_item(items_indexes) void Remove selected items. items_indexes could be a number with item index to remove or array with indexes.
get_popup() PopupMenu Returns the PopupMenu contained in this button.

Theme Properties

SpinButton comes with some theme properties that you apply for styling.

See Theme Module


Signals

Name Description
item_selected(index: int) Emitted when an item is selected.
length_changed(length: int) Emitted when the number of items changes.
edged(start: bool, end: bool) Emitted when the navigation edges are reached.