2 using System.Collections.Generic;
6 namespace ElmSharp.Wearable
8 public class RotarySelector : Layout
10 const string IconPartName = "selector,icon";
11 const string ContentPartName = "selector,content";
12 const string BgPartName = "selector,bg_image";
14 const string ItemSelectedEventName = "item,selected";
15 const string ItemClickedEventName = "item,clicked";
17 public event EventHandler<RotarySelectorItemEventArgs> Selected;
18 public event EventHandler<RotarySelectorItemEventArgs> Clicked;
20 SmartEvent<PointerEventArgs> _selectedEvent;
21 SmartEvent<PointerEventArgs> _clickedEvent;
24 public IList<RotarySelectorItem> Items { get; private set; }
26 public RotarySelector(EvasObject parent) : base(parent)
28 Items = new RotarySelectorList(this);
30 _selectedEvent = new SmartEvent<PointerEventArgs>(this, "item,selected", (d, o, info) => new PointerEventArgs { Pointer = info });
31 _clickedEvent = new SmartEvent<PointerEventArgs>(this, "item,clicked", (d, o, info) => new PointerEventArgs { Pointer = info });
32 _selectedEvent.On += (s, e) =>
34 RotarySelectorItem selected = Items.FirstOrDefault(i => i.Handle == e.Pointer);
35 Selected?.Invoke(this, new RotarySelectorItemEventArgs { Item = selected });
38 _clickedEvent.On += (s, e) =>
40 RotarySelectorItem selected = Items.FirstOrDefault(i => i.Handle == e.Pointer);
41 Clicked?.Invoke(this, new RotarySelectorItemEventArgs { Item = selected });
45 public RotarySelectorItem SelectedItem
49 IntPtr selectedPtr = Interop.Eext.eext_rotary_selector_selected_item_get(this);
50 if (selectedPtr == IntPtr.Zero) return null;
51 RotarySelectorItem item = Items.FirstOrDefault(i => i.Handle == selectedPtr);
57 if (!Items.Contains(value)) return;
58 Interop.Eext.eext_rotary_selector_selected_item_set(this, value.Handle);
62 void setPart(ref Image prop, string partName, State state, Image img)
64 if (prop == img) return;
68 Interop.Eext.eext_rotary_selector_part_content_set(this, partName, (int)state, prop);
71 void setPart(ref Color prop, string partName, State state, Color color)
73 if (prop == color) return;
76 Interop.Eext.eext_rotary_selector_part_color_set(this, partName, (int)state, color.R, color.G, color.B, color.A);
80 public Image BackgroundImage { set => setPart(ref _normalBgImage, BgPartName, State.Normal, value); get => _normalBgImage; }
82 protected override IntPtr CreateHandle(EvasObject parent)
84 IntPtr ptr = Interop.Eext.eext_rotary_selector_add(parent);
85 Interop.Eext.eext_rotary_object_event_activated_set(ptr, true);