/* * 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 { /// /// The Box is a container used to arranges UI components in a linear order. /// public class Box : Container { private Interop.Elementary.BoxLayoutCallback _layoutCallback; /// /// Creates and initializes a new instance of the Box class. /// /// The EvasObject to which the new Box will be attached as a child. public Box(EvasObject parent) : base(parent) { } /// /// Sets or gets IsHorizontal value which describe pack direction, vertical is default. /// public bool IsHorizontal { get { return Interop.Elementary.elm_box_horizontal_get(RealHandle); } set { Interop.Elementary.elm_box_horizontal_set(RealHandle, value); } } /// /// Sets or gets whether the box to arrange its children homogeneously. /// public bool IsHomogeneous { get { return Interop.Elementary.elm_box_homogeneous_get(RealHandle); } set { Interop.Elementary.elm_box_homogeneous_set(RealHandle, value); } } /// /// Adds an object at the end of the pack list. /// /// /// Packs "content" object into the Box, placing it last in the list of children objects. /// The actual position the object will get on screen depends on the layout used. /// If no custom layout is set, it will be at the bottom or right, /// depending if the Box is vertical or horizontal, respectively. /// /// The oject be packed public void PackEnd(EvasObject content) { Interop.Elementary.elm_box_pack_end(RealHandle, content); AddChild(content); } /// /// Adds an "content" object to the beginning of the pack list. /// /// /// Pack "content" object into the Box obj, placing it first in the list of children objects. /// The actual position the object will get on screen depends on the layout used. /// If no custom layout is set, it will be at the top or left, /// depending if the Box is vertical or horizontal, respectively. /// /// The object to be packed. public void PackStart(EvasObject content) { Interop.Elementary.elm_box_pack_start(RealHandle, content); AddChild(content); } /// /// Adds an "content "object to the Box after the "after" object. /// /// /// This will add the "content" to the Box indicated after the object indicated with "after". /// If "after" is not already in the Box, results are undefined. /// After means either to the right of the "after" object or below it depending on orientation. /// /// The object will be added in Box /// The object has been added in Box public void PackAfter(EvasObject content, EvasObject after) { Interop.Elementary.elm_box_pack_after(RealHandle, content, after); AddChild(content); } /// /// Adds an "content "object to the Box before the "before" object. /// /// /// This will add the "content" to the Box indicated before the object indicated with "before". /// If "before" is not already in the Box, results are undefined. /// before means either to the left of the "before" object or below it depending on orientation. /// /// The object will be added in Box /// The object has been added in Box public void PackBefore(EvasObject content, EvasObject before) { Interop.Elementary.elm_box_pack_before(RealHandle, content, before); AddChild(content); } /// /// Remove the "content" oject from Box without deleting it. /// /// The object to unpack public void UnPack(EvasObject content) { Interop.Elementary.elm_box_unpack(RealHandle, content); RemoveChild(content); } /// /// Removes all objects from Box container. /// public void UnPackAll() { Interop.Elementary.elm_box_unpack_all(RealHandle); ClearChildren(); } /// /// Whenever anything changes that requires the Box in obj to recalculate the size and position of its elements, /// the function cb will be called to determine what the layout of the children will be. /// /// The callback function used for layout public void SetLayoutCallback(Action action) { _layoutCallback = (obj, priv, data) => { action(); }; Interop.Elementary.elm_box_layout_set(RealHandle, _layoutCallback, IntPtr.Zero, null); } /// /// Sets the color of exact part to Box's layout parent. /// /// The name of part class, it could be 'bg', 'elm.swllow.content'. /// The color value. public override void SetPartColor(string part, Color color) { Interop.Elementary.elm_object_color_class_color_set(Handle, part, color.R * color.A / 255, color.G * color.A / 255, color.B * color.A / 255, color.A); } /// /// Gets the color of exact part of Box's layout parent. /// /// The name of part class, it could be 'bg', 'elm.swllow.content'. /// public override Color GetPartColor(string part) { int r, g, b, a; Interop.Elementary.elm_object_color_class_color_get(Handle, part, out r, out g, out b, out a); return new Color((int)(r / (a / 255.0)), (int)(g / (a / 255.0)), (int)(b / (a / 255.0)), a); } /// /// Force the box to recalculate its children packing. /// If any children was added or removed, box will not calculate the values immediately rather leaving it to the next main loop iteration. /// While this is great as it would save lots of recalculation, whenever you need to get the position of a just added item you must force recalculate before doing so. /// public void Recalculate() { Interop.Elementary.elm_box_recalculate(RealHandle); } /// /// Clear the box of all children. /// Remove all the elements contained by the box, deleting the respective objects. /// public void Clear() { Interop.Elementary.elm_box_clear(RealHandle); ClearChildren(); } /// /// Sets or gets the alignment of the whole bounding box of contents. /// /// Horizontal alignment /// Vertical alignment public void SetBoxAlignment(double horizontal, double vertical) { Interop.Elementary.elm_box_align_set(RealHandle, horizontal, vertical); } /// /// Sets or gets the space(padding) between the box's elements. /// /// Horizontal padding /// vertical padding public void SetPadding(int horizontal, int vertical) { Interop.Elementary.elm_box_padding_set(RealHandle, horizontal, vertical); } protected override IntPtr CreateHandle(EvasObject parent) { IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle); Interop.Elementary.elm_layout_theme_set(handle, "layout", "background", "default"); RealHandle = Interop.Elementary.elm_box_add(handle); Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle); return handle; } } }