summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Tizen/Native/TextHelper.cs
blob: 5109dad4866a767092502f0aacb1b466b7a28b29 (plain)
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
using System;
using ElmSharp;
using ESize = ElmSharp.Size;
using ELayout = ElmSharp.Layout;

namespace Xamarin.Forms.Platform.Tizen.Native
{
	/// <summary>
	/// The Text Helper contains functions that assist in working with text-able objects.
	/// </summary>
	internal static class TextHelper
	{
		/// <summary>
		/// Gets the size of raw text block.
		/// </summary>
		/// <param name="textable">The <see cref="EvasObject"/> with text part.</param>
		/// <returns>Returns the size of raw text block.</returns>
		public static ESize GetRawTextBlockSize(EvasObject textable)
		{
			return GetElmTextPart(textable).TextBlockNativeSize;
		}

		/// <summary>
		/// Gets the size of formatted text block.
		/// </summary>
		/// <param name="textable">The <see cref="ElmSharp.EvasObject"/> with text part.</param>
		/// <returns>Returns the size of formatted text block.</returns>
		public static ESize GetFormattedTextBlockSize(EvasObject textable)
		{
			return GetElmTextPart(textable).TextBlockFormattedSize;
		}

		/// <summary>
		/// Gets the ELM text part of evas object.
		/// </summary>
		/// <param name="textable">The <see cref="ElmSharp.EvasObject"/> with text part.</param>
		/// <exception cref="ArgumentException">Throws exception when parameter <param name="textable"> isn't text-able object or doesn't have ELM text part.</exception>
		/// <returns>Requested <see cref="ElmSharp.EdjeTextPartObject"/> instance.</returns>
		static EdjeTextPartObject GetElmTextPart(EvasObject textable)
		{
			ELayout widget = textable as ELayout;
			if (widget == null)
			{
				throw new ArgumentException("textable should be ElmSharp.Layout", "textable");
			}
			EdjeTextPartObject textPart = widget.EdjeObject["elm.text"];
			if (textPart == null)
			{
				throw new ArgumentException("There is no elm.text part", "textable");
			}
			return textPart;
		}
	}
}