mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2026-05-06 07:58:15 +00:00
Send enter and hover events to mouse over element's parent containers- improves ux, disable applying :active styles if element does not have any specificied- fixes element blinking on click.
This commit is contained in:
@@ -214,7 +214,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
if !@enabled
|
if !@enabled
|
||||||
update_styles(:disabled)
|
update_styles(:disabled)
|
||||||
elsif @focus
|
elsif @focus && !@style.active.empty?
|
||||||
update_styles(:active)
|
update_styles(:active)
|
||||||
else
|
else
|
||||||
update_styles(:hover)
|
update_styles(:hover)
|
||||||
@@ -229,7 +229,7 @@ module CyberarmEngine
|
|||||||
unless @enabled
|
unless @enabled
|
||||||
update_styles(:disabled)
|
update_styles(:disabled)
|
||||||
else
|
else
|
||||||
update_styles(:active)
|
update_styles(:active) unless @style.active.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
window.current_state.focus = self
|
window.current_state.focus = self
|
||||||
|
|||||||
@@ -106,9 +106,12 @@ module CyberarmEngine
|
|||||||
@children.each(&:update)
|
@children.each(&:update)
|
||||||
end
|
end
|
||||||
|
|
||||||
def hit_element?(x, y)
|
# return nil if element was not hit, or array of hit elements if hit, includes self.
|
||||||
|
def hit_element?(x, y, elements = [])
|
||||||
return unless hit?(x, y)
|
return unless hit?(x, y)
|
||||||
|
|
||||||
|
elements << self
|
||||||
|
|
||||||
# Offset child hit point by scroll position/offset
|
# Offset child hit point by scroll position/offset
|
||||||
child_x = x - @scroll_position.x
|
child_x = x - @scroll_position.x
|
||||||
child_y = y - @scroll_position.y
|
child_y = y - @scroll_position.y
|
||||||
@@ -118,15 +121,18 @@ module CyberarmEngine
|
|||||||
|
|
||||||
case child
|
case child
|
||||||
when Container
|
when Container
|
||||||
if (element = child.hit_element?(child_x, child_y))
|
if (child.hit_element?(child_x, child_y, elements))
|
||||||
return element
|
return elements
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
return child if child.hit?(child_x, child_y)
|
if child.hit?(child_x, child_y)
|
||||||
|
elements << child
|
||||||
|
return elements
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self if hit?(x, y)
|
elements
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_child_element_visibity(child)
|
def update_child_element_visibity(child)
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ module CyberarmEngine
|
|||||||
@dragging_element = nil
|
@dragging_element = nil
|
||||||
@pending_recalculate_request = false
|
@pending_recalculate_request = false
|
||||||
@pending_element_recalculate_requests = []
|
@pending_element_recalculate_requests = []
|
||||||
|
@hit_elements = []
|
||||||
|
|
||||||
@needs_repaint = false
|
@needs_repaint = false
|
||||||
|
|
||||||
@@ -81,6 +82,7 @@ module CyberarmEngine
|
|||||||
# Does NOT throw :focus event at element or set element as focused
|
# Does NOT throw :focus event at element or set element as focused
|
||||||
def focus=(element)
|
def focus=(element)
|
||||||
@focus.publish(:blur) if @focus && element && @focus != element
|
@focus.publish(:blur) if @focus && element && @focus != element
|
||||||
|
@hit_elements.delete(@focus)
|
||||||
@focus = element
|
@focus = element
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -163,22 +165,37 @@ module CyberarmEngine
|
|||||||
return unless window.has_focus?
|
return unless window.has_focus?
|
||||||
return unless window.current_state == self
|
return unless window.current_state == self
|
||||||
|
|
||||||
new_mouse_over = @menu.hit_element?(window.mouse_x, window.mouse_y) if @menu
|
# list of containers decending down to hit element
|
||||||
new_mouse_over ||= @root_container.hit_element?(window.mouse_x, window.mouse_y)
|
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
|
||||||
|
|
||||||
if new_mouse_over
|
# is the currently hit element the same as last hit element?
|
||||||
new_mouse_over.publish(:enter) if new_mouse_over != @mouse_over
|
same_element = @mouse_over && new_mouse_over == @mouse_over
|
||||||
new_mouse_over.publish(:hover)
|
|
||||||
# puts "#{new_mouse_over.class}[#{new_mouse_over.value}]: #{new_mouse_over.x}:#{new_mouse_over.y} #{new_mouse_over.width}:#{new_mouse_over.height}" if new_mouse_over != @mouse_over
|
unless @hit_elements == new_hit_elements
|
||||||
|
added_hit_elements = (new_hit_elements || []) - @hit_elements
|
||||||
|
removed_hit_elements = @hit_elements - (new_hit_elements || [])
|
||||||
|
|
||||||
|
added_hit_elements.each do |e|
|
||||||
|
e.publish(:enter)
|
||||||
|
e.publish(:hover)
|
||||||
end
|
end
|
||||||
@mouse_over.publish(:leave) if @mouse_over && new_mouse_over != @mouse_over
|
|
||||||
|
removed_hit_elements.each do |e|
|
||||||
|
e.publish(:leave)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@mouse_over = new_mouse_over
|
@mouse_over = new_mouse_over
|
||||||
|
@hit_elements = new_hit_elements || []
|
||||||
|
|
||||||
redirect_holding_mouse_button(:left) if @mouse_over && Gosu.button_down?(Gosu::MS_LEFT)
|
redirect_holding_mouse_button(:left) if @mouse_over && Gosu.button_down?(Gosu::MS_LEFT)
|
||||||
redirect_holding_mouse_button(:middle) if @mouse_over && Gosu.button_down?(Gosu::MS_MIDDLE)
|
redirect_holding_mouse_button(:middle) if @mouse_over && Gosu.button_down?(Gosu::MS_MIDDLE)
|
||||||
redirect_holding_mouse_button(:right) if @mouse_over && Gosu.button_down?(Gosu::MS_RIGHT)
|
redirect_holding_mouse_button(:right) if @mouse_over && Gosu.button_down?(Gosu::MS_RIGHT)
|
||||||
|
|
||||||
if Vector.new(window.mouse_x, window.mouse_y) == @last_mouse_pos
|
# handle tooltip
|
||||||
|
if same_element
|
||||||
if @mouse_over && (Gosu.milliseconds - @mouse_moved_at) > tool_tip_delay
|
if @mouse_over && (Gosu.milliseconds - @mouse_moved_at) > tool_tip_delay
|
||||||
@tip.value = @mouse_over.tip if @mouse_over
|
@tip.value = @mouse_over.tip if @mouse_over
|
||||||
@tip.x = window.mouse_x
|
@tip.x = window.mouse_x
|
||||||
@@ -261,6 +278,7 @@ module CyberarmEngine
|
|||||||
hide_menu unless @menu && (@menu == @mouse_over) || (@mouse_over&.parent == @menu)
|
hide_menu unless @menu && (@menu == @mouse_over) || (@mouse_over&.parent == @menu)
|
||||||
|
|
||||||
if @focus && @mouse_over != @focus
|
if @focus && @mouse_over != @focus
|
||||||
|
@hit_elements.delete(@focus)
|
||||||
@focus.publish(:blur)
|
@focus.publish(:blur)
|
||||||
@focus = nil
|
@focus = nil
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -58,6 +58,10 @@ module CyberarmEngine
|
|||||||
def mark_clean!
|
def mark_clean!
|
||||||
@dirty = false
|
@dirty = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def empty?
|
||||||
|
@hash.empty?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Style < StyleData
|
class Style < StyleData
|
||||||
|
|||||||
Reference in New Issue
Block a user