Class: TkWrapper::Widgets::AutoResizeEntry
- Inherits:
-
Entry
- Object
- Base::Widget
- Entry
- TkWrapper::Widgets::AutoResizeEntry
- Defined in:
- lib/widgets/auto_resize_entry.rb
Instance Attribute Summary collapse
-
#add_width ⇒ Object
auto resizes on user input, only works if in the grid geometry manager of tk.
-
#min_width ⇒ Object
auto resizes on user input, only works if in the grid geometry manager of tk.
Attributes inherited from Base::Widget
#cell, #childs, #config, #ids, #parent
Instance Method Summary collapse
- #build(parent, configure: true) ⇒ Object
-
#initialize(config: {}, childs: [], id: nil) ⇒ AutoResizeEntry
constructor
A new instance of AutoResizeEntry.
- #resize ⇒ Object
- #value ⇒ Object
- #value=(value) ⇒ Object
Methods inherited from Entry
Methods inherited from Base::Widget
#add_ids, config, #configure, #create_tk_widget, #each, manager, #manager, modify, #modify, #modify_each, #push, #tk_class, #tk_widget
Constructor Details
#initialize(config: {}, childs: [], id: nil) ⇒ AutoResizeEntry
Returns a new instance of AutoResizeEntry.
7 8 9 10 11 |
# File 'lib/widgets/auto_resize_entry.rb', line 7 def initialize(config: {}, childs: [], id: nil) @min_width = config[:min_width] || 0 @add_width = config[:add_width] || 0 super(config: config, childs: childs, id: id) end |
Instance Attribute Details
#add_width ⇒ Object
auto resizes on user input, only works if in the grid geometry manager of tk
5 6 7 |
# File 'lib/widgets/auto_resize_entry.rb', line 5 def add_width @add_width end |
#min_width ⇒ Object
auto resizes on user input, only works if in the grid geometry manager of tk
5 6 7 |
# File 'lib/widgets/auto_resize_entry.rb', line 5 def min_width @min_width end |
Instance Method Details
#build(parent, configure: true) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/widgets/auto_resize_entry.rb', line 13 def build(parent, configure: true) super(parent, configure: configure) parent..bind('Configure') { resize } .textvariable = TkVariable.new unless .textvariable .textvariable.trace('write') { resize } resize end |
#resize ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/widgets/auto_resize_entry.rb', line 29 def resize max_width = @cell.bbox[2] text_width = @font.measure(value) new_width = [[@min_width, text_width + @add_width].max, max_width].min .width = 0 .grid(ipadx: new_width / 2.0) @parent..update end |
#value ⇒ Object
25 26 27 |
# File 'lib/widgets/auto_resize_entry.rb', line 25 def value .textvariable.value end |
#value=(value) ⇒ Object
21 22 23 |
# File 'lib/widgets/auto_resize_entry.rb', line 21 def value=(value) .textvariable.value = value end |