Added Widget, which acts like a Flow and a button.

This commit is contained in:
2026-04-20 10:14:57 -05:00
parent c229329542
commit a79b9cc20e
5 changed files with 45 additions and 1 deletions

View File

@@ -20,6 +20,10 @@ module CyberarmEngine
container(CyberarmEngine::Element::Stack, options, &block)
end
def widget(options = {}, &block)
container(CyberarmEngine::Element::Widget, options, &block)
end
def menu(options = {}, &block)
container(CyberarmEngine::Element::Menu, options, &block)
end

View File

@@ -214,6 +214,9 @@ module CyberarmEngine
end
class ToolTip < TextBlock
def needs_repaint?
@needs_repaint || !value.to_s.empty?
end
end
class Link < TextBlock

View File

@@ -0,0 +1,36 @@
module CyberarmEngine
class Element
# Special container that has a layout like a Flow
# and makes all its children mirror its styling (i.e. hover, active, disabled...)
class Widget < Flow
def update_styles(style = :default)
super
@children.each do |child|
recursive_styles(style, self)
end
end
# Make child elements mirror the widgets styling
# disabled elements will not have their styling overridden
def recursive_styles(style, container)
container.children.each do |child|
child.update_styles(style)
recursive_styles(style, child) if child.is_a?(Container)
end
end
# Enable child elements to display their tooltips
# but fall back to the Widget if no hit element has a tip
def tip
elements = hit_element?(window.mouse_x, window.mouse_y)
return @tip unless elements
elements.delete(self) # prevent infinite recursive loop (Widget#tip)
elements.reverse.find { |e| !e.tip.empty? }&.tip || @tip
end
end
end
end

View File

@@ -168,7 +168,7 @@ module CyberarmEngine
# list of containers decending down to hit element
new_hit_elements = (@menu || @root_container).hit_element?(window.mouse_x, window.mouse_y)
# element the mouse is over, if any.
new_mouse_over = new_hit_elements&.last
new_mouse_over = new_hit_elements&.find { |c| c.is_a?(CyberarmEngine::Element::Widget) } || new_hit_elements&.last
# is the currently hit element the same as last hit element?
same_element = @mouse_over && new_mouse_over == @mouse_over