mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-15 20:52:35 +00:00
Added support for TextBlock's to have text_v_align to compliment text_h_align, EditLine and EditBox will now preserve their focus appear, fixed crash in ToggleButton due to using :Label instead of :TextBlock, misc. tweaks.
This commit is contained in:
@@ -455,8 +455,8 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
else # Handle min_width/height and max_width/height
|
||||
return @style.send(:"min_#{dimension}") if @style.send(:"min_#{dimension}") && new_size < @style.send(:"min_#{dimension}")
|
||||
return @style.send(:"max_#{dimension}") if @style.send(:"max_#{dimension}") && new_size > @style.send(:"max_#{dimension}")
|
||||
return @style.send(:"min_#{dimension}") if @style.send(:"min_#{dimension}") && new_size.to_f < @style.send(:"min_#{dimension}")
|
||||
return @style.send(:"max_#{dimension}") if @style.send(:"max_#{dimension}") && new_size.to_f > @style.send(:"max_#{dimension}")
|
||||
end
|
||||
|
||||
new_size
|
||||
|
||||
@@ -32,6 +32,7 @@ module CyberarmEngine
|
||||
@text_input.filter = @filter
|
||||
@text_input.text = text
|
||||
@last_text_value = text
|
||||
@last_caret_position = @text_input.caret_pos
|
||||
|
||||
@offset_x = 0
|
||||
@offset_y = 0
|
||||
@@ -82,6 +83,12 @@ module CyberarmEngine
|
||||
publish(:changed, value)
|
||||
end
|
||||
|
||||
if @last_caret_position != @text_input.caret_pos
|
||||
@last_caret_position = @text_input.caret_pos
|
||||
@show_caret = true
|
||||
@caret_last_interval = Gosu.milliseconds
|
||||
end
|
||||
|
||||
if Gosu.milliseconds >= @caret_last_interval + @caret_interval
|
||||
@caret_last_interval = Gosu.milliseconds
|
||||
|
||||
@@ -203,20 +210,35 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def focus(sender)
|
||||
super
|
||||
|
||||
@focus = true
|
||||
window.text_input = @text_input
|
||||
@text_input.caret_pos = @text_input.selection_start = @text_input.text.length
|
||||
|
||||
update_styles(:active)
|
||||
|
||||
:handled
|
||||
end
|
||||
|
||||
def enter(sender)
|
||||
_has_focus = @focus
|
||||
if @enabled && @focus
|
||||
update_styles(:active)
|
||||
elsif @enabled && !@focus
|
||||
update_styles(:hover)
|
||||
else
|
||||
update_styles(:disabled)
|
||||
end
|
||||
|
||||
super
|
||||
:handled
|
||||
end
|
||||
|
||||
@focus = _has_focus
|
||||
def leave(sender)
|
||||
if @enabled && @focus
|
||||
update_styles(:active)
|
||||
elsif @enabled && !@focus
|
||||
update_styles
|
||||
else
|
||||
update_styles(:disabled)
|
||||
end
|
||||
|
||||
:handled
|
||||
end
|
||||
|
||||
@@ -50,7 +50,7 @@ module CyberarmEngine
|
||||
@text.y = @style.border_thickness_top + @style.padding_top + @y
|
||||
@text.z = @z + 3
|
||||
|
||||
if (text_alignment = @options[:text_align])
|
||||
if (text_alignment = @options[:text_align] || @options[:text_h_align])
|
||||
case text_alignment
|
||||
when :left
|
||||
@text.x = @style.border_thickness_left + @style.padding_left + @x
|
||||
@@ -65,8 +65,17 @@ module CyberarmEngine
|
||||
end
|
||||
end
|
||||
|
||||
if is_a?(Button)
|
||||
@text.y = @y + height / 2 - @text.height / 2
|
||||
if (vertical_alignment = @options[:text_v_align])
|
||||
case vertical_alignment
|
||||
when :center
|
||||
@text.y = if @text.height <= height
|
||||
@y + height / 2 - @text.height / 2
|
||||
else
|
||||
@style.border_thickness_top + @style.padding_top + @y
|
||||
end
|
||||
when :bottom
|
||||
@text.y = @y + outer_height - (@text.height + @style.border_thickness_bottom + @style.padding_bottom)
|
||||
end
|
||||
end
|
||||
|
||||
update_background
|
||||
|
||||
@@ -5,7 +5,7 @@ module CyberarmEngine
|
||||
|
||||
def initialize(options, block = nil)
|
||||
if options.dig(:theme, :ToggleButton, :checkmark_image)
|
||||
options[:theme][:ToggleButton][:image_width] ||= options[:theme][:Label][:text_size]
|
||||
options[:theme][:ToggleButton][:image_width] ||= options[:theme][:TextBlock][:text_size]
|
||||
super(get_image(options.dig(:theme, :ToggleButton, :checkmark_image)), options, block)
|
||||
|
||||
@_image = @image
|
||||
|
||||
@@ -76,6 +76,7 @@ module CyberarmEngine
|
||||
border_radius: 0,
|
||||
background: ["ffc75e61".to_i(16), "ffe26623".to_i(16)],
|
||||
text_align: :center,
|
||||
text_v_align: :center,
|
||||
text_wrap: :none,
|
||||
|
||||
hover: {
|
||||
@@ -106,6 +107,10 @@ module CyberarmEngine
|
||||
text_static: false # static text causes issues correctly displaying caret position
|
||||
},
|
||||
|
||||
EditBox: { # < EditLine
|
||||
text_v_align: :top
|
||||
},
|
||||
|
||||
Image: { # < Element
|
||||
color: Gosu::Color::WHITE,
|
||||
tileable: false,
|
||||
|
||||
Reference in New Issue
Block a user