Class: Teek::UI::MenuBuilder
- Inherits:
-
Object
- Object
- Teek::UI::MenuBuilder
- Defined in:
- lib/teek/ui/menu_builder.rb
Overview
The build surface inside a menu_bar/menu/context_menu block - a
separate, small vocabulary from WidgetDSL (deliberately NOT mixed
into Session/yielded as self the way ordinary containers are),
since menu entries reuse names ordinary widgets already own
(checkbox/radio are ttk widgets one level up, menu entry kinds one
level down here) - a shared receiver would collide.
Menu structure realizes through Realizer#create_menu_tree rather
than the generic per-node widget-creation path: nothing here is a Tk
widget of its own except #menu (a nested cascade, itself a menu
command) - #item/#checkbox/#radio are entries added to their
parent's menu path, with no live Tk path of their own, addressed via
their WidgetType#addressing strategy (MenuEntryAddressing) the
same way Handle resolves any other type's - see
WidgetDSL#[]. #separator stays unaddressable (nothing to
enable/disable/relabel on a divider).
Instance Method Summary collapse
- #checkbox(name = nil, label:, bind:, **opts) ⇒ Handle
-
#initialize(document, stack) ⇒ MenuBuilder
constructor
private
A new instance of MenuBuilder.
-
#item(name = nil, label:, **opts) { ... } ⇒ Handle
A command entry.
-
#menu(name = nil, label:, **opts) {|m| ... } ⇒ Handle
A nested cascade - recursive, so the same method builds both a menu_bar's top-level dropdowns (File/Edit/...) and any submenu nested inside one of those.
-
#radio(name = nil, label:, bind:, value:, **opts) ⇒ Handle
A radiobutton entry -
bind:is shared across every radio entry in the group,value:is what this one entry sets it to when chosen. -
#separator ⇒ nil
A separator entry.
Constructor Details
#initialize(document, stack) ⇒ MenuBuilder
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of MenuBuilder.
25 26 27 28 |
# File 'lib/teek/ui/menu_builder.rb', line 25 def initialize(document, stack) @document = document @stack = stack end |
Instance Method Details
#checkbox(name = nil, label:, bind:, **opts) ⇒ Handle
84 85 86 |
# File 'lib/teek/ui/menu_builder.rb', line 84 def checkbox(name = nil, label:, bind:, **opts) Handle.new(append_entry(:menu_checkbox, name, opts.merge(label: label, bind: bind))) end |
#item(name = nil, label:, **opts) { ... } ⇒ Handle
A command entry.
64 65 66 67 |
# File 'lib/teek/ui/menu_builder.rb', line 64 def item(name = nil, label:, **opts, &block) opts = opts.merge(command: block) if block Handle.new(append_entry(:menu_item, name, opts.merge(label: label))) end |
#menu(name = nil, label:, **opts) {|m| ... } ⇒ Handle
A nested cascade - recursive, so the same method builds both a menu_bar's top-level dropdowns (File/Edit/...) and any submenu nested inside one of those.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/teek/ui/menu_builder.rb', line 38 def (name = nil, label:, **opts, &block) node = @document.create(type: :menu, name: name, opts: opts.merge(label: label)) @stack.last.add_child(node) if block @stack.push(node) @document.notify(:push, node, current_path) begin block.call(self) ensure path = current_path @stack.pop @document.notify(:pop, node, path) end end Handle.new(node) end |
#radio(name = nil, label:, bind:, value:, **opts) ⇒ Handle
A radiobutton entry - bind: is shared across every radio entry in
the group, value: is what this one entry sets it to when chosen.
96 97 98 |
# File 'lib/teek/ui/menu_builder.rb', line 96 def radio(name = nil, label:, bind:, value:, **opts) Handle.new(append_entry(:menu_radio, name, opts.merge(label: label, bind: bind, value: value))) end |
#separator ⇒ nil
A separator entry.
71 72 73 74 |
# File 'lib/teek/ui/menu_builder.rb', line 71 def separator append_entry(:menu_separator, nil, {}) nil end |