Class: TkComponent::Builder::TkTree
Constant Summary
Constants included
from Scrollable
Scrollable::ROOT_FRAME_OPTIONS
Instance Attribute Summary
Attributes inherited from TkItem
#native_item
Instance Method Summary
collapse
Methods included from Scrollable
#initialize, #remove
Methods inherited from TkItem
#apply_internal_grid, #built, create, #create_native_item, #focus, #initialize, #native_item_class, #remove, #set_event_handlers, #set_grid
Instance Method Details
#apply_option(option, v, to_item = self.native_item) ⇒ Object
297
298
299
300
301
302
303
304
305
306
|
# File 'lib/tk_component/builder/tk_item.rb', line 297
def apply_option(option, v, to_item = self.native_item)
case option.to_sym
when :column_defs
@column_defs = v
when :heading
@column_defs = [ { key: '#0', text: v } ]
else
super
end
end
|
#apply_options(options, to_item = self.native_item) ⇒ Object
283
284
285
286
287
288
289
290
291
292
293
294
295
|
# File 'lib/tk_component/builder/tk_item.rb', line 283
def apply_options(options, to_item = self.native_item)
super
return unless @column_defs.present?
cols = @column_defs.map { |c| c[:key] }
to_item.columns(cols[1..-1].join(' ')) unless cols == ['#0']
@column_defs.each.with_index do |cd, idx|
key = idx == 0 ? '#0' : cd[:key]
column_conf = cd.slice(:width, :anchor)
to_item.column_configure(key, column_conf) unless column_conf.empty?
heading_conf = cd.slice(:text)
to_item.heading_configure(key, heading_conf) unless heading_conf.empty?
end
end
|
Right now it only works well for non-nested trees
324
325
326
327
328
329
|
# File 'lib/tk_component/builder/tk_item.rb', line 324
def scroll_to_item(tree_item)
return unless tree_item.present?
items = @native_item.children('')
rel_pos = items.index(tree_item).to_f / items.size.to_f
@native_item.after(200) { @native_item.yview_moveto(rel_pos) }
end
|
319
320
321
|
# File 'lib/tk_component/builder/tk_item.rb', line 319
def scroll_to_selection
scroll_to_item(@native_item.selection.first)
end
|
#set_event_handler(event_handler) ⇒ Object
308
309
310
311
312
313
314
315
316
317
|
# File 'lib/tk_component/builder/tk_item.rb', line 308
def set_event_handler(event_handler)
case event_handler.name
when :select
Event.bind_event('<TreeviewSelect>', self, event_handler.options, event_handler.lambda)
when :item_open
Event.bind_event('<TreeviewOpen>', self, event_handler.options, event_handler.lambda)
else
super
end
end
|