~tpeeters/ubuntu-ui-toolkit/tabs-autoactive

« back to all changes in this revision

Viewing changes to modules/Ubuntu/Layouts/ubuntu-layouts.qdoc

  • Committer: Zsombor Egri
  • Date: 2013-06-07 09:08:17 UTC
  • mto: This revision was merged to the branch mainline in revision 552.
  • Revision ID: zsombor.egri@canonical.com-20130607090817-icehjbol9ddcg6pe
more documentation

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
  Tutorial chapters:
59
59
  \list 1
60
60
  \li \l {Layouts - Terminology}{Terminology}
61
 
  \li \l {Layouts - A simple layout}{A simple layout}
 
61
  \li \l {Layouts - The first conditional layout}{The first conditional layout}
 
62
  \li \l {Layouts - Resizing items laid out}{Resizing items laid out}
 
63
  \li \l {Layouts - Changing the order}{Changing the order}
 
64
  \li \l {Layouts - Lay out a single item differently from others}{Lay out a single item differently from others}
 
65
  \li \l {Layouts - Lay out individual items separately}{Lay out individual items separately}
 
66
  \li \l {Layouts - Defining more layouts for different form factors}{Defining more layouts for different form factors}
62
67
  \endlist
 
68
 
 
69
  So, let's take them step-by-step...
63
70
*/
64
71
 
65
72
/*!
66
73
  \page ubuntu-layouts1.html
67
74
  \title Layouts - Terminology
68
 
  \nextpage Layouts - A simple layout
 
75
  \nextpage Layouts - The first conditional layout
69
76
 
70
77
  First let's introduce the terminology we are going to use across this tutorial.
71
78
 
93
100
  Illustrating the layout on the image with code:
94
101
 
95
102
  \qml
96
 
  Layouts { // <-- \b{layout block}
 
103
  Layouts { // <-- layout block
97
104
      id: layouts
98
105
      layouts: [
99
 
          ConditionalLayout { // <-- \b layout
 
106
          // [...]
 
107
          ConditionalLayout { // <-- layout
100
108
              name: "composit"
101
 
              Row { // <-- \b{layout container}
 
109
              Row { // <-- layout container
102
110
                  // [...]
103
 
                  ItemLayout { // <-- \b{item holder}
 
111
                  ItemLayout { // <-- item holder
104
112
                      item: "item2"
105
113
                      // [...]
106
114
                  }
135
143
 
136
144
/*!
137
145
  \page ubuntu-layouts2.html
138
 
  \title Layouts - A simple layout
 
146
  \title Layouts - The first conditional layout
 
147
  \nextpage Layouts - Resizing items laid out
139
148
 
140
149
  As first let's create the following default layout, with anchored buttons to each other.
141
150
  \image default-layout.png
142
 
*/
 
151
 
 
152
  Defined by the following code:
 
153
  \snippet layouts/layout1.qml default layout
 
154
 
 
155
  \section1 Walkthrough
 
156
  \section2 Import
 
157
  First of all, in order to use the layouting abilities, you need to import Ubuntu.Layouts.
 
158
  \code
 
159
  import Ubuntu.Layouts 0.1
 
160
  \endcode
 
161
 
 
162
  This layout will have the red button anchored to the parent's left, top and bottom, having
 
163
  a width of 15 grid units. The green and blue buttons are anchored left to the red button,
 
164
  righ to their parent, top and bottom to the parent top rrespectively to the parent bottom
 
165
  and both having a height of 10 grid units.
 
166
 
 
167
  This layout looks good in small form factors, however as the width, height and grid unit
 
168
  changes, this layout will start to look cumbersome.
 
169
 
 
170
  \section2 Define the conditional layout
 
171
  Let's define a column layout for the case when the layout block width passes 50 GU, and
 
172
  move the items into a \l{http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-row.html}{Row}
 
173
  container in the following order: "red", "green" and "blue". We embedd the positioner
 
174
  into a \l{http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-flickable.html}{Flickable}
 
175
  so we can still access the components positioned in case the content is not fit with the
 
176
  current width.
 
