diff --git a/PowerControl/Menu.cs b/PowerControl/Menu.cs index 2406bc0..4923af6 100644 --- a/PowerControl/Menu.cs +++ b/PowerControl/Menu.cs @@ -90,6 +90,7 @@ namespace PowerControl public Object SelectedOption { get; set; } public Object ActiveOption { get; set; } public int ApplyDelay { get; set; } + public bool CycleOptions { get; set; } = true; public CurrentValueDelegate CurrentValue { get; set; } public OptionsValueDelegate OptionsValues { get; set; } @@ -230,26 +231,35 @@ namespace PowerControl collection.Add(toolStripItem); } + private void SelectIndex(int index) + { + if (Options.Count == 0) + return; + + SelectedOption = Options[Math.Clamp(index, 0, Options.Count - 1)]; + scheduleApply(); + } + public override void SelectNext() { int index = Options.IndexOf(SelectedOption ?? ActiveOption); - if (index >= 0) - SelectedOption = Options[Math.Min(index + 1, Options.Count - 1)]; + if (index < 0) + SelectIndex(0); // select first + else if (CycleOptions) + SelectIndex((index + 1) % Options.Count); else - SelectedOption = Options.First(); - - scheduleApply(); + SelectIndex(index + 1); } public override void SelectPrev() { int index = Options.IndexOf(SelectedOption ?? ActiveOption); - if (index >= 0) - SelectedOption = Options[Math.Max(index - 1, 0)]; + if (index < 0) + SelectIndex(Options.Count - 1); // select last + else if (CycleOptions) + SelectIndex((index - 1 + Options.Count) % Options.Count); else - SelectedOption = Options.First(); - - scheduleApply(); + SelectIndex(index - 1); } private String optionText(Object option) diff --git a/PowerControl/MenuStack.cs b/PowerControl/MenuStack.cs index df0cd02..8d58d76 100644 --- a/PowerControl/MenuStack.cs +++ b/PowerControl/MenuStack.cs @@ -22,7 +22,7 @@ namespace PowerControl { Name = "Brightness", Options = { 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100 }, - + CycleOptions = false, CurrentValue = delegate() { return Helpers.WindowsSettingsBrightnessController.Get(5.0); @@ -38,6 +38,7 @@ namespace PowerControl { Name = "Volume", Options = { 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100 }, + CycleOptions = false, CurrentValue = delegate() { return Helpers.AudioManager.GetMasterVolume(5.0); @@ -113,7 +114,7 @@ namespace PowerControl var refreshRate = Helpers.PhysicalMonitorBrightnessController.GetRefreshRate(); return new object[] { - "Off", refreshRate, refreshRate / 2, refreshRate / 4 + refreshRate / 4, refreshRate / 2, refreshRate, "Off" }; }, CurrentValue = delegate() diff --git a/RELEASE.md b/RELEASE.md index 6577cf4..52ea7ae 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -16,5 +16,6 @@ - Allow to disable SMT (second threads of each physical cores) - Fix PowerControl crash on startup (introduced with SMT) - Allow to change resolution (Experimental feature) +- PowerControl options are in cycle If you found it useful buy me [Ko-fi](https://ko-fi.com/ayufan).