Skip to content

Commit

Permalink
Merge pull request #46 from HotariTobu:feat/HotariTobu-accept-texture…
Browse files Browse the repository at this point in the history
…-button

Add TextureButton support
  • Loading branch information
HotariTobu authored Nov 24, 2024
2 parents 84ce5ec + 1bb57a3 commit db16b40
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
11 changes: 9 additions & 2 deletions addons/gd_data_binding/scripts/binding_source.gd
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Binder:
target_value_change_signal
)

func to_toggle_button(toggle_button: Button):
func to_toggle_button(toggle_button: BaseButton):
assert(_convert_to(TYPE_BOOL), "A value bound to Button must be a bool.")
assert(toggle_button.toggle_mode, "The button must be toggle mode.")
to(toggle_button, "button_pressed", toggle_button.toggled)
Expand All @@ -81,6 +81,10 @@ class Binder:
assert(_convert_to(TYPE_INT), "A value bound to OptionButton must be an int.")
to(option_button, "selected", option_button.item_selected)

func to_texture_button(texture_button: TextureButton):
assert(_convert_to(TYPE_BOOL), "A value bound to TextureButton must be a bool.")
to_toggle_button(texture_button)

func to_color_rect(color_rect: ColorRect):
assert(_convert_to(TYPE_COLOR), "A value bound to ColorRect must be a color.")
to(color_rect, "color")
Expand Down Expand Up @@ -193,7 +197,7 @@ class Unbinder:
func from(target_object, target_property: StringName):
_source.unbind_from(_source_property, target_object, target_property)

func from_toggle_button(button: Button):
func from_toggle_button(button: BaseButton):
from(button, "button_pressed")

func from_check_box(check_box: CheckBox):
Expand All @@ -208,6 +212,9 @@ class Unbinder:
func from_option_button(option_button: OptionButton):
from(option_button, "selected")

func from_texture_button(texture_button: TextureButton):
from_toggle_button(texture_button)

func from_color_rect(color_rect: ColorRect):
from(color_rect, "color")

Expand Down
23 changes: 23 additions & 0 deletions tests/test_binding_source.gd
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,29 @@ class TestBinder:
assert_eq(_source.int_var, -1)
assert_eq(option_button.selected, 1)

func test_texture_button():
var texture_button = TextureButton.new()
texture_button.toggle_mode = true
_add_and_focus(texture_button)

_source.bind("bool_var").to_texture_button(texture_button)

_source.bool_var = true
assert_true(texture_button.button_pressed)

_accept()
assert_false(_source.bool_var)

_source.unbind("bool_var").from_texture_button(texture_button)

_source.bool_var = true
assert_false(texture_button.button_pressed)

_source.bool_var = false
_accept()
assert_false(_source.bool_var)
assert_true(texture_button.button_pressed)

func test_color_rect():
var color_rect = ColorRect.new()
_add_and_focus(color_rect)
Expand Down

0 comments on commit db16b40

Please sign in to comment.