-
Notifications
You must be signed in to change notification settings - Fork 241
/
Layout.cs
413 lines (381 loc) · 17.1 KB
/
Layout.cs
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
namespace ElmSharp
{
/// <summary>
/// This is a container widget that takes a standard edje design file and wraps it very thinly in a widget.
/// Inherits Widget.
/// </summary>
/// <since_tizen> preview </since_tizen>
public class Layout : Container
{
SmartEvent _languageChanged;
SmartEvent _themeChanged;
IntPtr _edjeHandle;
/// <summary>
/// Creates and initializes a new instance of the Layout class.
/// </summary>
/// <param name="parent">The parent is a given container, which will be attached by the layout as a child. It's <see cref="EvasObject"/> type.</param>
/// <since_tizen> preview </since_tizen>
public Layout(EvasObject parent) : base(parent)
{
}
/// <summary>
/// Creates and initializes a new instance of the Layout class.
/// </summary>
/// <since_tizen> preview </since_tizen>
protected Layout() : base()
{
}
/// <summary>
/// LanguageChanged will be triggered when the program's language is changed.
/// </summary>
/// <since_tizen> preview </since_tizen>
public event EventHandler LanguageChanged;
/// <summary>
/// ThemeChanged will be triggered when the theme is changed.
/// </summary>
/// <since_tizen> preview </since_tizen>
public event EventHandler ThemeChanged;
/// <summary>
/// Gets the edje layout.
/// </summary>
/// <since_tizen> preview </since_tizen>
public EdjeObject EdjeObject
{
get
{
if (_edjeHandle == IntPtr.Zero)
_edjeHandle = Interop.Elementary.elm_layout_edje_get(RealHandle);
return new EdjeObject(_edjeHandle);
}
}
/// <summary>
/// Gets or sets the accessibility state of texblock (text) parts in a layout object.
/// </summary>
/// <since_tizen> preview </since_tizen>
public bool TextBlockAccessibility
{
get
{
return Interop.Elementary.elm_layout_edje_object_can_access_get(RealHandle);
}
set
{
Interop.Elementary.elm_layout_edje_object_can_access_set(RealHandle, value);
}
}
/// <summary>
/// Freezes the Elementary layout object.
/// This function puts all the changes on hold.
/// Successive freezes will nest, requiring an equal number of thaws.
/// </summary>
/// <returns>The frozen state, or 0 if the object is not frozen or on error.</returns>
/// <since_tizen> preview </since_tizen>
public int Freeze()
{
return Interop.Elementary.elm_layout_freeze(RealHandle);
}
/// <summary>
/// Thaws the Elementary object.
/// If sucessives freezes were done, an equal number of thaws will be required.
/// </summary>
/// <returns>The frozen state, or 0 if the object is not frozen or on error.</returns>
/// <since_tizen> preview </since_tizen>
public int Thaw()
{
return Interop.Elementary.elm_layout_thaw(RealHandle);
}
/// <summary>
/// Eval sizing.
/// Manually forces a sizing re-evaluation.
/// This is useful when the minimum size required by the edje theme of this layout has changed.
/// The change on the minimum size required by the edje theme is not immediately reported to the elementary layout, so one needs to call this function in order to tell the widget (layout) that it needs to reevaluate its own size.
/// The minimum size of the theme is calculated based on the minimum size of parts, the size of elements inside containers like the box and table, etc.
/// All of this can change due to state changes, and that's when this function should be called.
/// </summary>
/// <since_tizen> preview </since_tizen>
public void Resizing()
{
Interop.Elementary.elm_layout_sizing_eval(RealHandle);
}
/// <summary>
/// Requests sizing re-evaluation, restricted to the current width and/or height.
/// Useful mostly when there are TEXTBLOCK parts defining the height of an object and nothing else, restricting it to a minimum width. Calling this function will restrict minimum size in the Edje calculation to whatever size the layout has at the moment.
/// </summary>
/// <param name="width">Restrict minimum size of the current width.</param>
/// <param name="height">Restrict minimum size of the current height.</param>
/// <since_tizen> preview </since_tizen>
public void Resizing(bool width, bool height)
{
Interop.Elementary.elm_layout_sizing_restricted_eval(RealHandle, width, height);
}
/// <summary>
/// Gets the edje data from the given layout.
/// This function fetches the data specified inside the edje theme of this layout.
/// This function returns null if the data is not found.
/// </summary>
/// <param name="key">The data key.</param>
/// <returns>The data.</returns>
/// <since_tizen> preview </since_tizen>
public string GetEdjeData(string key)
{
return Interop.Elementary.elm_layout_data_get(RealHandle, key);
}
/// <summary>
/// Gets the text set in the given part.
/// </summary>
/// <param name="part">The text part to retrieve the text off.</param>
/// <returns></returns>
/// <since_tizen> preview </since_tizen>
public override string GetPartText(string part)
{
return Interop.Elementary.elm_layout_text_get(RealHandle, part);
}
/// <summary>
/// Sets the text set in the given part.
/// </summary>
/// <param name="part">The text part to retrieve the text off.</param>
/// <param name="text">The text to set.</param>
/// <returns></returns>
/// <since_tizen> preview </since_tizen>
public override bool SetPartText(string part, string text)
{
return Interop.Elementary.elm_layout_text_set(RealHandle, part, text);
}
/// <summary>
/// Appends a child to the layout box part.
/// Once the object is appended, it will become a child of the layout.
/// Its lifetime will be bound to the layout. Whenever the layout dies, the child will be deleted automatically.
/// </summary>
/// <remarks>
/// This will only work if the layout edc have box part.
/// </remarks>
/// <param name="part">The part.</param>
/// <param name="child">The object to append.</param>
/// <returns>Success is true.</returns>
/// <since_tizen> preview </since_tizen>
public bool BoxAppend(string part, EvasObject child)
{
AddChild(child);
return Interop.Elementary.elm_layout_box_append(RealHandle, part, child.Handle);
}
/// <summary>
/// Prepends a child to the layout box part.
/// Once the object is prepended, it will become a child of the layout.
/// Its lifetime will be bound to the layout. Whenever the layout dies, the child will be deleted automatically.
/// </summary>
/// <remarks>
/// This will only work if the layout edc have box part.
/// </remarks>
/// <param name="part">The part.</param>
/// <param name="child">The object to prepend.</param>
/// <returns>Success is true.</returns>
/// <since_tizen> preview </since_tizen>
public bool BoxPrepend(string part, EvasObject child)
{
AddChild(child);
return Interop.Elementary.elm_layout_box_prepend(RealHandle, part, child.Handle);
}
/// <summary>
/// Removes a child from the given part box.
/// The object will be removed from the box part and its lifetime will not be handled by the layout anymore.
/// </summary>
/// <remarks>
/// This will only work if the layout edc have box part.
/// </remarks>
/// <param name="part">The part.</param>
/// <param name="child">The object to remove.</param>
/// <returns>Success if true</returns>
/// <since_tizen> preview </since_tizen>
public bool BoxRemove(string part, EvasObject child)
{
RemoveChild(child);
return Interop.Elementary.elm_layout_box_remove(RealHandle, part, child.Handle) != IntPtr.Zero;
}
/// <summary>
/// Removes all the children from the given part box.
/// The objects will be removed from the box part and their lifetime will not be handled by the layout anymore.
/// </summary>
/// <remarks>
/// This will only work if the layout edc have box part.
/// </remarks>
/// <param name="part">The part.</param>
/// <param name="clear">If true, then all the objects will be deleted as well, otherwise they will just be removed and will be dangling on the canvas.</param>
/// <returns>Success if true.</returns>
/// <since_tizen> preview </since_tizen>
public bool BoxRemoveAll(string part, bool clear)
{
ClearChildren();
return Interop.Elementary.elm_layout_box_remove_all(RealHandle, part, clear);
}
/// <summary>
/// Inserts a child to the layout box part at a given position.
/// Once the object is inserted, it will become a child of the layout.
/// Its lifetime will be bound to the layout. Whenever the layout dies, the child will be deleted automatically.
/// </summary>
/// <remarks>
/// This will only work if the layout edc have box part.
/// </remarks>
/// <param name="part">The part.</param>
/// <param name="child">The child object to insert into the box.</param>
/// <param name="position">The numeric position >=0 to insert the child.</param>
/// <returns>Success if true.</returns>
/// <since_tizen> preview </since_tizen>
public bool BoxInsertAt(string part, EvasObject child, uint position)
{
AddChild(child);
return Interop.Elementary.elm_layout_box_insert_at(RealHandle, part, child.Handle, position);
}
/// <summary>
/// Inserts a child to the layout box part before a reference object.
/// Once the object is inserted, it will become child of the layout.
/// Its lifetime will be bound to the layout. Whenever the layout dies, the child will be deleted automatically.
/// </summary>
/// <remarks>
/// This will only work if the layout edc have box part.
/// </remarks>
/// <param name="part">The part.</param>
/// <param name="child">The child object to insert into the box.</param>
/// <param name="reference">Another reference object to insert before the box.</param>
/// <returns>Success is true.</returns>
/// <since_tizen> preview </since_tizen>
public bool BoxInsertBefore(string part, EvasObject child, EvasObject reference)
{
AddChild(child);
return Interop.Elementary.elm_layout_box_insert_before(RealHandle, part, child.Handle, reference.Handle);
}
/// <summary>
/// Sets the layout content.
/// </summary>
/// <param name="part">The swallow part name in the edje file.</param>
/// <param name="content">The child that will be added in this layout object.</param>
/// <returns>TRUE on success, FALSE otherwise.</returns>
/// <since_tizen> preview </since_tizen>
public override bool SetPartContent(string part, EvasObject content)
{
return SetPartContent(part, content, false);
}
/// <summary>
/// Sets the layout content.
/// </summary>
/// <param name="part">The name of a particular part.</param>
/// <param name="content">The content.</param>
/// <param name="preserveOldContent">true, preserve old content will be unset. false, preserve old content will not be unset.</param>
/// <returns>TRUE on success, FALSE otherwise.</returns>
/// <since_tizen> preview </since_tizen>
public override bool SetPartContent(string part, EvasObject content, bool preserveOldContent)
{
if (preserveOldContent)
{
Interop.Elementary.elm_layout_content_unset(RealHandle, part);
}
UpdatePartContents(content, part);
return Interop.Elementary.elm_layout_content_set(RealHandle, part, content);
}
/// <summary>
/// Sets the edje group from the elementary theme that is used as a layout.
/// </summary>
/// <param name="klass">The class of the group.</param>
/// <param name="group">The group.</param>
/// <param name="style">The style to use.</param>
/// <since_tizen> preview </since_tizen>
public void SetTheme(string klass, string group, string style)
{
Interop.Elementary.elm_layout_theme_set(RealHandle, klass, group, style);
}
/// <summary>
/// Sets the file that is used as a layout.
/// </summary>
/// <param name="file">The path to the file (edje) that is used as a layout.</param>
/// <param name="group">The group that the layout belongs to in the edje file.</param>
/// <since_tizen> preview </since_tizen>
public void SetFile(string file, string group)
{
Interop.Elementary.elm_layout_file_set(RealHandle, file, group);
}
/// <summary>
/// Sets the background color of a layout.
/// </summary>
/// <since_tizen> preview </since_tizen>
public override Color BackgroundColor
{
set
{
if (value.IsDefault)
{
Interop.Elementary.elm_object_color_class_del(RealHandle, "bg");
}
else
{
SetPartColor("bg", value);
}
_backgroundColor = value;
}
}
/// <summary>
/// Sets the vertical text alignment of the layout's text part.
/// </summary>
/// <remarks>
/// API, elm_layout_text_valign_set, is an internal API only in Tizen. Available since Tizen_4.0.
/// </remarks>
/// <since_tizen> preview </since_tizen>
public virtual void SetVerticalTextAlignment(string part, double valign)
{
Interop.Elementary.elm_layout_text_valign_set(RealHandle, part, valign);
}
/// <summary>
/// Gets the vertical text alignment of the layout's text part.
/// </summary>
/// <remarks>
/// API, elm_layout_text_valign_get, is an internal API only in Tizen. Available since Tizen_4.0.
/// </remarks>
/// <since_tizen> preview </since_tizen>
public virtual double GetVerticalTextAlignment(string part)
{
return Interop.Elementary.elm_layout_text_valign_get(RealHandle, part);
}
/// <summary>
/// The callback of the Realized Event.
/// </summary>
/// <since_tizen> preview </since_tizen>
protected override void OnRealized()
{
base.OnRealized();
_languageChanged = new SmartEvent(this, this.RealHandle, "language,changed");
_languageChanged.On += (s, e) =>
{
LanguageChanged?.Invoke(this, EventArgs.Empty);
};
_themeChanged = new SmartEvent(this, this.RealHandle, "theme,changed");
_themeChanged.On += (s, e) =>
{
ThemeChanged?.Invoke(this, EventArgs.Empty);
};
}
/// <summary>
/// Sets the content at a part of a given container widget.
/// </summary>
/// <param name="parent">The parent is a given container which will be attached by the layout as a child. It's <see cref="EvasObject"/> type.</param>
/// <returns>The new object, otherwise null if it cannot be created.</returns>
/// <since_tizen> preview </since_tizen>
protected override IntPtr CreateHandle(EvasObject parent)
{
return Interop.Elementary.elm_layout_add(parent.Handle);
}
}
}