Class: TkWrapper::Widgets::Base::Widget
- Inherits:
-
Object
- Object
- TkWrapper::Widgets::Base::Widget
- Extended by:
- Forwardable
- Includes:
- Enumerable, TkExtensions
- Defined in:
- lib/widgets/base/widget.rb
Direct Known Subclasses
Entry, Frame, Grid, Label, Menu, Menu::Cascade, Menu::Command, Root, Text
Instance Attribute Summary collapse
-
#cell ⇒ Object
readonly
Returns the value of attribute cell.
-
#childs ⇒ Object
readonly
Returns the value of attribute childs.
-
#config ⇒ Object
Returns the value of attribute config.
-
#ids ⇒ Object
readonly
Returns the value of attribute ids.
-
#manager ⇒ Object
readonly
Returns the value of attribute manager.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #build(parent, configure: true, manager: nil) ⇒ Object
- #configure ⇒ Object
- #create_tk_widget(parent) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(config: {}, childs: [], manager: nil, ids: []) ⇒ Widget
constructor
A new instance of Widget.
- #push(child) ⇒ Object
- #tk_class ⇒ Object
-
#tk_widget(parent = @parent) ⇒ Object
if parent is provided and self has no tk_class, the tk_widget of the parent is returned, if parent is not nil.
Constructor Details
#initialize(config: {}, childs: [], manager: nil, ids: []) ⇒ Widget
Returns a new instance of Widget.
19 20 21 22 23 24 25 26 |
# File 'lib/widgets/base/widget.rb', line 19 def initialize(config: {}, childs: [], manager: nil, ids: []) @cell = TkWrapper::Util::Tk::Cell.new(self) @finder = TkWrapper::Util::Tk::Finder.new(widgets: self) @config = TkWrapper::Widgets::Base::Configuration.new(config) @childs = childs.is_a?(Array) ? childs : [childs] @manager = manager @ids = ids.is_a?(Array) ? ids : [ids] end |
Instance Attribute Details
#cell ⇒ Object (readonly)
Returns the value of attribute cell.
15 16 17 |
# File 'lib/widgets/base/widget.rb', line 15 def cell @cell end |
#childs ⇒ Object (readonly)
Returns the value of attribute childs.
15 16 17 |
# File 'lib/widgets/base/widget.rb', line 15 def childs @childs end |
#config ⇒ Object
Returns the value of attribute config.
14 15 16 |
# File 'lib/widgets/base/widget.rb', line 14 def config @config end |
#ids ⇒ Object (readonly)
Returns the value of attribute ids.
15 16 17 |
# File 'lib/widgets/base/widget.rb', line 15 def ids @ids end |
#manager ⇒ Object (readonly)
Returns the value of attribute manager.
15 16 17 |
# File 'lib/widgets/base/widget.rb', line 15 def manager @manager end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
15 16 17 |
# File 'lib/widgets/base/widget.rb', line 15 def parent @parent end |
Instance Method Details
#build(parent, configure: true, manager: nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/widgets/base/widget.rb', line 44 def build(parent, configure: true, manager: nil) @parent = parent # creates the widget if possible and not yet created @font = TkWrapper::Util::Tk::Font.new() @manager ||= manager @config.merge(*@manager.configurations(self)) if @manager self.configure if configure @manager&.execute_modifications(self) @manager&.&.push(self) @childs.each { |child| child.build(self, manager: @manager) } end |
#configure ⇒ Object
56 57 58 59 |
# File 'lib/widgets/base/widget.rb', line 56 def configure @config.() @config.configure_tearoff end |
#create_tk_widget(parent) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/widgets/base/widget.rb', line 28 def (parent) tk_class = @config[:tk_class] || self.tk_class return unless tk_class parent&. ? tk_class.new(parent.) : tk_class.new end |
#each(&block) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/widgets/base/widget.rb', line 61 def each(&block) nodes_to_walk = [self] until nodes_to_walk.empty? node = nodes_to_walk.pop block.call(node) nodes_to_walk = node.childs + nodes_to_walk end end |
#push(child) ⇒ Object
70 71 72 73 |
# File 'lib/widgets/base/widget.rb', line 70 def push(child) @childs.push(child) child.build(self) end |
#tk_class ⇒ Object
17 |
# File 'lib/widgets/base/widget.rb', line 17 def tk_class() end |
#tk_widget(parent = @parent) ⇒ Object
if parent is provided and self has no tk_class, the tk_widget of the parent is returned, if parent is not nil
38 39 40 41 42 |
# File 'lib/widgets/base/widget.rb', line 38 def (parent = @parent) return @tk_widget if @tk_widget (@tk_widget = (parent)) || parent&. end |