Cycle most of options for PowerControl

This commit is contained in:
Kamil Trzciński 2022-11-19 09:29:44 +01:00
parent b94719adb0
commit 681db9231d
3 changed files with 24 additions and 12 deletions

View file

@ -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)

View file

@ -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()

View file

@ -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).