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

@@ -13,10 +13,10 @@ module CyberarmEngine
@options = options @options = options
@block = block @block = block
@focus = false @focus = @options[:focus].nil? ? false : @options[:focus]
@enabled = true @enabled = @options[:enabled].nil? ? true : @options[:enabled]
@visible = true @visible = @options[:visible].nil? ? true : @options[:visible]
@tip = @options[:tip] || "" @tip = @options[:tip] || ""
@style = Style.new(options) @style = Style.new(options)

View File

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

View File

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

View File

@@ -82,6 +82,11 @@ module CyberarmEngine
active: { active: {
color: Gosu::Color::BLACK, color: Gosu::Color::BLACK,
background: ["ffB23E41".to_i(16)] background: ["ffB23E41".to_i(16)]
},
disabled: {
color: Gosu::Color::GRAY,
background: 0xff303030
} }
}, },

View File

@@ -21,7 +21,7 @@ module CyberarmEngine
def initialize(width: 800, height: 600, fullscreen: false, update_interval: 1000.0 / 60, resizable: false, borderless: false) def initialize(width: 800, height: 600, fullscreen: false, update_interval: 1000.0 / 60, resizable: false, borderless: false)
@show_cursor = false @show_cursor = false
super(width, height, fullscreen: fullscreen, update_interval: update_interval, resizable: resizable, borderless: borderless) super(width, height, fullscreen: fullscreen, update_interval: update_interval, resizable: resizable)
$window = self $window = self
@last_frame_time = Gosu.milliseconds - 1 @last_frame_time = Gosu.milliseconds - 1
@current_frame_time = Gosu.milliseconds @current_frame_time = Gosu.milliseconds