2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 /// This is a container widget that takes a standard Edje design file and wraps it very thinly in a widget.
25 public class Layout : Container
27 SmartEvent _languageChanged;
28 SmartEvent _themeChanged;
33 /// Creates and initializes a new instance of Layout class.
35 /// <param name="parent">The parent is a given container which will be attached by Layout as a child. It's <see cref="EvasObject"/> type.</param>
36 public Layout(EvasObject parent) : base(parent)
41 /// Creates and initializes a new instance of Layout class.
43 protected Layout() : base()
48 /// LanguageChanged will be triggered when the program's language is changed.
50 public event EventHandler LanguageChanged;
53 /// ThemeChanged will be triggered when the theme is changed.
55 public event EventHandler ThemeChanged;
58 /// Gets the edje layout.
60 public EdjeObject EdjeObject
64 if (_edjeHandle == IntPtr.Zero)
65 _edjeHandle = Interop.Elementary.elm_layout_edje_get(RealHandle);
66 return new EdjeObject(_edjeHandle);
71 /// Gets or sets accessibility state of texblock(text) parts in the layout object.
73 public bool TextBlockAccessibility
77 return Interop.Elementary.elm_layout_edje_object_can_access_get(RealHandle);
81 Interop.Elementary.elm_layout_edje_object_can_access_set(RealHandle, value);
86 /// Freezes the Elementary layout object.
87 /// This function puts all changes on hold.
88 /// Successive freezes will nest, requiring an equal number of thaws.
90 /// <returns>The frozen state or 0 if the object is not frozen or on error.</returns>
93 return Interop.Elementary.elm_layout_freeze(RealHandle);
97 /// Thaws the Elementary object.
98 /// If sucessives freezes were done, an equal number of thaws will be required.
100 /// <returns>The frozen state or 0 if the object is not frozen or on error.</returns>
103 return Interop.Elementary.elm_layout_thaw(RealHandle);
108 /// Manually forces a sizing re-evaluation.
109 /// This is useful when the minimum size required by the edje theme of this layout has changed.
110 /// 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.
111 /// The minimum size of the theme is calculated based on minimum size of parts, the size of elements inside containers like box and table, etc.
112 /// All of this can change due to state changes, and that's when this function should be called.
114 public void Resizing()
116 Interop.Elementary.elm_layout_sizing_eval(RealHandle);
120 /// Request sizing reevaluation, restricted to current width and/or height.
121 /// Useful mostly when there are TEXTBLOCK parts defining the height of the object and nothing else restricting it to a minimum width.Calling this function will restrict the minimum size in the Edje calculation to whatever size it the layout has at the moment.
123 /// <param name="width">Restrict minimum size ot the current width.</param>
124 /// <param name="height">Restrict minimum size ot the current height.</param>
125 public void Resizing(bool width, bool height)
127 Interop.Elementary.elm_layout_sizing_restricted_eval(RealHandle, width, height);
131 /// Get the edje data from the given layout.
132 /// This function fetches data specified inside the edje theme of this layout.
133 /// This function return NULL if data is not found.
135 /// <param name="key">The data key</param>
136 /// <returns>The data</returns>
137 public string GetEdjeData(string key)
139 return Interop.Elementary.elm_layout_data_get(RealHandle, key);
143 /// Gets the text set in the given part.
145 /// <param name="part">The TEXT part to retrieve the text off.</param>
146 /// <returns></returns>
147 public override string GetPartText(string part)
149 return Interop.Elementary.elm_layout_text_get(RealHandle, part);
153 /// Sets the text set in the given part.
155 /// <param name="part">The TEXT part to retrieve the text off.</param>
156 /// <param name="text">The text to set.</param>
157 /// <returns></returns>
158 public override bool SetPartText(string part, string text)
160 return Interop.Elementary.elm_layout_text_set(RealHandle, part, text);
164 /// Append child to layout box part.
165 /// Once the object is appended, it will become child of the layout.
166 /// Its lifetime will be bound to the layout, whenever the layout dies the child will be deleted automatically.
168 /// <param name="part">The part</param>
169 /// <param name="child">The Object to append</param>
170 /// <returns>Sucess is true</returns>
171 public bool BoxAppend(string part, EvasObject child)
174 return Interop.Elementary.elm_layout_box_append(RealHandle, part, child.Handle);
178 /// Prepend child to layout box part.
179 /// Once the object is prepended, it will become child of the layout.
180 /// Its lifetime will be bound to the layout, whenever the layout dies the child will be deleted automatically.
182 /// <param name="part">The part</param>
183 /// <param name="child">The Object to prepend</param>
184 /// <returns>Sucess is true</returns>
185 public bool BoxPrepend(string part, EvasObject child)
188 return Interop.Elementary.elm_layout_box_prepend(RealHandle, part, child.Handle);
192 /// Remove a child of the given part box.
193 /// The object will be removed from the box part and its lifetime will not be handled by the layout anymore.
195 /// <param name="part">The part</param>
196 /// <param name="child">The Object to remove</param>
197 /// <returns>Sucess is true</returns>
198 public bool BoxRemove(string part, EvasObject child)
201 return Interop.Elementary.elm_layout_box_remove(RealHandle, part, child.Handle) != null;
205 /// Remove all children of the given part box.
206 /// The objects will be removed from the box part and their lifetime will not be handled by the layout anymore.
208 /// <param name="part">The part</param>
209 /// <param name="clear">If true, then all objects will be deleted as well, otherwise they will just be removed and will be dangling on the canvas.</param>
210 /// <returns>Sucess is true</returns>
211 public bool BoxRemoveAll(string part, bool clear)
214 return Interop.Elementary.elm_layout_box_remove_all(RealHandle, part, clear);
218 /// Insert child to layout box part at a given position.
219 /// Once the object is inserted, it will become child of the layout.
220 /// Its lifetime will be bound to the layout, whenever the layout dies the child will be deleted automatically.
222 /// <param name="part">The part</param>
223 /// <param name="child">The child object to insert into box.</param>
224 /// <param name="position">The numeric position >=0 to insert the child.</param>
225 /// <returns>Sucess is true</returns>
226 public bool BoxInsertAt(string part, EvasObject child, uint position)
229 return Interop.Elementary.elm_layout_box_insert_at(RealHandle, part, child.Handle, position);
233 /// Insert child to layout box part before a reference object.
234 /// Once the object is inserted, it will become child of the layout.
235 /// Its lifetime will be bound to the layout, whenever the layout dies the child will be deleted automatically.
237 /// <param name="part"></param>
238 /// <param name="child">The child object to insert into box.</param>
239 /// <param name="reference">Another reference object to insert before in box.</param>
240 /// <returns>Sucess is true</returns>
241 public bool BoxInsertBefore(string part, EvasObject child, EvasObject reference)
244 return Interop.Elementary.elm_layout_box_insert_before(RealHandle, part, child.Handle, reference.Handle);
248 /// Sets the layout content.
250 /// <param name="part">The swallow part name in the edje file</param>
251 /// <param name="content">The child that will be added in this layout object.</param>
252 /// <returns>TRUE on success, FALSE otherwise</returns>
253 public override bool SetPartContent(string part, EvasObject content)
255 return SetPartContent(part, content, false);
259 /// Sets the layout content.
261 /// <param name="part">The name of particular part</param>
262 /// <param name="content">The content</param>
263 /// <param name="preserveOldContent">true, preserve old content will be unset. false, preserve old content will not be unset.</param>
264 /// <returns>TRUE on success, FALSE otherwise</returns>
265 public override bool SetPartContent(string part, EvasObject content, bool preserveOldContent)
267 if (preserveOldContent)
269 Interop.Elementary.elm_layout_content_unset(RealHandle, part);
271 UpdatePartContents(content, part);
272 return Interop.Elementary.elm_layout_content_set(RealHandle, part, content);
276 /// Sets the edje group from the elementary theme that is used as a layout.
278 /// <param name="klass">The class of the group</param>
279 /// <param name="group">The group</param>
280 /// <param name="style">The style to use</param>
281 public void SetTheme(string klass, string group, string style)
283 Interop.Elementary.elm_layout_theme_set(RealHandle, klass, group, style);
287 /// Sets the file that is used as a layout.
289 /// <param name="file">The path to the file (edj) that is used as a layout</param>
290 /// <param name="group">The group that the layout belongs to in the edje file</param>
291 public void SetFile(string file, string group)
293 Interop.Elementary.elm_layout_file_set(RealHandle, file, group);
297 /// Sets the back ground color of layout
299 public override Color BackgroundColor
303 if (value.IsDefault && ClassName != null)
305 string part = ClassName.ToLower().Replace("elm_", "") + "/" + "bg";
306 EdjeObject.DeleteColorClass(part);
310 SetPartColor("bg", value);
312 _backgroundColor = value;
317 /// Sets the vertical text alignment of layout's text part
320 /// API, elm_layout_text_valign_set, is an internal API only in Tizen. Avalilable since Tizen_4.0.
322 public virtual void SetVerticalTextAlignment(string part, double valign)
324 Interop.Elementary.elm_layout_text_valign_set(RealHandle, part, valign);
328 /// Gets the vertical text alignment of layout's text part
331 /// API, elm_layout_text_valign_get, is internal API only in Tizen. Avalilable since Tizen_4.0.
333 public virtual double GetVerticalTextAlignment(string part)
335 return Interop.Elementary.elm_layout_text_valign_get(RealHandle, part);
339 /// The callback of Realized Event
341 protected override void OnRealized()
344 _languageChanged = new SmartEvent(this, this.RealHandle, "language,changed");
345 _languageChanged.On += (s, e) =>
347 LanguageChanged?.Invoke(this, EventArgs.Empty);
350 _themeChanged = new SmartEvent(this, this.RealHandle, "theme,changed");
351 _themeChanged.On += (s, e) =>
353 ThemeChanged?.Invoke(this, EventArgs.Empty);
358 /// Sets the content at a part of a given container widget.
360 /// <param name="parent">The parent is a given container which will be attached by Layout as a child. It's <see cref="EvasObject"/> type.</param>
361 /// <returns>The new object, otherwise null if it cannot be created</returns>
362 protected override IntPtr CreateHandle(EvasObject parent)
364 return Interop.Elementary.elm_layout_add(parent.Handle);