summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Tizen/Cells/TextCellRenderer.cs
blob: e46783e9440c1d78a0745a350cbb153d7b81c26d (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using ElmSharp;
using System.Collections.Generic;

namespace Xamarin.Forms.Platform.Tizen
{
	public class TextCellRenderer : CellRenderer
	{
		// TextCell.Detail property is not supported on TV profile due to UX limitation.
		public TextCellRenderer() : this( Device.Idiom == TargetIdiom.Phone ? "double_label" : "default") { }

		protected TextCellRenderer(string style) : base(style)
		{
			MainPart = "elm.text";
			DetailPart = "elm.text.sub";
		}

		protected string MainPart { get; set; }
		protected string DetailPart { get; set; }

		protected override Span OnGetText(Cell cell, string part)
		{
			var textCell = (TextCell)cell;
			if (part == MainPart)
			{
				return OnMainText(textCell);
			}
			if (part == DetailPart)
			{
				return OnDetailText(textCell);
			}
			return null;
		}

		protected virtual Span OnMainText(TextCell cell)
		{
			return new Span()
			{
				Text = cell.Text,
				ForegroundColor = cell.TextColor,
				FontSize = -1
			};
		}

		protected virtual Span OnDetailText(TextCell cell)
		{
			return new Span()
			{
				Text = cell.Detail,
				ForegroundColor = cell.DetailColor,
				FontSize = -1
			};
		}

		protected override bool OnCellPropertyChanged(Cell cell, string property, Dictionary<string, EvasObject> realizedView)
		{
			if (property == TextCell.TextProperty.PropertyName ||
				property == TextCell.TextColorProperty.PropertyName ||
				property == TextCell.DetailProperty.PropertyName ||
				property == TextCell.DetailColorProperty.PropertyName)
			{
				return true;
			}
			return base.OnCellPropertyChanged(cell, property, realizedView);
		}
	}

	internal class GroupCellTextRenderer : TextCellRenderer
	{

		public GroupCellTextRenderer() : this("group_index")
		{
			DetailPart = "elm.text.end";
		}
		protected GroupCellTextRenderer(string style) : base(style) { }
	}
}