1#
2# Demo: Layout
3#
4def demoLayout(t)
5  t.configure(:showroot=>false, :showrootbutton=>true, :showbuttons=>true,
6              :showlines=>true, :itemheight=>0, :selectmode=>:browse)
7
8  if $HasColumnCreate
9    t.column_create(:text=>'Layout')
10  else
11    t.column_configure(0, :text=>'Layout')
12  end
13
14  t.element_create('e1', :rect, :width=>30, :height=>30, :fill=>'gray20')
15  t.element_create('e2', :rect, :width=>30, :height=>30, :fill=>'gray40',
16                   :outline=>'blue', :outlinewidth=>3)
17  t.element_create('e3', :rect, :fill=>'gray60')
18  t.element_create('e4', :rect, :showfocus=>true,
19                   :fill=>[
20                     @SystemHighlight, ['selected', 'focus'], 'gray80', []
21                   ])
22  t.element_create('e5', :rect, :fill=>'{sky blue}', :width=>20, :height=>20)
23  t.element_create('e6', :rect, :fill=>'{sea green}', :width=>30, :height=>16)
24  t.element_create('e7', :rect, :fill=>'{sky blue}', :width=>30, :height=>16)
25  t.element_create('e8', :rect, :fill=>'gray70', :height=>1)
26
27  s = t.style_create('s1')
28  t.style_elements(s, ['e4', 'e3', 'e1', 'e2', 'e5', 'e6', 'e7'])
29  t.style_layout(s, 'e1', :padx=>[28, 4], :pady=>4)
30  t.style_layout(s, 'e2', :expand=>:es, :padx=>[0, 38])
31  t.style_layout(s, 'e3', :union=>['e1', 'e2'], :ipadx=>4, :ipady=>4, :pady=>2)
32  t.style_layout(s, 'e4', :detach=>true, :iexpand=>:es)
33  t.style_layout(s, 'e5', :detach=>true, :padx=>[2,0], :pady=>2, :iexpand=>:s)
34  t.style_layout(s, 'e6', :detach=>true, :expand=>:ws,
35                 :padx=>[0,2], :pady=>[2,0])
36  t.style_layout(s, 'e7', :detach=>true, :expand=>:wn,
37                 :padx=>[0,2], :pady=>[0,2])
38
39  if $Version_1_1_OrLater
40    i = t.item_create(:button=>true)
41  else
42    i = t.item_create
43    t.item_hasbutton(i, true)
44  end
45  t.item_style_set(i, 0, s)
46  t.item_lastchild(:root, i)
47  parent = i
48
49  i = t.item_create()
50  unless $Version_1_1_OrLater
51    t.item_hasbutton(i, false)
52  end
53  t.item_style_set(i, 0, s)
54  t.item_lastchild(parent, i)
55
56  ###
57
58  s = t.style_create('s2')
59  t.style_elements(s, ['e4', 'e3', 'e1'])
60  t.style_layout(s, 'e1', :padx=>8, :pady=>8, :iexpand=>:e)
61  t.style_layout(s, 'e3', :union=>['e1'], :ipadx=>[20,4], :ipady=>[4,12])
62  t.style_layout(s, 'e4', :detach=>true, :iexpand=>:es)
63
64  if $Version_1_1_OrLater
65    i = t.item_create(:button=>true)
66  else
67    i = t.item_create
68    t.item_hasbutton(i, true)
69  end
70  t.item_style_set(i, 0, s)
71  t.item_lastchild(:root, i)
72
73  i2 = t.item_create()
74  unless $Version_1_1_OrLater
75    t.item_hasbutton(i2, false)
76  end
77  t.item_style_set(i2, 0, s)
78  t.item_lastchild(i, i2)
79
80  ###
81
82  s = t.style_create('s3')
83  t.style_elements(s, ['e4', 'e3', 'e1', 'e5', 'e6'])
84  t.style_layout(s, 'e4', :union=>['e1', 'e6'], :ipadx=>8, :ipady=>[8,0])
85  t.style_layout(s, 'e3', :union=>['e1', 'e5'], :ipadx=>4, :ipady=>4)
86  t.style_layout(s, 'e5', :ipady=>[0,20])
87
88  if $Version_1_1_OrLater
89    i = t.item_create(:button=>true)
90  else
91    i = t.item_create
92    t.item_hasbutton(i, true)
93  end
94  t.item_style_set(i, 0, s)
95  t.item_lastchild(:root, i)
96
97  i2 = t.item_create()
98  unless $Version_1_1_OrLater
99    t.item_hasbutton(i2, false)
100  end
101  t.item_style_set(i2, 0, s)
102  t.item_lastchild(i, i2)
103
104  ###
105
106  t.element_create('eb', :border, :background=>@SystemButtonFace,
107                   :relief=>[:sunken, ['selected'], :raised, []],
108                   :thickness=>2, :filled=>true)
109  t.element_create('et', :text)
110
111  text = "Here is a text element surrounded by a border element.\nResize the column to watch me wrap."
112
113  s = t.style_create('e4')
114  t.style_elements(s, ['eb', 'et'])
115  t.style_layout(s, 'eb', :union=>['et'], :ipadx=>2, :ipady=>2)
116  t.style_layout(s, 'et', :squeeze=>:x)
117
118  if $Version_1_1_OrLater
119    i = t.item_create(:button=>true)
120  else
121    i = t.item_create
122    t.item_hasbutton(i, true)
123  end
124  t.item_style_set(i, 0, s)
125  t.item_text(i, 0, text)
126  t.item_lastchild(:root, i)
127  parent = i
128
129  i = t.item_create()
130  unless $Version_1_1_OrLater
131    t.item_hasbutton(i, false)
132  end
133  t.item_style_set(i, 0, s)
134  t.item_text(i, 0, text)
135  t.item_lastchild(parent, i)
136
137  ###
138
139  styleNum = 5
140  [
141    [:horizontal, [:s, :ns, :n]],
142    [:vertical,   [:e, :we, :w]]
143  ].each{|orient, expandList|
144    expandList.each{|expand|
145      s = t.style_create("s#{styleNum}", :orient=>orient)
146      t.style_elements(s, ['e4', 'e8', 'e2', 'e5', 'e6'])
147      t.style_layout(s, 'e4', :detach=>true, :iexpand=>:es)
148      t.style_layout(s, 'e8', :detach=>true, :expand=>:n, :iexpand=>:e)
149      t.style_layout(s, 'e2', :expand=>expand)
150      t.style_layout(s, 'e5', :expand=>expand)
151      t.style_layout(s, 'e6', :expand=>expand)
152      styleNum += 1
153
154      i = t.item_create()
155      t.item_style_set(i, 0, s)
156      t.item_lastchild(:root, i)
157    }
158  }
159end
160