Button element (and its decendents) can now be disabled

This commit is contained in:
2021-01-04 09:34:11 -06:00
parent 1c22c36d6b
commit 0268a8a5fb
5 changed files with 40 additions and 12 deletions

View File

@@ -37,7 +37,10 @@ module CyberarmEngine
def enter(_sender)
@focus = false unless window.button_down?(Gosu::MsLeft)
if @focus
if !@enabled
@style.background_canvas.background = default(:disabled, :background)
@text.color = default(:disabled, :color)
elsif @focus
@style.background_canvas.background = default(:active, :background)
@text.color = default(:active, :color)
else
@@ -50,9 +53,16 @@ module CyberarmEngine
def left_mouse_button(_sender, _x, _y)
@focus = true
@style.background_canvas.background = default(:active, :background)
unless @enabled
@style.background_canvas.background = default(:disabled, :background)
@text.color = default(:disabled, :color)
else
@style.background_canvas.background = default(:active, :background)
@text.color = default(:active, :color)
end
window.current_state.focus = self
@text.color = default(:active, :color)
:handled
end
@@ -64,14 +74,19 @@ module CyberarmEngine
end
def clicked_left_mouse_button(_sender, _x, _y)
@block.call(self) if @block
@block.call(self) if @enabled && @block
:handled
end
def leave(_sender)
@style.background_canvas.background = default(:background)
@text.color = default(:color)
unless @enabled
@style.background_canvas.background = default(:disabled, :background)
@text.color = default(:disabled, :color)
else
@style.background_canvas.background = default(:background)
@text.color = default(:color)
end
:handled
end
@@ -83,6 +98,14 @@ module CyberarmEngine
end
def recalculate
unless @enabled
@style.background_canvas.background = default(:disabled, :background)
@text.color = default(:disabled, :color)
else
@style.background_canvas.background = default(:background)
@text.color = default(:color)
end
if @image
@width = 0
@height = 0

View File

@@ -19,7 +19,7 @@ module CyberarmEngine
end
def clicked_left_mouse_button(_sender, _x, _y)
@block&.call(self)
@block&.call(self) if @enabled
# return :handled
end