Sha256: 7769367f8bcaea0611a55f09480d506cca6397a4c2c3e4df116655dd95ff4bfc
Contents?: true
Size: 1.25 KB
Versions: 2
Compression:
Stored size: 1.25 KB
Contents
#!/usr/bin/env ruby require "bundler/setup" require "tk_component" require "pry" class ColorBlock < TkComponent::Base def generate(parent_component, options = {}) parse_component(parent_component, options) do |p| p.canvas(background: options[:color], sticky: 'wens', x_flex: 1, y_flex: 1) end end end class DemoRoot < TkComponent::Base COLORS = %w|red yellow green brown blue orange| ROWS = 10 COLUMNS = 10 def generate(parent_component, options = {}) parse_component(parent_component, options) do |p| p.frame(sticky: 'wens', x_flex: 1, y_flex: 1) do |f| f.row(sticky: 'wens', x_flex: 1, y_flex: 1) do |r| r.button(text: "Refresh", columnspan: COLUMNS, sticky: 'e') do |b| b.on_click ->(e) { regenerate } end end ROWS.times do f.row(sticky: 'wens', x_flex: 1, y_flex: 1) do |r| COLUMNS.times do r.insert_component(ColorBlock, self, color: random_color, sticky: 'nsew', x_flex: 1, y_flex: 1) end end end end end end def random_color COLORS.sample end end @tk_root = TkComponent::Window.new(title: "Demo") @main_component = DemoRoot.new @tk_root.place_root_component(@main_component) Tk.mainloop
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tk_component-0.1.2 | bin/tiles_demo.rb |
tk_component-0.1.1 | bin/tiles_demo.rb |