forked from Samsung/TizenFX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextLabel.cs
More file actions
executable file
·3922 lines (3638 loc) · 150 KB
/
TextLabel.cs
File metadata and controls
executable file
·3922 lines (3638 loc) · 150 KB
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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright(c) 2025 Samsung Electronics Co., Ltd.
*
* 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.
*
*/
extern alias TizenSystemSettings;
using TizenSystemSettings.Tizen.System;
using System;
using System.Globalization;
using System.ComponentModel;
using Tizen.NUI.Text;
using Tizen.NUI.Binding;
namespace Tizen.NUI.BaseComponents
{
/// <summary>
/// A control which renders a short text string.<br />
/// Text labels are lightweight, non-editable, and do not respond to the user input.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
public partial class TextLabel : View, IPropertyProvider
{
internal class TextLabelLayout : LayoutItem
{
private float lastWidth = 0;
private float lastHeight = 0;
public void OnAsyncTextRendered(object sender, AsyncTextRenderedEventArgs e)
{
SetMeasuredDimensions(new LayoutLength(e.Width), new LayoutLength(e.Height));
RequestLayout();
}
protected override void OnMeasure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
{
// Padding will be automatically applied by DALi TextLabel.
float totalWidth = widthMeasureSpec.Size.AsDecimal();
float totalHeight = heightMeasureSpec.Size.AsDecimal();
if (Owner is TextLabel label && label.RenderMode == TextRenderMode.AsyncAuto)
{
label.AddAsyncTextRendered();
if (label.NeedRequestAsyncRender || (lastWidth != totalWidth) || (lastHeight != totalHeight))
{
lastWidth = totalWidth;
lastHeight = totalHeight;
if (widthMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly)
{
if (heightMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly)
{
label.RequestAsyncRenderWithFixedSize(totalWidth, totalHeight);
}
else
{
if (heightMeasureSpec.Mode == MeasureSpecification.ModeType.Unspecified)
{
totalHeight = float.PositiveInfinity;
}
label.RequestAsyncRenderWithFixedWidth(totalWidth, totalHeight);
}
}
else
{
if (heightMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly)
{
label.RequestAsyncRenderWithFixedHeight(totalWidth, totalHeight);
}
else
{
if (heightMeasureSpec.Mode == MeasureSpecification.ModeType.Unspecified)
{
totalHeight = float.PositiveInfinity;
}
label.RequestAsyncRenderWithConstraint(totalWidth, totalHeight);
}
}
float width = label.SizeWidth;
float height = label.SizeHeight;
SetMeasuredDimensions(new LayoutLength(width), new LayoutLength(height));
}
}
else
{
if (widthMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly)
{
if (heightMeasureSpec.Mode != MeasureSpecification.ModeType.Exactly)
{
var padding = Owner.Padding;
totalHeight = Owner.GetHeightForWidth(totalWidth - (padding.Start + padding.End));
heightMeasureSpec = new MeasureSpecification(new LayoutLength(totalHeight), MeasureSpecification.ModeType.Exactly);
}
}
else
{
var minWidth = Owner.GetMinimumWidth();
var minHeight = Owner.GetMinimumHeight();
var maxWidth = Owner.GetMaximumWidth();
var maxHeight = Owner.GetMaximumHeight();
var naturalSize = Owner.GetNaturalSize();
if (heightMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly)
{
// GetWidthForHeight is not implemented.
float width = naturalSize != null ? naturalSize.Width : 0;
// Since priority of MinimumSize is higher than MaximumSize in DALi, here follows it.
totalWidth = Math.Max(Math.Min(width, maxWidth < 0 ? Int32.MaxValue : maxWidth), minWidth);
widthMeasureSpec = new MeasureSpecification(new LayoutLength(totalWidth), MeasureSpecification.ModeType.Exactly);
}
else
{
float width = naturalSize != null ? naturalSize.Width : 0;
// Since priority of MinimumSize is higher than MaximumSize in DALi, here follows it.
totalWidth = Math.Max(Math.Min(width, maxWidth < 0 ? Int32.MaxValue : maxWidth), minWidth);
var padding = Owner.Padding;
float height = Owner.GetHeightForWidth(totalWidth - (padding.Start + padding.End));
totalHeight = Math.Max(Math.Min(height, maxHeight < 0 ? Int32.MaxValue : maxHeight), minHeight);
heightMeasureSpec = new MeasureSpecification(new LayoutLength(totalHeight), MeasureSpecification.ModeType.Exactly);
widthMeasureSpec = new MeasureSpecification(new LayoutLength(totalWidth), MeasureSpecification.ModeType.Exactly);
}
}
MeasuredSize.StateType childWidthState = MeasuredSize.StateType.MeasuredSizeOK;
MeasuredSize.StateType childHeightState = MeasuredSize.StateType.MeasuredSizeOK;
SetMeasuredDimensions(ResolveSizeAndState(new LayoutLength(totalWidth), widthMeasureSpec, childWidthState),
ResolveSizeAndState(new LayoutLength(totalHeight), heightMeasureSpec, childHeightState));
}
}
/// <inheritdoc/>
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool IsPaddingHandledByNative()
{
return true;
}
}
static TextLabel()
{
if (NUIApplication.IsUsingXaml)
{
TranslatableTextProperty = BindableProperty.Create(nameof(TranslatableText), typeof(string), typeof(TextLabel), string.Empty,
propertyChanged: SetInternalTranslatableTextProperty, defaultValueCreator: GetInternalTranslatableTextProperty);
TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(TextLabel), string.Empty,
propertyChanged: SetInternalTextProperty, defaultValueCreator: GetInternalTextProperty);
FontFamilyProperty = BindableProperty.Create(nameof(FontFamily), typeof(string), typeof(TextLabel), string.Empty,
propertyChanged: SetInternalFontFamilyProperty, defaultValueCreator: GetInternalFontFamilyProperty);
FontStyleProperty = BindableProperty.Create(nameof(FontStyle), typeof(PropertyMap), typeof(TextLabel), null,
propertyChanged: SetInternalFontStyleProperty, defaultValueCreator: GetInternalFontStyleProperty);
PointSizeProperty = BindableProperty.Create(nameof(PointSize), typeof(float), typeof(TextLabel), default(float),
propertyChanged: SetInternalPointSizeProperty, defaultValueCreator: GetInternalPointSizeProperty);
MultiLineProperty = BindableProperty.Create(nameof(MultiLine), typeof(bool), typeof(TextLabel), false,
propertyChanged: SetInternalMultiLineProperty, defaultValueCreator: GetInternalMultiLineProperty);
HorizontalAlignmentProperty = BindableProperty.Create(nameof(HorizontalAlignment), typeof(HorizontalAlignment), typeof(TextLabel), HorizontalAlignment.Begin,
propertyChanged: SetInternalHorizontalAlignmentProperty, defaultValueCreator: GetInternalHorizontalAlignmentProperty);
VerticalAlignmentProperty = BindableProperty.Create(nameof(VerticalAlignment), typeof(VerticalAlignment), typeof(TextLabel), VerticalAlignment.Bottom,
propertyChanged: SetInternalVerticalAlignmentProperty, defaultValueCreator: GetInternalVerticalAlignmentProperty);
TextColorProperty = BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(TextLabel), null,
propertyChanged: SetInternalTextColorProperty, defaultValueCreator: GetInternalTextColorProperty);
AnchorColorProperty = BindableProperty.Create(nameof(TextLabel.AnchorColor), typeof(Color), typeof(TextLabel), null,
propertyChanged: SetInternalAnchorColorProperty, defaultValueCreator: GetInternalAnchorColorProperty);
AnchorClickedColorProperty = BindableProperty.Create(nameof(TextLabel.AnchorClickedColor), typeof(Color), typeof(TextLabel), null,
propertyChanged: SetInternalAnchorClickedColorProperty, defaultValueCreator: GetInternalAnchorClickedColorProperty);
RemoveFrontInsetProperty = BindableProperty.Create(nameof(RemoveFrontInset), typeof(bool), typeof(TextLabel), false,
propertyChanged: SetInternalRemoveFrontInsetProperty, defaultValueCreator: GetInternalRemoveFrontInsetProperty);
RemoveBackInsetProperty = BindableProperty.Create(nameof(RemoveBackInset), typeof(bool), typeof(TextLabel), false,
propertyChanged: SetInternalRemoveBackInsetProperty, defaultValueCreator: GetInternalRemoveBackInsetProperty);
EnableMarkupProperty = BindableProperty.Create(nameof(EnableMarkup), typeof(bool), typeof(TextLabel), false,
propertyChanged: SetInternalEnableMarkupProperty, defaultValueCreator: GetInternalEnableMarkupProperty);
EnableAutoScrollProperty = BindableProperty.Create(nameof(EnableAutoScroll), typeof(bool), typeof(TextLabel), false,
propertyChanged: SetInternalEnableAutoScrollProperty, defaultValueCreator: GetInternalEnableAutoScrollProperty);
AutoScrollSpeedProperty = BindableProperty.Create(nameof(AutoScrollSpeed), typeof(int), typeof(TextLabel), default(int),
propertyChanged: SetInternalAutoScrollSpeedProperty, defaultValueCreator: GetInternalAutoScrollSpeedProperty);
AutoScrollLoopCountProperty = BindableProperty.Create(nameof(AutoScrollLoopCount), typeof(int), typeof(TextLabel), default(int),
propertyChanged: SetInternalAutoScrollLoopCountProperty, defaultValueCreator: GetInternalAutoScrollLoopCountProperty);
AutoScrollGapProperty = BindableProperty.Create(nameof(AutoScrollGap), typeof(float), typeof(TextLabel), default(float),
propertyChanged: SetInternalAutoScrollGapProperty, defaultValueCreator: GetInternalAutoScrollGapProperty);
LineSpacingProperty = BindableProperty.Create(nameof(LineSpacing), typeof(float), typeof(TextLabel), default(float),
propertyChanged: SetInternalLineSpacingProperty, defaultValueCreator: GetInternalLineSpacingProperty);
RelativeLineHeightProperty = BindableProperty.Create(nameof(RelativeLineHeight), typeof(float), typeof(TextLabel), default(float),
propertyChanged: SetInternalRelativeLineHeightProperty, defaultValueCreator: GetInternalRelativeLineHeightProperty);
UnderlineProperty = BindableProperty.Create(nameof(Underline), typeof(PropertyMap), typeof(TextLabel), null,
propertyChanged: SetInternalUnderlineProperty, defaultValueCreator: GetInternalUnderlineProperty);
ShadowProperty = BindableProperty.Create(nameof(Shadow), typeof(PropertyMap), typeof(TextLabel), null,
propertyChanged: SetInternalShadowProperty, defaultValueCreator: GetInternalShadowProperty);
TextShadowProperty = BindableProperty.Create(nameof(TextShadow), typeof(TextShadow), typeof(TextLabel), null,
propertyChanged: SetInternalTextShadowProperty, defaultValueCreator: GetInternalTextShadowProperty);
EmbossProperty = BindableProperty.Create(nameof(Emboss), typeof(string), typeof(TextLabel), string.Empty,
propertyChanged: SetInternalEmbossProperty, defaultValueCreator: GetInternalEmbossProperty);
OutlineProperty = BindableProperty.Create(nameof(Outline), typeof(PropertyMap), typeof(TextLabel), null,
propertyChanged: SetInternalOutlineProperty, defaultValueCreator: GetInternalOutlineProperty);
PixelSizeProperty = BindableProperty.Create(nameof(PixelSize), typeof(float), typeof(TextLabel), default(float),
propertyChanged: SetInternalPixelSizeProperty, defaultValueCreator: GetInternalPixelSizeProperty);
EllipsisProperty = BindableProperty.Create(nameof(Ellipsis), typeof(bool), typeof(TextLabel), false,
propertyChanged: SetInternalEllipsisProperty, defaultValueCreator: GetInternalEllipsisProperty);
EllipsisPositionProperty = BindableProperty.Create(nameof(EllipsisPosition), typeof(EllipsisPosition), typeof(TextLabel), EllipsisPosition.End,
propertyChanged: SetInternalEllipsisPositionProperty, defaultValueCreator: GetInternalEllipsisPositionProperty);
AutoScrollLoopDelayProperty = BindableProperty.Create(nameof(AutoScrollLoopDelay), typeof(float), typeof(TextLabel), default(float),
propertyChanged: SetInternalAutoScrollLoopDelayProperty, defaultValueCreator: GetInternalAutoScrollLoopDelayProperty);
AutoScrollStopModeProperty = BindableProperty.Create(nameof(AutoScrollStopMode), typeof(AutoScrollStopMode), typeof(TextLabel), AutoScrollStopMode.FinishLoop,
propertyChanged: SetInternalAutoScrollStopModeProperty, defaultValueCreator: GetInternalAutoScrollStopModeProperty);
LineWrapModeProperty = BindableProperty.Create(nameof(LineWrapMode), typeof(LineWrapMode), typeof(TextLabel), LineWrapMode.Word,
propertyChanged: SetInternalLineWrapModeProperty, defaultValueCreator: GetInternalLineWrapModeProperty);
VerticalLineAlignmentProperty = BindableProperty.Create(nameof(VerticalLineAlignment), typeof(VerticalLineAlignment), typeof(TextLabel), VerticalLineAlignment.Bottom,
propertyChanged: SetInternalVerticalLineAlignmentProperty, defaultValueCreator: GetInternalVerticalLineAlignmentProperty);
MatchSystemLanguageDirectionProperty = BindableProperty.Create(nameof(MatchSystemLanguageDirection), typeof(bool), typeof(TextLabel), false,
propertyChanged: SetInternalMatchSystemLanguageDirectionProperty, defaultValueCreator: GetInternalMatchSystemLanguageDirectionProperty);
CharacterSpacingProperty = BindableProperty.Create(nameof(CharacterSpacing), typeof(float), typeof(TextLabel), default(float),
propertyChanged: SetInternalCharacterSpacingProperty, defaultValueCreator: GetInternalCharacterSpacingProperty);
TextFitProperty = BindableProperty.Create(nameof(TextFit), typeof(PropertyMap), typeof(TextLabel), null,
propertyChanged: SetInternalTextFitProperty, defaultValueCreator: GetInternalTextFitProperty);
MinLineSizeProperty = BindableProperty.Create(nameof(MinLineSize), typeof(float), typeof(TextLabel), default(float),
propertyChanged: SetInternalMinLineSizeProperty, defaultValueCreator: GetInternalMinLineSizeProperty);
FontSizeScaleProperty = BindableProperty.Create(nameof(FontSizeScale), typeof(float), typeof(TextLabel), default(float),
propertyChanged: SetInternalFontSizeScaleProperty, defaultValueCreator: GetInternalFontSizeScaleProperty);
EnableFontSizeScaleProperty = BindableProperty.Create(nameof(EnableFontSizeScale), typeof(bool), typeof(TextLabel), default(bool),
propertyChanged: SetInternalEnableFontSizeScaleProperty, defaultValueCreator: GetInternalEnableFontSizeScaleProperty);
ShadowOffsetProperty = BindableProperty.Create(nameof(ShadowOffset), typeof(Tizen.NUI.Vector2), typeof(TextLabel), null,
propertyChanged: SetInternalShadowOffsetProperty, defaultValueCreator: GetInternalShadowOffsetProperty);
ShadowColorProperty = BindableProperty.Create(nameof(ShadowColor), typeof(Tizen.NUI.Vector4), typeof(TextLabel), null,
propertyChanged: SetInternalShadowColorProperty, defaultValueCreator: GetInternalShadowColorProperty);
UnderlineEnabledProperty = BindableProperty.Create(nameof(UnderlineEnabled), typeof(bool), typeof(TextLabel), false,
propertyChanged: SetInternalUnderlineEnabledProperty, defaultValueCreator: GetInternalUnderlineEnabledProperty);
UnderlineColorProperty = BindableProperty.Create(nameof(UnderlineColor), typeof(Tizen.NUI.Vector4), typeof(TextLabel), null,
propertyChanged: SetInternalUnderlineColorProperty, defaultValueCreator: GetInternalUnderlineColorProperty);
UnderlineHeightProperty = BindableProperty.Create(nameof(UnderlineHeight), typeof(float), typeof(TextLabel), 0.0f,
propertyChanged: SetInternalUnderlineHeightProperty, defaultValueCreator: GetInternalUnderlineHeightProperty);
CutoutProperty = BindableProperty.Create(nameof(Cutout), typeof(bool), typeof(TextLabel), false,
propertyChanged: SetInternalCutoutProperty, defaultValueCreator: GetInternalCutoutProperty);
}
}
static internal new void Preload()
{
// Do not call View.Preload(), since we already call it
Property.Preload();
// Do nothing. Just call for load static values.
}
static private string defaultStyleName = "Tizen.NUI.BaseComponents.TextLabel";
static private string defaultFontFamily = "BreezeSans";
private string textLabelSid;
private TextLabelSelectorData selectorData;
private string fontFamily = defaultFontFamily;
private float fontSizeScale = 1.0f;
private bool textIsEmpty = true;
private bool hasSystemLanguageChanged;
private bool hasSystemFontSizeChanged;
private bool hasSystemFontTypeChanged;
private bool hasAsyncTextRendered;
private Color internalTextColor;
private Color internalAnchorColor;
private Color internalAnchorClickedColor;
/// <summary>
/// Creates the TextLabel control.
/// </summary>
/// <since_tizen> 3 </since_tizen>
public TextLabel() : this(Interop.TextLabel.New(ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
/// This will be public opened after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
[EditorBrowsable(EditorBrowsableState.Never)]
public TextLabel(TextLabelStyle viewStyle) : this(Interop.TextLabel.New(ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true, viewStyle)
{
}
/// <summary>
/// Creates the TextLabel with setting the status of shown or hidden.
/// </summary>
/// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
/// This will be public opened after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
[EditorBrowsable(EditorBrowsableState.Never)]
public TextLabel(bool shown) : this(Interop.TextLabel.New(ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
SetVisible(shown);
}
/// <summary>
/// Creates the TextLabel control.
/// </summary>
/// <param name="text">The text to display</param>
/// <since_tizen> 3 </since_tizen>
public TextLabel(string text) : this(Interop.TextLabel.New(text, ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
textIsEmpty = string.IsNullOrEmpty(text);
}
/// <summary>
/// Creates the TextLabel with setting the status of shown or hidden.
/// </summary>
/// <param name="text">The text to display</param>
/// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
/// This will be public opened after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
[EditorBrowsable(EditorBrowsableState.Never)]
public TextLabel(string text, bool shown) : this(Interop.TextLabel.New(text, ThemeManager.GetStyle(defaultStyleName) == null ? false : true), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
textIsEmpty = string.IsNullOrEmpty(text);
SetVisible(shown);
}
internal TextLabel(global::System.IntPtr cPtr, bool cMemoryOwn, ViewStyle viewStyle, bool shown = true) : base(cPtr, cMemoryOwn, viewStyle)
{
if (!shown)
{
SetVisible(false);
}
}
internal TextLabel(global::System.IntPtr cPtr, bool cMemoryOwn, bool shown = true) : base(cPtr, cMemoryOwn, null)
{
if (!shown)
{
SetVisible(false);
}
}
private bool HasStyle()
{
return ThemeManager.GetStyle(this.GetType()) == null ? false : true;
}
// IPropertyProvider
/// <summary>
/// Gets a string property by name.
/// </summary>
/// <param name="propertyName">The name of the property to retrieve.</param>
/// <returns>The string value of the property, or null if not found.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public string GetStringProperty(string propertyName) => propertyName switch
{
nameof(TranslatableText) => TranslatableText,
_ => null
};
/// <summary>
/// Requests asynchronous rendering of text with a fixed size.
/// </summary>
/// <param name="width">The width of text to render.</param>
/// <param name="height">The height of text to render.</param>
/// <remarks>
/// Only works when AsyncAuto and AsyncManual.<br />
/// If another request occurs before the requested render is completed, the previous request will be canceled.<br />
/// In AsyncAuto, the manual request is not canceled by an auto request caused by OnRealyout.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public void RequestAsyncRenderWithFixedSize(float width, float height)
{
Interop.TextLabel.RequestAsyncRenderWithFixedSize(SwigCPtr, width, height);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
/// <summary>
/// Requests asynchronous text rendering with a fixed width.
/// </summary>
/// <param name="width">The width of text to render.</param>
/// <param name="heightConstraint">The maximum available height of text to render.</param>
/// <remarks>
/// Only works when AsyncAuto and AsyncManual.<br />
/// The height is determined by the content of the text when rendered with the given width.<br />
/// The result will be the same as the height returned by GetHeightForWidth.<br />
/// If the heightConstraint is given, the maximum height will be the heightConstraint.<br />
/// If another request occurs before the requested render is completed, the previous request will be canceled.<br />
/// In AsyncAuto, the manual request is not canceled by an auto request caused by OnRealyout.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public void RequestAsyncRenderWithFixedWidth(float width, float heightConstraint = float.PositiveInfinity)
{
Interop.TextLabel.RequestAsyncRenderWithFixedWidth(SwigCPtr, width, heightConstraint);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
/// <summary>
/// Requests asynchronous text rendering with a fixed height.
/// </summary>
/// <param name="widthConstraint">The maximum available width of text to render.</param>
/// <param name="height">The height of text to render.</param>
/// <remarks>
/// Only works when AsyncAuto and AsyncManual.<br />
/// The width is determined by the content of the text.<br />
/// The maximum width will be the widthConstraint.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public void RequestAsyncRenderWithFixedHeight(float widthConstraint, float height)
{
Interop.TextLabel.RequestAsyncRenderWithFixedHeight(SwigCPtr, widthConstraint, height);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
/// <summary>
/// Requests asynchronous rendering with the maximum available width using the given widthConstraint.
/// </summary>
/// <param name="widthConstraint">The maximum available width of text to render.</param>
/// <param name="heightConstraint">The maximum available height of text to render.</param>
/// <remarks>
/// Only works when AsyncAuto and AsyncManual.<br />
/// If the width of the text content is smaller than the widthConstraint, the width will be determined by the width of the text.<br />
/// If the width of the text content is larger than the widthConstraint, the width will be determined by the widthConstraint.<br />
/// The height is determined by the content of the text when rendered with the given width.<br />
/// In this case, the result will be the same as the height returned by GetHeightForWidth.<br />
/// If the heightConstraint is given, the maximum height will be the heightConstraint.<br />
/// If another request occurs before the requested render is completed, the previous request will be canceled.<br />
/// In AsyncAuto, the manual request is not canceled by an auto request caused by OnRealyout.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public void RequestAsyncRenderWithConstraint(float widthConstraint, float heightConstraint = float.PositiveInfinity)
{
Interop.TextLabel.RequestAsyncRenderWithConstraint(SwigCPtr, widthConstraint, heightConstraint);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
/// <summary>
/// Requests asynchronous text natural size computation.
/// </summary>
/// <remarks>
/// If another request occurs before the requested natural size computation is completed, the previous request will be canceled.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public void RequestAsyncNaturalSize()
{
Interop.TextLabel.RequestAsyncNaturalSize(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
/// <summary>
/// Requests asynchronous computation of the height of the text based on the given width.
/// </summary>
/// <param name="width">The width of text to compute.</param>
/// <remarks>
/// If another request occurs before the requested height for width computation is completed, the previous request will be canceled.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public void RequestAsyncHeightForWidth(float width)
{
Interop.TextLabel.RequestAsyncHeightForWidth(SwigCPtr, width);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
/// <summary>
/// The TranslatableText property.<br />
/// The text can set the SID value.<br />
/// </summary>
/// <exception cref='ArgumentNullException'>
/// ResourceManager about multilingual is null.
/// </exception>
/// <since_tizen> 4 </since_tizen>
public string TranslatableText
{
get
{
if (NUIApplication.IsUsingXaml)
{
return (string)GetValue(TranslatableTextProperty);
}
else
{
return GetInternalTranslatableText();
}
}
set
{
if (NUIApplication.IsUsingXaml)
{
SetValue(TranslatableTextProperty, value);
}
else
{
SetInternalTranslatableText(value);
}
}
}
private void SetInternalTranslatableText(string text)
{
selectorData?.TranslatableText?.Reset(this);
SetTranslatableText(text);
}
private string GetInternalTranslatableText()
{
return translatableText;
}
private string translatableText
{
get
{
return textLabelSid;
}
set
{
if (NUIApplication.MultilingualResourceManager == null)
{
throw new ArgumentNullException(null, "ResourceManager about multilingual is null");
}
string translatableText = null;
textLabelSid = value;
translatableText = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(SystemLocaleLanguageChangedManager.LocaleLanguage.Replace("_", "-")));
if (translatableText != null)
{
Text = translatableText;
AddSystemSettingsLocaleLanguageChanged();
}
else
{
Text = "";
RemoveSystemSettingsLocaleLanguageChanged();
}
NotifyPropertyChanged();
}
}
/// <summary>
/// The Text property.<br />
/// The text to display in the UTF-8 format.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
public string Text
{
get
{
if (NUIApplication.IsUsingXaml)
{
return (string)GetValue(TextProperty);
}
else
{
return GetInternalText();
}
}
set
{
if (NUIApplication.IsUsingXaml)
{
SetValue(TextProperty, value);
}
else
{
SetInternalText(value);
}
NotifyPropertyChanged();
}
}
private void SetInternalText(string text)
{
selectorData?.Text?.Reset(this);
SetText(text);
}
private string GetInternalText()
{
// Do not try to get string if we know that previous text was empty.
return textIsEmpty ? "" : Object.InternalGetPropertyString(SwigCPtr, Property.TEXT);
}
/// <summary>
/// The FontFamily property.<br />
/// The requested font family to use.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
public string FontFamily
{
get
{
if (NUIApplication.IsUsingXaml)
{
return (string)GetValue(FontFamilyProperty);
}
else
{
return InternalFontFamily;
}
}
set
{
if (NUIApplication.IsUsingXaml)
{
SetValue(FontFamilyProperty, value);
}
else
{
selectorData?.FontFamily?.Reset(this);
SetFontFamily(value);
}
NotifyPropertyChanged();
}
}
private string InternalFontFamily
{
get
{
if (HasStyle())
return fontFamily;
else
return Object.InternalGetPropertyString(this.SwigCPtr, TextLabel.Property.FontFamily);
}
set
{
if (string.Equals(fontFamily, value)) return;
fontFamily = value;
string newFontFamily;
if (fontFamily == Tizen.NUI.FontFamily.UseSystemSetting)
{
newFontFamily = SystemFontTypeChangedManager.FontType;
AddSystemSettingsFontTypeChanged();
}
else
{
newFontFamily = fontFamily;
RemoveSystemSettingsFontTypeChanged();
}
SetInternalFontFamily(newFontFamily);
}
}
private void SetInternalFontFamily(string fontFamily)
{
Object.InternalSetPropertyString(this.SwigCPtr, TextLabel.Property.FontFamily, (string)fontFamily);
RequestLayout();
}
/// <summary>
/// The FontStyle property.<br />
/// The requested font style to use.<br />
/// The fontStyle map contains the following keys :<br />
/// <list type="table">
/// <item><term>width (string)</term><description>The width key defines occupied by each glyph. (values: ultraCondensed, extraCondensed, condensed, semiCondensed, normal, semiExpanded, expanded, extraExpanded, ultraExpanded)</description></item>
/// <item><term>weight (string)</term><description>The weight key defines the thickness or darkness of the glyphs. (values: thin, ultraLight, extraLight, light, demiLight, semiLight, book, normal, regular, medium, demiBold, semiBold, bold, ultraBold, extraBold, black, heavy, extraBlack)</description></item>
/// <item><term>slant (string)</term><description>The slant key defines whether to use italics. (values: normal, roman, italic, oblique)</description></item>
/// </list>
/// </summary>
/// <since_tizen> 3 </since_tizen>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1721: Property names should not match get methods")]
public PropertyMap FontStyle
{
get
{
if (NUIApplication.IsUsingXaml)
{
return (PropertyMap)GetValue(FontStyleProperty);
}
else
{
return GetInternalFontStyle();
}
}
set
{
if (NUIApplication.IsUsingXaml)
{
SetValue(FontStyleProperty, value);
}
else
{
SetInternalFontStyle(value);
}
NotifyPropertyChanged();
}
}
private void SetInternalFontStyle(PropertyMap map)
{
if (map != null)
{
using var pv = new PropertyValue(map);
Object.SetProperty(SwigCPtr, Property.FontStyle, pv);
RequestLayout();
}
}
private PropertyMap GetInternalFontStyle()
{
PropertyMap temp = new PropertyMap();
using (var prop = Object.GetProperty(SwigCPtr, Property.FontStyle))
{
prop.Get(temp);
}
return temp;
}
/// <summary>
/// Set FontStyle to TextLabel. <br />
/// </summary>
/// <param name="fontStyle">The FontStyle</param>
/// <remarks>
/// SetFontStyle specifies the requested font style through <see cref="Tizen.NUI.Text.FontStyle"/>. <br />
/// </remarks>
/// <example>
/// The following example demonstrates how to use the SetFontStyle method.
/// <code>
/// var fontStyle = new Tizen.NUI.Text.FontStyle();
/// fontStyle.Width = FontWidthType.Expanded;
/// fontStyle.Weight = FontWeightType.Bold;
/// fontStyle.Slant = FontSlantType.Italic;
/// label.SetFontStyle(fontStyle);
/// </code>
/// </example>
[EditorBrowsable(EditorBrowsableState.Never)]
public void SetFontStyle(FontStyle fontStyle)
{
using (var fontStyleMap = TextMapHelper.GetFontStyleMap(fontStyle))
{
if (NUIApplication.IsUsingXaml)
{
SetValue(FontStyleProperty, fontStyleMap);
}
else
{
SetInternalFontStyle(fontStyleMap);
}
}
}
/// <summary>
/// Get FontStyle from TextLabel. <br />
/// </summary>
/// <returns>The FontStyle</returns>
/// <remarks>
/// <see cref="Tizen.NUI.Text.FontStyle"/>
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public FontStyle GetFontStyle()
{
FontStyle fontStyle;
if (NUIApplication.IsUsingXaml)
{
var fontStyleMap = (PropertyMap)GetValue(FontStyleProperty);
fontStyle = TextMapHelper.GetFontStyleStruct(fontStyleMap);
}
else
{
using var fontStyleMap = GetInternalFontStyle();
fontStyle = TextMapHelper.GetFontStyleStruct(fontStyleMap);
}
return fontStyle;
}
/// <summary>
/// The PointSize property.<br />
/// The size of font in points.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
[Binding.TypeConverter(typeof(PointSizeTypeConverter))]
public float PointSize
{
get
{
if (NUIApplication.IsUsingXaml)
{
return (float)GetValue(PointSizeProperty);
}
else
{
return GetInternalPointSize();
}
}
set
{
if (NUIApplication.IsUsingXaml)
{
SetValue(PointSizeProperty, value);
}
else
{
SetInternalPointSize(value);
}
NotifyPropertyChanged();
}
}
private void SetInternalPointSize(float newValue)
{
selectorData?.PointSize?.Reset(this);
SetPointSize(newValue);
}
private float GetInternalPointSize()
{
return Object.InternalGetPropertyFloat(SwigCPtr, Property.PointSize);
}
/// <summary>
/// The MultiLine property.<br />
/// The single-line or multi-line layout option.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
public bool MultiLine
{
get
{
if (NUIApplication.IsUsingXaml)
{
return (bool)GetValue(MultiLineProperty);
}
else
{
return GetInternalMultiLine();
}
}
set
{
if (NUIApplication.IsUsingXaml)
{
SetValue(MultiLineProperty, value);
}
else
{
SetInternalMultiLine(value);
}
NotifyPropertyChanged();
}
}
private void SetInternalMultiLine(bool newValue)
{
Object.InternalSetPropertyBool(SwigCPtr, Property.MultiLine, newValue);
RequestLayout();
}
private bool GetInternalMultiLine()
{
return Object.InternalGetPropertyBool(SwigCPtr, Property.MultiLine);
}
/// <summary>
/// The HorizontalAlignment property.<br />
/// The line horizontal alignment.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
public HorizontalAlignment HorizontalAlignment
{
get
{
if (NUIApplication.IsUsingXaml)
{
return (HorizontalAlignment)GetValue(HorizontalAlignmentProperty);
}
else
{
return GetInternalHorizontalAlignment();
}
}
set
{
if (NUIApplication.IsUsingXaml)
{
SetValue(HorizontalAlignmentProperty, value);
}
else
{
SetInternalHorizontalAlignment(value);
}
NotifyPropertyChanged();
}
}
private void SetInternalHorizontalAlignment(HorizontalAlignment newValue)
{
Object.InternalSetPropertyInt(SwigCPtr, Property.HorizontalAlignment, (int)newValue);
}
private HorizontalAlignment GetInternalHorizontalAlignment()
{
string temp = Object.InternalGetPropertyString(SwigCPtr, Property.HorizontalAlignment);
if (System.String.IsNullOrEmpty(temp))
{
return HorizontalAlignment.Begin; // Return default value.
}
if (temp.Equals("BEGIN", StringComparison.Ordinal))
{
return HorizontalAlignment.Begin;
}
else if (temp.Equals("CENTER", StringComparison.Ordinal))
{
return HorizontalAlignment.Center;
}
else
{
return HorizontalAlignment.End;
}
}
/// <summary>
/// The VerticalAlignment property.<br />
/// The line vertical alignment.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
public VerticalAlignment VerticalAlignment
{
get
{
if (NUIApplication.IsUsingXaml)
{
return (VerticalAlignment)GetValue(VerticalAlignmentProperty);
}
else
{
return GetInternalVerticalAlignment();
}
}
set
{
if (NUIApplication.IsUsingXaml)
{
SetValue(VerticalAlignmentProperty, value);
}
else
{
SetInternalVerticalAlignment(value);
}
NotifyPropertyChanged();
}
}
private void SetInternalVerticalAlignment(VerticalAlignment newValue)
{
Object.InternalSetPropertyInt(SwigCPtr, Property.VerticalAlignment, (int)newValue);
}
private VerticalAlignment GetInternalVerticalAlignment()
{
string temp = Object.InternalGetPropertyString(SwigCPtr, Property.VerticalAlignment);
if (System.String.IsNullOrEmpty(temp))
{
return VerticalAlignment.Top; // Return default value.
}