class BasicTableButton
Constants
- BasicAnimal
Attributes
animals[RW]
Public Class Methods
new()
click to toggle source
# File examples/basic_table_button.rb, line 16 def initialize @animals = [ Animal.new('cat', 'meow'), Animal.new('dog', 'woof'), Animal.new('chicken', 'cock-a-doodle-doo'), Animal.new('horse', 'neigh'), Animal.new('cow', 'moo'), ] end
Public Instance Methods
launch()
click to toggle source
# File examples/basic_table_button.rb, line 26 def launch window('Animal sounds', 400, 200) { horizontal_box { table { text_column('Animal') text_column('Description') button_column('Action') { on_clicked do |row| # Option 1: direct data deletion is the simpler solution # @animals.delete_at(row) # automatically deletes actual table row due to explicit data-binding # Option 2: cloning only to demonstrate table row deletion upon explicit setting of animals attribute (cloning is not recommended beyond demonstrating this point) new_animals = @animals.clone new_animals.delete_at(row) self.animals = new_animals # automatically loses deleted table row due to explicit data-binding end } cell_rows <= [self, :animals, column_attributes: {'Animal' => :name, 'Description' => :sound}] # explicit unidirectional data-binding of table cell_rows to self.animals on_changed do |row, type, row_data| puts "Row #{row} #{type}: #{row_data}" $stdout.flush end } } }.show end