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, #font, #ids, #manager, #opts, #parent, #winfo
Instance Method Summary collapse
- #build(parent, **args) ⇒ Object
-
#initialize(**args) ⇒ AutoResizeEntry
constructor
A new instance of AutoResizeEntry.
- #resize ⇒ Object
- #value ⇒ Object
- #value=(value) ⇒ Object
Methods inherited from Entry
Methods inherited from Base::Widget
#create_tk_widget, #each, #init_id, #initialize_utilities, #normalize_childs, #push, #tk_class, #tk_widget
Constructor Details
#initialize(**args) ⇒ AutoResizeEntry
Returns a new instance of AutoResizeEntry.
7 8 9 10 11 |
# File 'lib/widgets/auto_resize_entry.rb', line 7 def initialize(**args) @min_width = args.dig(:config, :min_width) || 0 @add_width = args.dig(:config, :add_width) || 0 super(**args) 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, **args) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/widgets/auto_resize_entry.rb', line 13 def build(parent, **args) super(parent, **args) 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], 0].max 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 |