public void ColumnSelectorEnum <T>(ICellRW <T> curr, Action <T, DebugLayout> fillFunc, DebugLayoutOptions opts = default(DebugLayoutOptions)) { Func <string, T> parse = s => (T)Enum.Parse(typeof(T), s); ColumnSelector(Enum.GetNames(typeof(T)), curr.MapToString(parse), (s, l) => fillFunc(parse(s), l), opts); }
public DebugLayout Selector(FieldPresentSettings name, IList <string> options, ICellRW <string> value , DebugLayoutOptions opts = default(DebugLayoutOptions)) { Dropdown selector = NamedElementOrLayouted <Dropdown>(name, factory.dropdownPrefab, opts).GetComponentInChildren <Dropdown>(); selector.options = options.Select(elemName => new Dropdown.OptionData(elemName)).ToList(); value.Bind(v => selector.value = options.IndexOf(v)); selector.onValueChanged.AddListener(new UnityAction <int>(i => { value.value = options[i]; })); return(this); }
public void ColumnSelector(string[] names, ICellRW <string> curr, Action <string, DebugLayout> fillFunc, DebugLayoutOptions opts = default(DebugLayoutOptions)) { Selector("", names, curr); foreach (var name in names) { var c = Column(opts); if (opts.fitSize) { c.GetComponent <VerticalLayoutGroup>().childControlHeight = false; } c.HideIf(curr.IsNot(name)); fillFunc(name, c); } }
public DebugLayout ScrollSingleSelection <T>( IReactiveCollection <T> collection, ICellRW <T> selected, Func <T, string> toString, float takeRelativeLayoutSize = 1) { var currentSelected = InstantiateInLayout(factory.titlePrefab).GetComponentInChildren <Text>(); currentSelected.SetTextContent(selected.Select(v => $"current: {toString(v)}")); var scroll = InstantiateInLayout(factory.scrollPrefab, new DebugLayoutOptions { flexibleSpace = takeRelativeLayoutSize }); Rui.PresentInScrollWithLayout(collection, scroll, show: (s, button) => { button.Show(toString(s), selected.Select(v => object.ReferenceEquals(v, s)), button.connectionSink); button.button.ClickStream().Subscribe(() => selected.value = s); }, prefab: PrefabRef.ToPrefabRef(factory.buttonPrefab), layout: Rui.LinearLayout(forceMainSize: 80)); return(this); }
public static ICellRW <T2> MapRWConvert <T, T2>(this ICellRW <T> cell) { return(new AnonymousRWCell <T2>((Action <T2> reaction) => { var disp = new MapDisposable <T2>(); disp.last = (T2)Convert.ChangeType(cell.value, typeof(T2)); disp.Disposable = cell.ListenUpdates(val => { var newCurr = (T2)Convert.ChangeType(cell.value, typeof(T2)); if (!EqualityComparer <T2> .Default.Equals(newCurr, disp.last)) { disp.last = newCurr; reaction(newCurr); } }); return disp; }, () => (T2)Convert.ChangeType(cell.value, typeof(T2)), v => cell.value = (T)Convert.ChangeType(v, typeof(T)))); }
public static ICellRW <string> MapRWEnumToString <T>(this ICellRW <T> cell) { return(new AnonymousRWCell <string>((Action <string> reaction) => { var disp = new MapDisposable <string>(); disp.last = cell.value.ToString(); disp.Disposable = cell.ListenUpdates(val => { var newCurr = val.ToString(); if (newCurr != disp.last) { disp.last = newCurr; reaction(newCurr); } }); return disp; }, () => cell.value.ToString(), v => cell.value = (T)Enum.Parse(typeof(T), v))); }
/// An experimental concept some kink of abstract lens. public static ICellRW <T2> MapRW <T, T2>(this ICellRW <T> cell, Func <T, T2> map, Func <T2, T> mapBack) { return(new AnonymousRWCell <T2>((Action <T2> reaction) => { var disp = new MapDisposable <T2>(); disp.last = map(cell.value); disp.Disposable = cell.ListenUpdates(val => { var newCurr = map(val); if (!EqualityComparer <T2> .Default.Equals(newCurr, disp.last)) { disp.last = newCurr; reaction(newCurr); } }); return disp; }, () => map(cell.value), v => cell.value = mapBack(v))); }
public DebugLayout ScrollSingleSelection( IReactiveCollection <string> collection, ICellRW <string> selected, float takeRelativeLayoutSize = 1) { var currentSelected = InstantiateInLayout(factory.titlePrefab).GetComponentInChildren <Text>(); currentSelected.SetTextContent(selected.Select(v => $"current: {v}")); var scroll = InstantiateInLayout(factory.scrollPrefab, new DebugLayoutOptions { flexibleSpace = takeRelativeLayoutSize }); Rui.PresentInScrollWithLayout(collection, scroll, PrefabRef.ToPrefabRef(factory.buttonPrefab), (s, button) => { button.Show(s, selected.Select(v => v == s), button.connectionSink); button.addConnection = button.button.ClickStream().Subscribe(() => selected.value = s); }, layout: Rui.LinearLayout(forceMainSize: 80)); return(this); }
public static ICellRW <string> MapToString <T>(this ICellRW <T> cell, Func <string, T> parseFunc) { return(cell.MapRW(v => v.ToString(), parseFunc)); }
public DebugLayout EnumSelector(FieldPresentSettings name, Type enumType, ICellRW <object> value, DebugLayoutOptions opts = default(DebugLayoutOptions), ExcudeEnumNameInSelector exclude = null) { return(Selector(name, Enum.GetNames(enumType).Where(n => exclude == null || exclude.name.Contains(n) == false).ToList(), value.MapRW(v => v.ToString(), s => Enum.Parse(enumType, s)), opts)); }
public DebugLayout EnumSelector <T>(FieldPresentSettings name, ICellRW <T> value, DebugLayoutOptions opts = default(DebugLayoutOptions)) { return(Selector(name, Enum.GetNames(typeof(T)), value.MapRW(v => v.ToString(), s => (T)Enum.Parse(typeof(T), s)), opts)); }
public IDisposable Show(ICellRW <int> value) { Show(value); return(value.Bind(v => text.text = v.ToString())); }