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
TkWrapper::Widgets::Button, Entry, Frame, Grid, Label, Menu, Menu::Cascade, Menu::Command, MountPoint, 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.
-
#winfo ⇒ Object
readonly
Returns the value of attribute winfo.
Instance Method Summary collapse
- #build(parent, configure: true, manager: nil) ⇒ Object
- #build_childs ⇒ 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.
20 21 22 23 24 25 26 27 28 |
# File 'lib/widgets/base/widget.rb', line 20 def initialize(config: {}, childs: [], manager: nil, ids: []) @cell = TkWrapper::Util::Tk::Cell.new(self) @winfo = TkWrapper::Widgets::Base::WindowInfo.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.
16 17 18 |
# File 'lib/widgets/base/widget.rb', line 16 def cell @cell end |
#childs ⇒ Object (readonly)
Returns the value of attribute childs.
16 17 18 |
# File 'lib/widgets/base/widget.rb', line 16 def childs @childs end |
#config ⇒ Object
Returns the value of attribute config.
15 16 17 |
# File 'lib/widgets/base/widget.rb', line 15 def config @config end |
#ids ⇒ Object (readonly)
Returns the value of attribute ids.
16 17 18 |
# File 'lib/widgets/base/widget.rb', line 16 def ids @ids end |
#manager ⇒ Object (readonly)
Returns the value of attribute manager.
16 17 18 |
# File 'lib/widgets/base/widget.rb', line 16 def manager @manager end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
16 17 18 |
# File 'lib/widgets/base/widget.rb', line 16 def parent @parent end |
#winfo ⇒ Object (readonly)
Returns the value of attribute winfo.
16 17 18 |
# File 'lib/widgets/base/widget.rb', line 16 def winfo @winfo end |
Instance Method Details
#build(parent, configure: true, manager: nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/widgets/base/widget.rb', line 50 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) build_childs end |
#build_childs ⇒ Object
46 47 48 |
# File 'lib/widgets/base/widget.rb', line 46 def build_childs @childs.each { |child| child.build(self, manager: @manager) } end |
#configure ⇒ Object
62 63 64 65 |
# File 'lib/widgets/base/widget.rb', line 62 def configure @config.() @config.configure_tearoff end |
#create_tk_widget(parent) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/widgets/base/widget.rb', line 30 def (parent) tk_class = @config[:tk_class] || self.tk_class return unless tk_class tk_class.new(parent&.) end |
#each(&block) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/widgets/base/widget.rb', line 67 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
76 77 78 79 |
# File 'lib/widgets/base/widget.rb', line 76 def push(child) @childs.push(child) child.build(self, manager: @manager) end |
#tk_class ⇒ Object
18 |
# File 'lib/widgets/base/widget.rb', line 18 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
40 41 42 43 44 |
# File 'lib/widgets/base/widget.rb', line 40 def (parent = @parent) return if ( = (parent)) || parent&. end |