Sha256: aa0fef830d6635e8f36ec92d07ae0e4b3076b99a7bd3af62fa43be338727019f

Contents?: true

Size: 1.97 KB

Versions: 64

Compression:

Stored size: 1.97 KB

Contents

require 'glimmer-dsl-libui'
require 'facets'

include Glimmer

Address = Struct.new(:street, :p_o_box, :city, :state, :zip_code)

def form_field(model, property)
  property = property.to_s
  entry { |e|
    label property.underscore.split('_').map(&:capitalize).join(' ')
    text model.send(property).to_s

    on_changed do
      model.send("#{property}=", e.text)
    end
  }
end

def address_form(address_model)
  form {
    form_field(address_model, :street)
    form_field(address_model, :p_o_box)
    form_field(address_model, :city)
    form_field(address_model, :state)
    form_field(address_model, :zip_code)
  }
end

def label_pair(model, attribute, value)
  name_label = nil
  value_label = nil
  horizontal_box {
    name_label = label(attribute.to_s.underscore.split('_').map(&:capitalize).join(' '))
    value_label = label(value.to_s)
  }
  observe(model, attribute) do
    value_label.text = model.send(attribute)
  end
end

def address_view(address_model)
  vertical_box {
    address_model.each_pair do |attribute, value|
      label_pair(address_model, attribute, value)
    end
  }
end

address1 = Address.new('123 Main St', '23923', 'Denver', 'Colorado', '80014')
address2 = Address.new('2038 Park Ave', '83272', 'Boston', 'Massachusetts', '02101')

window('Method-Based Custom Controls') {
  margined true
  
  horizontal_box {
    vertical_box {
      label('Address 1') {
        stretchy false
      }
      
      address_form(address1)
      
      horizontal_separator {
        stretchy false
      }
      
      label('Address 1 (Saved)') {
        stretchy false
      }
      
      address_view(address1)
    }
    
    vertical_separator {
      stretchy false
    }
    
    vertical_box {
      label('Address 2') {
        stretchy false
      }
      
      address_form(address2)
      
      horizontal_separator {
        stretchy false
      }
      
      label('Address 2 (Saved)') {
        stretchy false
      }
      
      address_view(address2)
    }
  }
}.show

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
glimmer-dsl-libui-0.12.5 examples/method_based_custom_controls2.rb
glimmer-dsl-libui-0.12.4 examples/method_based_custom_controls2.rb
glimmer-dsl-libui-0.12.3 examples/method_based_custom_controls2.rb
glimmer-dsl-libui-0.12.2 examples/method_based_custom_controls2.rb
glimmer-dsl-libui-0.12.1 examples/method_based_custom_controls2.rb
glimmer-dsl-libui-0.12.0 examples/method_based_custom_controls2.rb
glimmer-dsl-libui-0.11.10 examples/method_based_custom_controls2.rb
glimmer-dsl-libui-0.11.9 examples/method_based_custom_controls2.rb
glimmer-dsl-libui-0.11.8 examples/method_based_custom_controls2.rb
glimmer-dsl-libui-0.11.7 examples/method_based_custom_controls2.rb
glimmer-dsl-libui-0.11.6 examples/method_based_custom_controls2.rb
glimmer-dsl-libui-0.11.5 examples/method_based_custom_controls2.rb
glimmer-dsl-libui-0.11.4 examples/method_based_custom_controls2.rb
glimmer-dsl-libui-0.11.3 examples/method_based_custom_controls2.rb
glimmer-dsl-libui-0.11.2 examples/method_based_custom_controls2.rb
glimmer-dsl-libui-0.11.1 examples/method_based_custom_controls2.rb
glimmer-dsl-libui-0.11.0 examples/method_based_custom_controls2.rb
glimmer-dsl-libui-0.10.2 examples/method_based_custom_controls2.rb
glimmer-dsl-libui-0.10.1 examples/method_based_custom_controls2.rb
glimmer-dsl-libui-0.10.0 examples/method_based_custom_controls2.rb