-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSmartObjectDynamicListHelper.cs
More file actions
68 lines (55 loc) · 2.39 KB
/
Copy pathSmartObjectDynamicListHelper.cs
File metadata and controls
68 lines (55 loc) · 2.39 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport;
namespace Daniels.UI
{
public class SmartObjectDynamicListHelperParameters : SmartObjectHelperParameters
{
public ushort NumberOfItems = 0;
}
public class SmartObjectDynamicListHelper : SmartObjectHelper
{
public const string ScrollToItem = "Scroll To Item";
public const string SetNumberOfItems = "Set Number of Items";
public const string ItemClicked = "Item Clicked";
private Dictionary<uint, SmartObjectDynamicListItem> _items;
public SmartObjectDynamicListHelper(SmartObject smartObject, SmartObjectDynamicListHelperParameters helperParams)
: base(smartObject, helperParams)
{
MaxNumberOfItems = (ushort)_smartObject.BooleanOutput.Count(s => s.Name.EndsWith("Pressed"));
_items = new Dictionary<uint, SmartObjectDynamicListItem>(MaxNumberOfItems);
for (uint i = 1; i <= MaxNumberOfItems; i++)
_items.Add(i, new SmartObjectDynamicListItem(this, i));
Items = new ReadOnlyDictionary<uint, SmartObjectDynamicListItem>(_items);
NumberOfItems = helperParams.NumberOfItems;
if (helperParams.NumberOfItems > MaxNumberOfItems)
throw new ArgumentOutOfRangeException("helperParams.NumberOfItems", "Only " + MaxNumberOfItems + " items defined in the SGD file");
else
NumberOfItems = helperParams.NumberOfItems;
}
#region Properties
public ushort MaxNumberOfItems { get; private set; }
public virtual ushort NumberOfItems
{
get { return _smartObject.UShortInput[SetNumberOfItems].UShortValue; }
set
{
if (value > 0 && value <= MaxNumberOfItems)
{
_smartObject.UShortInput[SetNumberOfItems].UShortValue = value;
}
}
}
public Action<ushort> ItemClickedAction
{
get { return _smartObject.UShortOutput[ItemClicked].UserObject as Action<ushort>; }
set { _smartObject.UShortOutput[ItemClicked].UserObject = value; }
}
#endregion Properties
public ReadOnlyDictionary<uint, SmartObjectDynamicListItem> Items;
}
}