Module: TkComponent::Builder::Scrollable

Included in:
TkText, TkTree
Defined in:
lib/tk_component/builder/tk_item.rb

Constant Summary collapse

ROOT_FRAME_OPTIONS =
%i|width height relief borderwidth padx pady padding| + TkComponent::Builder::LAYOUT_OPTIONS

Instance Method Summary collapse

Instance Method Details

#initialize(parent_item, name, options = {}, grid = {}, event_handlers = []) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/tk_component/builder/tk_item.rb', line 190

def initialize(parent_item, name, options = {}, grid = {}, event_handlers = [])
  return super unless (s_options = options.delete(:scrollers)) && s_options.present? && s_options != 'none'
  frame_item = TK_CLASSES[:frame].new(parent_item.native_item) # Containing frame
  real_native_item = create_native_item(frame_item, name, options, grid, event_handlers)
  f_options = options.extract!(*ROOT_FRAME_OPTIONS)
  apply_options(f_options, frame_item) # Apply the applicable options to the enclosing frame
  @native_item = real_native_item
  apply_options(options, real_native_item)
  set_grid(grid, frame_item)
  real_native_item.grid( :column => 0, :row => 0, :sticky => 'nwes')
  if s_options.include?('x')
    h_scrollbar = TK_CLASSES[:hscroll_bar].new(frame_item)
    h_scrollbar.orient('horizontal')
    h_scrollbar.command proc { |*args| real_native_item.xview(*args) }
    real_native_item['xscrollcommand'] = proc { |*args| h_scrollbar.set(*args) }
    h_scrollbar.grid( :column => 0, :row => 1, :sticky => 'wes')
  end
  if s_options.include?('y')
    v_scrollbar =  TK_CLASSES[:vscroll_bar].new(frame_item)
    v_scrollbar.orient('vertical')
    v_scrollbar.command proc { |*args| real_native_item.yview(*args) }
    real_native_item['yscrollcommand'] = proc { |*args| v_scrollbar.set(*args) }
    v_scrollbar.grid( :column => 1, :row => 0, :sticky => 'nse')
  end
  TkGrid.columnconfigure(frame_item, 0, :weight => 1)
  TkGrid.columnconfigure(frame_item, 1, :weight => 0) if v_scrollbar.present?
  TkGrid.rowconfigure(frame_item, 0, :weight => 1)
  TkGrid.rowconfigure(frame_item, 1, :weight => 0) if h_scrollbar.present?
  @native_item = real_native_item
  set_event_handlers(event_handlers)
end

#removeObject

We need to remove the parent native item, as it’s the container we put in place initially



223
224
225
# File 'lib/tk_component/builder/tk_item.rb', line 223

def remove
  @native_item.winfo_parent.destroy
end