lib/cyberarm_engine/ui/element.rb in cyberarm_engine-0.22.0 vs lib/cyberarm_engine/ui/element.rb in cyberarm_engine-0.23.0
- old
+ new
@@ -63,10 +63,12 @@
set_background_nine_slice
set_background_image
set_border_thickness
set_border_color
+
+ root.gui_state.request_repaint
end
def safe_style_fetch(*args)
@style.hash.dig(@style_event, *args) || @style.hash.dig(:default, *args) || default(*args)
end
@@ -164,14 +166,14 @@
@style_event = event
return if self.is_a?(ToolTip)
if old_width != width || old_height != height
- (root&.gui_state || @gui_state).request_recalculate
- else
- stylize
+ root.gui_state.request_recalculate
end
+
+ stylize
end
def default_events
%i[left middle right].each do |button|
event(:"#{button}_mouse_button")
@@ -254,10 +256,12 @@
:handled
end
def enabled=(boolean)
+ root.gui_state.request_repaint if @enabled != boolean
+
@enabled = boolean
recalculate
@enabled
@@ -265,10 +269,14 @@
def enabled?
@enabled
end
+ def focused?
+ @focus
+ end
+
def visible?
@visible
end
def element_visible?
@@ -276,22 +284,25 @@
end
def toggle
@visible = !@visible
root.gui_state.request_recalculate
+ root.gui_state.request_repaint
end
def show
bool = visible?
@visible = true
root.gui_state.request_recalculate unless bool
+ root.gui_state.request_repaint unless bool
end
def hide
bool = visible?
@visible = false
root.gui_state.request_recalculate if bool
+ root.gui_state.request_repaint if bool
end
def draw
return unless visible?
return unless element_visible?
@@ -421,13 +432,13 @@
a_ << child
end
pairs_ << a_ unless pairs_.last == a_
- pairs_.sum { |pair| pair.map(&:outer_height).max } + @style.padding_bottom + @style.border_thickness_bottom
+ pairs_.sum { |pair| + @style.padding_top + @style.border_thickness_top + pair.map(&:outer_height).max } + @style.padding_bottom + @style.border_thickness_bottom
else
- @children.sum(&:outer_height) + @style.padding_bottom + @style.border_thickness_bottom
+ @style.padding_top + @style.border_thickness_top + @children.sum(&:outer_height) + @style.padding_bottom + @style.border_thickness_bottom
end
end
def max_scroll_width
scroll_width - outer_width
@@ -438,25 +449,25 @@
end
def dimensional_size(size, dimension)
raise "dimension must be either :width or :height" unless %i[width height].include?(dimension)
- new_size = if size.is_a?(Numeric) && size.between?(0.0, 1.0)
- (@parent.send(:"content_#{dimension}") * size).floor - send(:"noncontent_#{dimension}").floor
- else
- size
- end
+ new_size = if size.is_a?(Float) && size.between?(0.0, 1.0)
+ (@parent.send(:"content_#{dimension}") * size).floor - send(:"noncontent_#{dimension}").floor
+ else
+ size
+ end
- if @parent && @style.fill # Handle fill behavior
- if dimension == :width && @parent.is_a?(Flow)
- return space_available_width - noncontent_width
+ # Handle fill behavior
+ if @parent && @style.fill &&
+ (dimension == :width && @parent.is_a?(Flow) ||
+ dimension == :height && @parent.is_a?(Stack))
+ return space_available_width - noncontent_width if dimension == :width && @parent.is_a?(Flow)
+ return space_available_height - noncontent_height if dimension == :height && @parent.is_a?(Stack)
- elsif dimension == :height && @parent.is_a?(Stack)
- return space_available_height - noncontent_height
- end
-
- else # Handle min_width/height and max_width/height
+ # Handle min_width/height and max_width/height
+ else
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
@@ -477,10 +488,12 @@
available_space = ((@parent.content_height - (@parent.children.reject { |c| c.style.fill }).map(&:outer_height).sum) / fill_siblings)
(available_space.nan? || available_space.infinite?) ? 0 : available_space.floor # The parent element might not have its dimensions, yet.
end
def background=(_background)
+ root.gui_state.request_repaint
+
@style.background_canvas.background = _background
update_background
end
def update_background
@@ -495,10 +508,12 @@
update_background_image
@style.border_canvas.update
end
def background_nine_slice=(_image_path)
+ root.gui_state.request_repaint
+
@style.background_nine_slice_canvas.image = _image_path
update_background_nine_slice
end
def update_background_nine_slice
@@ -519,9 +534,11 @@
@style.background_nine_slice_canvas.image = @style.background_nine_slice
end
def background_image=(image_path)
+ root.gui_state.request_repaint
+
@style.background_image = image_path.is_a?(Gosu::Image) ? image_path : get_image(image_path)
update_background_image
end
def update_background_image