class TkComponent::Builder::TkTree
Public Instance Methods
apply_option(option, v, to_item = self.native_item)
click to toggle source
Calls superclass method
TkComponent::Builder::TkItem#apply_option
# 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)
click to toggle source
Calls superclass method
TkComponent::Builder::TkItem#apply_options
# 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
scroll_to_item(tree_item)
click to toggle source
Right now it only works well for non-nested trees
# 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
scroll_to_selection()
click to toggle source
# 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)
click to toggle source
Calls superclass method
TkComponent::Builder::TkItem#set_event_handler
# 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