-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaddress_form_custom_control.rb
88 lines (72 loc) · 1.81 KB
/
address_form_custom_control.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require 'glimmer-dsl-libui'
class Address
ATTRIBUTES = [:name, :street, :city, :state, :zip]
attr_accessor *ATTRIBUTES
def summary
ATTRIBUTES.map(&method(:send)).compact.reject(&:empty?).join(', ')
end
end
class User
attr_accessor :addresses
def initialize
@addresses = 2.times.map { Address.new }
end
end
class AddressForm
include Glimmer::LibUI::CustomControl
option :address
body {
vertical_box {
form {
Address::ATTRIBUTES.each do |attribute|
entry {
label attribute.to_s.capitalize
text <=> [address, attribute]
}
end
}
label {
stretchy false
text <= [address, :summary, computed_by: Address::ATTRIBUTES]
}
}
}
end
class AddressFormApp
include Glimmer
def initialize
@user = User.new
@user.addresses[0].name = 'John Doe'
@user.addresses[0].street = '123 Main St.'
@user.addresses[0].city = 'San Diego'
@user.addresses[0].state = 'California'
@user.addresses[0].zip = '92108'
@user.addresses[1].name = 'Johnny Doe'
@user.addresses[1].street = '2000 Main St.'
@user.addresses[1].city = 'San Diego'
@user.addresses[1].state = 'CA'
@user.addresses[1].zip = '92109'
create_gui_body
end
def create_gui_body
@window = window('Address Form Custom Control') { |main_window|
content_size 400, 200
margined true
vertical_box {
label('1) Shipping Address') {
stretchy false
}
address_form(address: @user.addresses[0])
label('2) Billing Address') {
stretchy false
}
address_form(address: @user.addresses[1])
}
}
end
def launch
@window.show
end
end
address_form_app = AddressFormApp.new
address_form_app.launch