summaryrefslogtreecommitdiff
path: root/testsuite/reftests/align-expand.sh
blob: 4e61f4adb588a4cffa077270bfc27a53a65cdc80 (plain)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/bin/bash
#
# align-expand.sh [METHOD]
#
# This is the script used to create the align-expand tests. These tests
# put a 20x20 size-requested GtkTreeView into a 40x40 size-requested
# container and try to achieve multiple combinations of expand and align
# flags. The resulting GtkBuilder file is written to stdout. All of the
# resulting files should render identical.
#
# METHOD is one of:
# * flags (default)
#   Uses expand flags to align and expand the treeview inside a GtkGrid.
#   You should use this as the reference when adding tests for other
#   methods
# * alignment
#   Aligns and expands the treeview in a GtkAlignment using its scale
#   and align properties.


if test $# -lt 1; then
  method="flags"
else
  method=$1
fi

cat << EOF
<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <!-- interface-requires gtk+ 3.0 -->
  <object class="GtkWindow" id="window">
    <property name="can_focus">False</property>
    <property name="type">popup</property>
    <child>
      <object class="GtkGrid" id="grid">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="row_spacing">2</property>
        <property name="column_spacing">2</property>
EOF


y=2
for hexpand in False True; do
for halign in "start" center end fill; do

cat << EOF
        <child>
          <object class="GtkLabel" id="hexpand-$halign-$hexpand">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="label">$hexpand</property>
            <property name="angle">90</property>
          </object>
          <packing>
            <property name="left_attach">$y</property>
            <property name="top_attach">0</property>
            <property name="width">1</property>
            <property name="height">1</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel" id="halign-$halign-$hexpand">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="label">$halign</property>
            <property name="angle">90</property>
          </object>
          <packing>
            <property name="left_attach">$y</property>
            <property name="top_attach">1</property>
            <property name="width">1</property>
            <property name="height">1</property>
          </packing>
        </child>
EOF
x=2
for vexpand in False True; do
for valign in "start" center end fill; do

if test $y = "2"; then
cat << EOF
        <child>
          <object class="GtkLabel" id="vexpand-$valign-$vexpand">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="label">$vexpand</property>
          </object>
          <packing>
            <property name="left_attach">0</property>
            <property name="top_attach">$x</property>
            <property name="width">1</property>
            <property name="height">1</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel" id="valign-$valign-$vexpand">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="label">$valign</property>
          </object>
          <packing>
            <property name="left_attach">1</property>
            <property name="top_attach">$x</property>
            <property name="width">1</property>
            <property name="height">1</property>
          </packing>
        </child>
EOF
fi

if test $method = "flags"; then

cat << EOF
        <child>
          <object class="GtkGrid" id="grid-$valign-$halign-$vexpand-$hexpand">
            <property name="width_request">40</property>
            <property name="height_request">40</property>
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <child>
              <object class="GtkTreeView" id="treeview-$valign-$halign-$vexpand-$hexpand">
                <property name="width_request">20</property>
                <property name="height_request">20</property>
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="halign">$halign</property>
                <property name="valign">$valign</property>
                <property name="hexpand">$hexpand</property>
                <property name="vexpand">$vexpand</property>
              </object>
              <packing>
                <property name="left_attach">0</property>
                <property name="top_attach">0</property>
                <property name="width">1</property>
                <property name="height">1</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="left_attach">$x</property>
            <property name="top_attach">$y</property>
            <property name="width">1</property>
            <property name="height">1</property>
          </packing>
        </child>
EOF
  
elif test $method = "alignment"; then

xscale=0.0
case "$halign" in
  "start") xalign=0.0 ;;
  "center") xalign=0.5 ;;
  "end") xalign=1.0 ;;
  "fill") xalign=0.5; xscale=1.0 ;;
esac
if test $hexpand = "True"; then
  xscale=1.0
fi

yscale=0.0
case "$valign" in
  "start") yalign=0.0 ;;
  "center") yalign=0.5 ;;
  "end") yalign=1.0 ;;
  "fill") yalign=0.5; yscale=1.0 ;;
esac
if test $vexpand = "True"; then
  yscale=1.0
fi

cat << EOF
        <child>
          <object class="GtkAlignment" id="align-$valign-$halign-$vexpand-$hexpand">
            <property name="width_request">40</property>
            <property name="height_request">40</property>
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="xalign">$xalign</property>
            <property name="yalign">$yalign</property>
            <property name="xscale">$xscale</property>
            <property name="yscale">$yscale</property>
            <child>
              <object class="GtkTreeView" id="treeview-$valign-$halign-$vexpand-$hexpand">
                <property name="width_request">20</property>
                <property name="height_request">20</property>
                <property name="visible">True</property>
                <property name="can_focus">False</property>
              </object>
            </child>
          </object>
          <packing>
            <property name="left_attach">$x</property>
            <property name="top_attach">$y</property>
            <property name="width">1</property>
            <property name="height">1</property>
          </packing>
        </child>
EOF

else

  exit 1

fi

x=`expr $x + 1`
done
done

y=`expr $y + 1`
x=0
done
done

cat << EOF
      </object>
    </child>
  </object>
</interface>
EOF