mirror of
https://github.com/ayufan/steam-deck-tools.git
synced 2026-04-05 22:35:38 +00:00
PowerControl: Simplify Next, Select and SelectNext
This commit is contained in:
parent
130a6fb745
commit
06f2d9a702
5 changed files with 41 additions and 93 deletions
|
|
@ -32,7 +32,6 @@ namespace PowerControl.Menu
|
|||
public abstract void Update();
|
||||
public abstract void Reset();
|
||||
|
||||
public abstract void SelectNext();
|
||||
public abstract void SelectPrev();
|
||||
public abstract void SelectNext(int change);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -160,26 +160,22 @@ namespace PowerControl.Menu
|
|||
scheduleApply();
|
||||
}
|
||||
|
||||
public override void SelectNext()
|
||||
public override void SelectNext(int change)
|
||||
{
|
||||
int index = Options.IndexOf(SelectedOption ?? ActiveOption);
|
||||
if (index < 0)
|
||||
SelectIndex(0); // select first
|
||||
else if (CycleOptions)
|
||||
SelectIndex((index + 1) % Options.Count);
|
||||
else
|
||||
SelectIndex(index + 1);
|
||||
}
|
||||
{
|
||||
if (change > 0)
|
||||
SelectIndex(0); // select first
|
||||
else
|
||||
SelectIndex(Options.Count); // select last
|
||||
return;
|
||||
}
|
||||
|
||||
public override void SelectPrev()
|
||||
{
|
||||
int index = Options.IndexOf(SelectedOption ?? ActiveOption);
|
||||
if (index < 0)
|
||||
SelectIndex(Options.Count - 1); // select last
|
||||
else if (CycleOptions)
|
||||
SelectIndex((index - 1 + Options.Count) % Options.Count);
|
||||
if (CycleOptions)
|
||||
SelectIndex((index + change + Options.Count) % Options.Count);
|
||||
else
|
||||
SelectIndex(index - 1);
|
||||
SelectIndex(index + change);
|
||||
}
|
||||
|
||||
private String optionText(Object option)
|
||||
|
|
|
|||
|
|
@ -76,18 +76,20 @@ namespace PowerControl.Menu
|
|||
return true;
|
||||
}
|
||||
|
||||
public void Prev()
|
||||
public void Next(int change)
|
||||
{
|
||||
if (Show())
|
||||
return;
|
||||
|
||||
int index = Items.IndexOf(Selected);
|
||||
if (index < 0)
|
||||
index = Items.Count; // select last item
|
||||
int index = -1;
|
||||
if (Selected is not null)
|
||||
index = Items.IndexOf(Selected);
|
||||
if (index < 0 && change < 0)
|
||||
index = Items.Count; // Select last item if want to iterate down
|
||||
|
||||
for (int i = 0; i < Items.Count; i++)
|
||||
{
|
||||
index = (index - 1 + Items.Count) % Items.Count;
|
||||
index = (index + change + Items.Count) % Items.Count;
|
||||
var item = Items[index];
|
||||
if (item.Visible && item.Selectable)
|
||||
{
|
||||
|
|
@ -98,74 +100,27 @@ namespace PowerControl.Menu
|
|||
}
|
||||
}
|
||||
|
||||
public void Next()
|
||||
{
|
||||
if (Show())
|
||||
return;
|
||||
|
||||
int index = Items.IndexOf(Selected);
|
||||
if (index < 0)
|
||||
index = -1; // select first item
|
||||
|
||||
for (int i = 0; i < Items.Count; i++)
|
||||
{
|
||||
index = (index + 1) % Items.Count;
|
||||
var item = Items[index];
|
||||
if (item.Visible && item.Selectable)
|
||||
{
|
||||
Selected = item;
|
||||
VisibleChanged();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void SelectNext()
|
||||
public override void SelectNext(int change)
|
||||
{
|
||||
if (Show())
|
||||
return;
|
||||
|
||||
if (Selected != null)
|
||||
{
|
||||
Selected.SelectNext();
|
||||
Selected.SelectNext(change);
|
||||
VisibleChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void SelectNext(String name)
|
||||
public MenuItem? Select(String name)
|
||||
{
|
||||
var item = this[name];
|
||||
if (item is null)
|
||||
return;
|
||||
Selected = this[name];
|
||||
if (Selected is null)
|
||||
return null;
|
||||
|
||||
Show();
|
||||
Selected = item;
|
||||
item.SelectNext();
|
||||
VisibleChanged();
|
||||
}
|
||||
|
||||
public override void SelectPrev()
|
||||
{
|
||||
if (Show())
|
||||
return;
|
||||
|
||||
if (Selected != null)
|
||||
{
|
||||
Selected.SelectPrev();
|
||||
VisibleChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void SelectPrev(String name)
|
||||
{
|
||||
var item = this[name];
|
||||
if (item is null)
|
||||
return;
|
||||
|
||||
Show();
|
||||
Selected = item;
|
||||
item.SelectPrev();
|
||||
VisibleChanged();
|
||||
return Selected;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -23,11 +23,7 @@ namespace PowerControl.Menu
|
|||
return Color("---", Colors.Blue);
|
||||
}
|
||||
|
||||
public override void SelectNext()
|
||||
{
|
||||
}
|
||||
|
||||
public override void SelectPrev()
|
||||
public override void SelectNext(int change)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue