Class: TkWrapper::Widgets::Base::Widget
- Inherits:
-
Object
- Object
- TkWrapper::Widgets::Base::Widget
- Extended by:
- Forwardable
- Includes:
- Enumerable
- 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.
-
#font ⇒ Object
readonly
Returns the value of attribute font.
-
#ids ⇒ Object
readonly
Returns the value of attribute ids.
-
#manager ⇒ Object
readonly
Returns the value of attribute manager.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#winfo ⇒ Object
readonly
Returns the value of attribute winfo.
Instance Method Summary collapse
- #create_tk_widget(parent) ⇒ Object
- #each(&block) ⇒ Object
- #init_id(id) ⇒ Object
-
#initialize(parent: nil, config: {}, childs: [], manager: nil, ids: [], id: []) ⇒ Widget
constructor
A new instance of Widget.
- #initialize_utilities ⇒ Object
- #normalize_childs(childs) ⇒ Object
- #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(parent: nil, config: {}, childs: [], manager: nil, ids: [], id: []) ⇒ Widget
Returns a new instance of Widget.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/widgets/base/widget.rb', line 22 def initialize(parent: nil, config: {}, childs: [], manager: nil, ids: [], id: []) initialize_utilities @config = TkWrapper::Widgets::Base::Configuration.new(config) @manager = manager @ids = init_id(id) + init_id(ids) @parent = parent modify_configuration(@config) @childs = normalize_childs(childs) parent&.push(self) end |
Instance Attribute Details
#cell ⇒ Object (readonly)
Returns the value of attribute cell.
18 19 20 |
# File 'lib/widgets/base/widget.rb', line 18 def cell @cell end |
#childs ⇒ Object (readonly)
Returns the value of attribute childs.
18 19 20 |
# File 'lib/widgets/base/widget.rb', line 18 def childs @childs end |
#config ⇒ Object
Returns the value of attribute config.
17 18 19 |
# File 'lib/widgets/base/widget.rb', line 17 def config @config end |
#font ⇒ Object (readonly)
Returns the value of attribute font.
18 19 20 |
# File 'lib/widgets/base/widget.rb', line 18 def font @font end |
#ids ⇒ Object (readonly)
Returns the value of attribute ids.
18 19 20 |
# File 'lib/widgets/base/widget.rb', line 18 def ids @ids end |
#manager ⇒ Object (readonly)
Returns the value of attribute manager.
18 19 20 |
# File 'lib/widgets/base/widget.rb', line 18 def manager @manager end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
18 19 20 |
# File 'lib/widgets/base/widget.rb', line 18 def opts @opts end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
18 19 20 |
# File 'lib/widgets/base/widget.rb', line 18 def parent @parent end |
#winfo ⇒ Object (readonly)
Returns the value of attribute winfo.
18 19 20 |
# File 'lib/widgets/base/widget.rb', line 18 def winfo @winfo end |
Instance Method Details
#create_tk_widget(parent) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/widgets/base/widget.rb', line 49 def (parent) tk_class = @config[:tk_class] || self.tk_class return unless tk_class tk_class.new(parent&.) end |
#each(&block) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/widgets/base/widget.rb', line 65 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 |
#init_id(id) ⇒ Object
40 41 42 |
# File 'lib/widgets/base/widget.rb', line 40 def init_id(id) id.is_a?(Array) ? id : [id] end |
#initialize_utilities ⇒ Object
33 34 35 36 37 38 |
# File 'lib/widgets/base/widget.rb', line 33 def initialize_utilities @cell = TkWrapper::Util::Tk::Cell.new(self) @winfo = TkWrapper::Widgets::Base::WindowInfo.new(self) @opts = TkWrapper::Widgets::Base::TkOptions.new(self) @finder = TkWrapper::Util::Tk::Finder.new(widgets: self) end |
#normalize_childs(childs) ⇒ Object
44 45 46 47 |
# File 'lib/widgets/base/widget.rb', line 44 def normalize_childs(childs) childs = create_childs || childs childs.is_a?(Array) ? childs : [childs] end |
#push(child) ⇒ Object
74 75 76 77 |
# File 'lib/widgets/base/widget.rb', line 74 def push(child) @childs.push(child) child.build(self, manager: @manager) end |
#tk_class ⇒ Object
20 |
# File 'lib/widgets/base/widget.rb', line 20 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
59 60 61 62 63 |
# File 'lib/widgets/base/widget.rb', line 59 def (parent = @parent) return if ( = (parent)) || parent&. end |