177
  \snippet layouts/layout1.qml row layout
 
178
 
 
179
  Note the way the container is defined. ConditionalLayout.items attached property lists
 
180
  the items to be hosted (laid out) and the order of the items of those.
 
181
 
 
182
  Combining this with the default layout we will see the following layout when width exceeds
 
183
  50 GU:
 
184
  \image layout1.png
 
185
  \snippet layouts/layout1.qml 0
 
186
 
 
187
  As you can see the blue button is not visible whan the row layout is activated. In fact
 
188
  the blue button will never be shown when the row layout gets activated, as both green and
 
189
  blue buttons being anchored right to their parent and left to the red button, they will
 
190
  get the width of the last time they have neen still in the default layout. This may be
 
191
  the desired behavior, however it may also look clumsy. Let's see how can we circumvent that.
 
192
*/
 
193
 
 
194
/*!
 
195
  \page ubuntu-layouts3.html
 
196
  \title Layouts - Resizing items laid out
 
197
  \nextpage Layouts - Changing the order
 
198
 
 
199
  So, let's take the layout we did so far in \l{Layouts - The first conditional layout}{The first conditional layout}
 
200
  and define the width of each item to be one third of the layout's width. We can do this by
 
201
  defining the ConditionalLayout.width attached property, which will be applied to each item
 
202
  listed in the ConditionalLayout.items attached property.
 
203
  \snippet layouts/layout2.qml row layout
 
204
  \image layout2-1.png
 
205
  \image layout2-2.png
 
206
  Similar thing can be done with the height by defining the value or expression in
 
207
  ConditionalLayout.height attached property. Note that this property will also be applied
 
208
  to each item hosted by the container.
 
209
 
 
210
  The entire code will look as follows:
 
211
  \snippet layouts/layout2.qml 0
 
212
 
 
213
*/
 
214
 
 
215
/*!
 
216
  \page ubuntu-layouts4.html
 
217
  \title Layouts - Changing the order
 
218
  \nextpage Layouts - Lay out a single item differently from others
 
219
 
 
220
  So far we have seen how to define the defaul tlayout, a conditional layout and how to resize
 
221
  each of them.
 
222
 
 
223
  As mentioned in ConditionalLayout documentation, items hosted by the container are laid
 
224
  out based on the order they are specified in the ConditionalLayout.items attached property.
 
225
 
 
226
  To illustrate this, let's change the order of the buttons so that we have blue, red and green
 
227
  order.
 
228
 
 
229
  \snippet layouts/layout3.qml row layout
 
230
  The layout after resizing the window width to exceed 50 GU will look as follows:
 
231
  \image layout3.png
 
232
 
 
233
  Note that when resizing the window width to < 50 GU, you will get all your components back to
 
234
  their original (default) positions.
 
235
 
 
236
  The layout has the red button with a different height than the other two. This is because the
 
237
  height is "inherited" from the time they were transferred from the default layout. But what if
 
238
  I want to have one of the butons to be of a different size than the others? Or what if I want
 
239
  to have each of them to hav edifferent sizes? The following chapters will show how to do this.
 
240
*/
 
241
 
 
242
/*!
 
243
  \page ubuntu-layouts5.html
 
244
  \title Layouts - Lay out a single item differently from others
 
245
  \nextpage Layouts - Lay out individual items separately
 
246
  Let's create a layout where the blue button has a different size than the other two. We can
 
247
  achieve this by using ItemLayout component to host the blue button. Let's also resize the other
 
248
  biuttons to hav ethe same width and height.
 
249
  The code will look as follows:
 
250
  \snippet layouts/layout4.qml row layout
 
251
  \image layout4.png
 
252
*/
 
253
 
 
254
/*!
 
255
  \page ubuntu-layouts6.html
 
256
  \title Layouts - Lay out individual items separately
 
257
  \nextpage Layouts - Defining more layouts for different form factors
 
258
 */
 
259
 
 
260
/*!
 
261
  \page ubuntu-layouts7.html
 
262
  \title Layouts - Defining more layouts for different form factors
 
263
 */