Class: Teek::UI::WidgetType Private
- Inherits:
-
Object
- Object
- Teek::UI::WidgetType
- Defined in:
- lib/teek/ui/widget_type.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A single widget/node type's own metadata: what it draws, how it's built and arranged, what it validates - self-contained enough that WidgetDSL (the builder), Realizer, and Validator can each treat a registered type as the sole source of truth for it, dispatched by node type via WidgetTypes.
Leaf defaults cover the common case, so a real widget is a ~5-line descriptor: +WidgetType.new(type: :divider, tk_command: 'ttk::separator')+ is a complete, working leaf widget. A container, or a widget needing bespoke DSL methods/realize setup, overrides +dsl:+/+post_create:+.
Instance Attribute Summary collapse
- #addressing ⇒ Object readonly private
- #bind_option ⇒ Object readonly private
- #flow ⇒ Object readonly private
- #tk_command ⇒ Object readonly private
- #type ⇒ Object readonly private
- #validator ⇒ Object readonly private
Instance Method Summary collapse
-
#arrange(realizer, node, children) ⇒ void
private
Runs this type's custom arrangement strategy.
-
#arrange? ⇒ Boolean
private
Whether this type replaces the generic arrangement.
- #arranged? ⇒ Boolean private
- #container? ⇒ Boolean private
-
#custom_children(realizer, node, path) ⇒ void
private
Runs this type's custom child-creation strategy, once its own widget already exists at
path. -
#custom_children? ⇒ Boolean
private
Whether this type replaces generic child creation.
-
#custom_create(realizer, node, parent_path) ⇒ void
private
Runs this type's entire create/link replacement.
-
#custom_create? ⇒ Boolean
private
Whether this type replaces the entire create/link handling.
-
#define_dsl_method!(mod) ⇒ void
private
Defines this type's
ui.<type>method(s) onmod(the WidgetDSL module) - see Teek::UI::WidgetTypes.on_register, which drives this. -
#global_scroll_default ⇒ Boolean
private
The current value of this type's own Teek::UI global scroll-default reader (+scroll_default:+).
-
#initialize(type:, tk_command:, leaf: true, natively_scrollable: false, arranged: true, scroll_default: :auto_scroll, bind_option: nil, flow: nil, arrange: nil, custom_children: nil, custom_create: nil, validator: nil, dsl: nil, post_create: nil, addressing: WidgetAddressing) ⇒ WidgetType
constructor
private
A new instance of WidgetType.
- #leaf? ⇒ Boolean private
- #natively_scrollable? ⇒ Boolean private
-
#post_create(app, node, path, parent_path) ⇒ void
private
Runs this type's post-creation realize setup, if any - a no-op unless
post_create:was given.
Constructor Details
#initialize(type:, tk_command:, leaf: true, natively_scrollable: false, arranged: true, scroll_default: :auto_scroll, bind_option: nil, flow: nil, arrange: nil, custom_children: nil, custom_create: nil, validator: nil, dsl: nil, post_create: nil, addressing: WidgetAddressing) ⇒ WidgetType
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 WidgetType.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/teek/ui/widget_type.rb', line 113 def initialize(type:, tk_command:, leaf: true, natively_scrollable: false, arranged: true, scroll_default: :auto_scroll, bind_option: nil, flow: nil, arrange: nil, custom_children: nil, custom_create: nil, validator: nil, dsl: nil, post_create: nil, addressing: WidgetAddressing) @type = type.to_sym @tk_command = tk_command @leaf = leaf @natively_scrollable = natively_scrollable @arranged = arranged @scroll_default = scroll_default @bind_option = bind_option @flow = flow @arrange = arrange || (flow && ->(realizer, node, children) { realizer.send(:arrange_flow, node, children, flow) }) @custom_children = custom_children @custom_create = custom_create @validator = validator @dsl = dsl || default_dsl @addressing = addressing @post_create = post_create end |
Instance Attribute Details
#addressing ⇒ Object (readonly)
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.
21 22 23 |
# File 'lib/teek/ui/widget_type.rb', line 21 def addressing @addressing end |
#bind_option ⇒ Object (readonly)
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.
21 22 23 |
# File 'lib/teek/ui/widget_type.rb', line 21 def bind_option @bind_option end |
#flow ⇒ Object (readonly)
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.
21 22 23 |
# File 'lib/teek/ui/widget_type.rb', line 21 def flow @flow end |
#tk_command ⇒ Object (readonly)
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.
21 22 23 |
# File 'lib/teek/ui/widget_type.rb', line 21 def tk_command @tk_command end |
#type ⇒ Object (readonly)
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.
21 22 23 |
# File 'lib/teek/ui/widget_type.rb', line 21 def type @type end |
#validator ⇒ Object (readonly)
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.
21 22 23 |
# File 'lib/teek/ui/widget_type.rb', line 21 def validator @validator end |
Instance Method Details
#arrange(realizer, node, children) ⇒ void
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.
This method returns an undefined value.
Runs this type's custom arrangement strategy.
170 171 172 |
# File 'lib/teek/ui/widget_type.rb', line 170 def arrange(realizer, node, children) @arrange.call(realizer, node, children) end |
#arrange? ⇒ Boolean
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 whether this type replaces the generic arrangement.
161 162 163 |
# File 'lib/teek/ui/widget_type.rb', line 161 def arrange? !@arrange.nil? end |
#arranged? ⇒ Boolean
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.
156 157 158 |
# File 'lib/teek/ui/widget_type.rb', line 156 def arranged? @arranged end |
#container? ⇒ Boolean
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.
140 141 142 |
# File 'lib/teek/ui/widget_type.rb', line 140 def container? !@leaf end |
#custom_children(realizer, node, path) ⇒ void
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.
This method returns an undefined value.
Runs this type's custom child-creation strategy, once its own
widget already exists at path.
185 186 187 |
# File 'lib/teek/ui/widget_type.rb', line 185 def custom_children(realizer, node, path) @custom_children.call(realizer, node, path) end |
#custom_children? ⇒ Boolean
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 whether this type replaces generic child creation.
175 176 177 |
# File 'lib/teek/ui/widget_type.rb', line 175 def custom_children? !@custom_children.nil? end |
#custom_create(realizer, node, parent_path) ⇒ void
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.
This method returns an undefined value.
Runs this type's entire create/link replacement.
199 200 201 |
# File 'lib/teek/ui/widget_type.rb', line 199 def custom_create(realizer, node, parent_path) @custom_create.call(realizer, node, parent_path) end |
#custom_create? ⇒ Boolean
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 whether this type replaces the entire create/link handling.
190 191 192 |
# File 'lib/teek/ui/widget_type.rb', line 190 def custom_create? !@custom_create.nil? end |
#define_dsl_method!(mod) ⇒ void
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.
This method returns an undefined value.
Defines this type's ui.<type> method(s) on mod (the Teek::UI::WidgetDSL
module) - see Teek::UI::WidgetTypes.on_register, which drives this.
207 208 209 |
# File 'lib/teek/ui/widget_type.rb', line 207 def define_dsl_method!(mod) @dsl.call(mod) end |
#global_scroll_default ⇒ Boolean
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 the current value of this type's own Teek::UI global scroll-default reader (+scroll_default:+).
151 152 153 |
# File 'lib/teek/ui/widget_type.rb', line 151 def global_scroll_default Teek::UI.public_send(@scroll_default) end |
#leaf? ⇒ Boolean
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.
135 136 137 |
# File 'lib/teek/ui/widget_type.rb', line 135 def leaf? @leaf end |
#natively_scrollable? ⇒ Boolean
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.
145 146 147 |
# File 'lib/teek/ui/widget_type.rb', line 145 def natively_scrollable? @natively_scrollable end |
#post_create(app, node, path, parent_path) ⇒ void
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.
This method returns an undefined value.
Runs this type's post-creation realize setup, if any - a no-op
unless post_create: was given.
218 219 220 |
# File 'lib/teek/ui/widget_type.rb', line 218 def post_create(app, node, path, parent_path) @post_create&.call(app, node, path, parent_path) end |