lib/glimmer/swt/menu_proxy.rb in glimmer-dsl-opal-0.28.3 vs lib/glimmer/swt/menu_proxy.rb in glimmer-dsl-opal-0.29.0
- old
+ new
@@ -1,6 +1,6 @@
-# Copyright (c) 2020-2021 Andy Maleh
+# Copyright (c) 2020-2022 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
@@ -96,11 +96,11 @@
CSS
attr_reader :menu_item_proxy, :menu_parent
- def initialize(parent, args)
+ def initialize(parent, args, block = nil)
# TODO refactor/simplify code below
@children = []
index = args.delete(args.last) if args.last.is_a?(Numeric)
args = args.map {|arg| arg.is_a?(String) ? arg.to_sym : arg}
if parent.is_a?(ShellProxy)
@@ -109,25 +109,26 @@
args = args.unshift(:drop_down)
else
args = args.unshift(:pop_up)
end
if parent.is_a?(MenuProxy)
- @menu_item_proxy = SWT::WidgetProxy.for('menu_item', parent, [:cascade] + [index].compact)
- super(@menu_item_proxy, args)
+ @menu_item_proxy = SWT::WidgetProxy.for('menu_item', parent, [:cascade] + [index].compact, block)
+ super(@menu_item_proxy, args, nil)
@menu_item_proxy.menu = self
elsif parent.is_a?(ShellProxy)
- super(parent, args)
+ super(parent, args, nil)
else # widget pop up
- super(parent, args)
+ super(parent, args, nil)
end
-
+
if bar?
# Assumes a parent shell
parent.menu_bar = self
elsif pop_up?
parent.menu = self
end
+
# TODO IMPLEMENT PROPERLY
# on_focus_lost {
# dispose
# }
end
@@ -193,38 +194,43 @@
end
end
def post_add_content
if bar?
- # delay this till all children rendered (perhaps post_add_content block)
parent_dom_element.css('position', 'relative')
parent_dom_element.css('margin-top', '30px')
parent_dom_element.css('height', '114%')
- redraw
+ render
`$(#{path}).menu({
position: { my: "top", at: "bottom" },
icons: { submenu: "ui-icon-blank" }
});`
the_element = dom_element
- the_element.on('mouseover') { |event|
+ the_element.on('mouseenter') do |event|
if event.page_x.between?(the_element.offset.left, the_element.offset.left + the_element.width) and
event.page_y.between?(the_element.offset.top, the_element.offset.top + the_element.height)
`$(#{path}).menu('option', 'position', { my: 'left top', at: 'left bottom' })`
end
- }
- the_element.on('menublur') {
- `$(#{path}).menu('option', 'position', { my: 'left top', at: 'right top' })`
- }
- minimum_width = children.to_a.map(&:dom_element).map(&:width).reduce(:+)
+ end
+ the_element.on('mouseout') do |event|
+ if event.page_x.between?(the_element.offset.left, the_element.offset.left + the_element.width) and
+ event.page_y.between?(the_element.offset.top, the_element.offset.top + the_element.height)
+ `$(#{path}).menu('option', 'position', { my: 'left top', at: 'left bottom' })`
+ else
+ `$(#{path}).menu('option', 'position', { my: 'left top', at: 'right top' })`
+ end
+ end
+ minimum_width = children.to_a.map(&:dom_element).map(&:width).map(&:to_f).reduce(:+)
the_element.css('min-width', minimum_width)
end
end
def visible=(value)
@visible = value
if @visible
parent.menu_requested = true
+ parent.dom_element.css('position', 'relative')
render
dom_element.css('position', 'absolute')
dom_element.css('left', parent.menu_x - parent.dom_element.offset.left)
dom_element.css('top', parent.menu_y - parent.dom_element.offset.top)
parent.menu_requested = false
@@ -248,10 +254,10 @@
end
end
def close
dom_element.remove
- Element['body'].off('click', &@close_event_handler)
+ Element['body'].off('click', @close_event_handler)
@visible = false
end
def root_menu?
!parent.is_a?(MenuProxy) && !parent.is_a?(MenuItemProxy)