Merge remote-tracking branch 'uix-tts-engine/tizen'
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Label.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18 namespace ElmSharp
19 {
20     /// <summary>
21     /// Label is a widget to display text, with simple html-like markup.
22     /// Inherits Layout
23     /// </summary>
24     public class Label : Layout
25     {
26         SmartEvent _slideCompleted;
27
28         /// <summary>
29         /// Creates and initializes a new instance of Label class.
30         /// </summary>
31         /// <param name="parent">The parent is a given container which will be attached by Label as a child. It's <see cref="EvasObject"/> type.</param>
32         public Label(EvasObject parent) : base(parent)
33         {
34             _slideCompleted = new SmartEvent(this, this.RealHandle, "slide,end");
35             _slideCompleted.On += (s, e) =>
36             {
37                 SlideCompleted?.Invoke(this, EventArgs.Empty);
38             };
39         }
40
41         /// <summary>
42         /// SlideCompleted will be triggered when the slide is completed.
43         /// </summary>
44         public event EventHandler SlideCompleted;
45
46         /// <summary>
47         /// Sets or gets wrap width of the label.
48         /// </summary>
49         public int LineWrapWidth
50         {
51             get
52             {
53                 return Interop.Elementary.elm_label_wrap_width_get(RealHandle);
54             }
55             set
56             {
57                 Interop.Elementary.elm_label_wrap_width_set(RealHandle, value);
58             }
59         }
60
61         /// <summary>
62         /// Sets or gets the wrapping behavior of the label.
63         /// </summary>
64         public WrapType LineWrapType
65         {
66             get
67             {
68                 return (WrapType)Interop.Elementary.elm_label_line_wrap_get(RealHandle);
69             }
70             set
71             {
72                 Interop.Elementary.elm_label_line_wrap_set(RealHandle, (int)value);
73                 if (value != WrapType.None)
74                 {
75                     Interop.Evas.evas_object_size_hint_min_get(RealHandle, IntPtr.Zero, out int h);
76                     Interop.Evas.evas_object_size_hint_min_set(RealHandle, 0, h);
77                 }
78             }
79         }
80
81         /// <summary>
82         /// Sets or gets the slide mode of the label widget.
83         /// </summary>
84         public LabelSlideMode SlideMode
85         {
86             get
87             {
88                 return (LabelSlideMode)Interop.Elementary.elm_label_slide_mode_get(RealHandle);
89             }
90             set
91             {
92                 Interop.Elementary.elm_label_slide_mode_set(RealHandle, (int)value);
93             }
94         }
95
96         /// <summary>
97         /// Sets or gets the slide duration of the label.
98         /// </summary>
99         public double SlideDuration
100         {
101             get
102             {
103                 return Interop.Elementary.elm_label_slide_duration_get(RealHandle);
104             }
105             set
106             {
107                 Interop.Elementary.elm_label_slide_duration_set(RealHandle, value);
108             }
109         }
110
111         /// <summary>
112         /// Sets or gets the slide Speed of the label.
113         /// </summary>
114         /// <remarks>
115         /// The speed of the slide animation in px per seconds.
116         /// If you set the duration of the slide using elm_label_slide_duration_set() you cannot get the correct speed using this function until the label is actually rendered and resized.
117         /// </remarks>
118         /// <seealso cref="SlideDuration"/>
119         public double SlideSpeed
120         {
121             get
122             {
123                 return Interop.Elementary.elm_label_slide_speed_get(RealHandle);
124             }
125             set
126             {
127                 Interop.Elementary.elm_label_slide_speed_set(RealHandle, value);
128             }
129         }
130
131         /// <summary>
132         /// Sets or gets the ellipsis behavior of the label.
133         /// </summary>
134         public bool IsEllipsis
135         {
136             get
137             {
138                 return Interop.Elementary.elm_label_ellipsis_get(RealHandle);
139             }
140             set
141             {
142                 Interop.Elementary.elm_label_ellipsis_set(RealHandle, value);
143             }
144         }
145
146         /// <summary>
147         /// Sets or gets the style of the label text.
148         /// </summary>
149         /// <remarks>
150         /// APIs, elm_label_text_style_user_peek/pop/push, are internal APIs only in Tizen. Avalilable since Tizen_4.0.
151         /// </remarks>
152         /// 
153         public string TextStyle
154         {
155             get
156             {
157                 return Interop.Elementary.elm_label_text_style_user_peek(RealHandle);
158             }
159             set
160             {
161                 if (string.IsNullOrEmpty(value))
162                 {
163                     Interop.Elementary.elm_label_text_style_user_pop(RealHandle);
164                 }
165                 else
166                 {
167                     Interop.Elementary.elm_label_text_style_user_push(RealHandle, value);
168                 }
169             }
170         }
171
172         /// <summary>
173         /// Start slide effect.
174         /// </summary>
175         public void PlaySlide()
176         {
177             Interop.Elementary.elm_label_slide_go(RealHandle);
178         }
179
180         /// <summary>
181         /// Sets the content at a part of a given container widget.
182         /// </summary>
183         /// <param name="parent">EvasObject</param>
184         /// <returns>The new object, otherwise null if it cannot be created</returns>
185         protected override IntPtr CreateHandle(EvasObject parent)
186         {            
187             return Interop.Elementary.elm_label_add(parent.Handle);
188         }
189     }
190
191     /// <summary>
192     /// Enumeration for slide mode of a label widget
193     /// </summary>
194     public enum LabelSlideMode
195     {
196         /// <summary>
197         /// no slide effect
198         /// </summary>
199         None = 0,
200         /// <summary>
201         /// slide only if the label area is bigger than the text width length
202         /// </summary>
203         Auto,
204         /// <summary>
205         /// slide always
206         /// </summary>
207         Always
208     }
209 }