2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Collections;
19 using System.Collections.Generic;
22 namespace ElmSharp.Wearable
24 class RotarySelectorList : IList<RotarySelectorItem>
26 RotarySelector _owner;
27 List<RotarySelectorItem> Items { get; set; }
29 public RotarySelectorList(RotarySelector owner)
32 Items = new List<RotarySelectorItem>();
35 public RotarySelectorItem this[int index] { get => Items[index]; set => Items[index] = value; }
37 public int Count => Items.Count;
39 public bool IsReadOnly => false;
41 public void Add(RotarySelectorItem item)
43 item.Handle = Interop.Eext.eext_rotary_selector_item_append(_owner);
49 Interop.Eext.eext_rotary_selector_items_clear(_owner);
52 public bool Contains(RotarySelectorItem item)
54 return Items.Contains(item);
57 public void CopyTo(RotarySelectorItem[] array, int arrayIndex)
59 Items.CopyTo(array, arrayIndex);
62 public IEnumerator<RotarySelectorItem> GetEnumerator()
64 return Items.GetEnumerator();
67 public int IndexOf(RotarySelectorItem item)
69 return Items.IndexOf(item);
72 public void Insert(int index, RotarySelectorItem item)
74 if (Items.Count <= index || index < 0)
76 throw new ArgumentOutOfRangeException("index is not valid in the RotarySelector");
78 RotarySelectorItem target = Items[index];
79 item.Handle = Interop.Eext.eext_rotary_selector_item_insert_after(_owner, target.Handle);
80 Items.Insert(index, item);
83 public bool Remove(RotarySelectorItem item)
85 if (Items.Contains(item))
87 Interop.Eext.eext_rotary_selector_item_del(item.Handle);
94 public void RemoveAt(int index)
96 if (Items.Count < index + 1 || index < 0)
98 throw new ArgumentOutOfRangeException("index is not valid in the RotarySelector");
101 RotarySelectorItem target = Items[index];
102 Interop.Eext.eext_rotary_selector_item_del(target.Handle);
103 target.Handle = IntPtr.Zero;
104 Items.RemoveAt(index);
107 IEnumerator IEnumerable.GetEnumerator()
109 return Items.GetEnumerator();