static int Bounded(int index, int count, SelectBoundMode mode) { switch (mode) { case SelectBoundMode.LOOP_OVER_NONE: index %= count + 1; if (index < 0) { index += count + 1; } return(index == count ? -1 : index); case SelectBoundMode.LOOP: index %= count; return(index < 0 ? index + count : index); case SelectBoundMode.CLAMP: return(index < 0 ? 0 : index >= count ? count - 1 : index); default: return(index < 0 ? -1 : index >= count ? count - 1 : index); } }
void Increment(SelectBoundMode incrementBoundMode, int step) { T currentItem = set.FirstOrDefault(); int currentIndex = select.list.IndexOf(currentItem); if (currentIndex != -1) { DoExit(currentItem); } int nextIndex = Bounded(currentIndex + 1, select.Count, incrementBoundMode); T nextItem = select.list[nextIndex]; if (nextIndex != -1) { DoEnter(nextItem); } DoChange(); }
public void Previous(SelectBoundMode boundMode) => Increment(boundMode, -1);
public void Next(SelectBoundMode boundMode) => Increment(boundMode, 1);
public void Previous <TLayer>(SelectBoundMode boundMode) => GetLayer <TLayer>().Previous(boundMode);
public void Previous(object layerKey, SelectBoundMode boundMode) => GetLayer(layerKey).Previous(boundMode);
public void Previous(SelectBoundMode boundMode) => GetLayer(defaultLayerKey).Previous(boundMode);
public void Next <TLayer>(SelectBoundMode boundMode) => GetLayer <TLayer>().Next(boundMode);
public void Next(object layerKey, SelectBoundMode boundMode) => GetLayer(layerKey).Next(boundMode);
public void Next(SelectBoundMode boundMode) => GetLayer(defaultLayerKey).Next(boundMode);