mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-30 17:57:57 +01:00
Nuked ScenarioListDataSource
This commit is contained in:
@@ -503,79 +503,6 @@ namespace UICatalog {
|
||||
}
|
||||
}
|
||||
|
||||
internal class ScenarioListDataSource : IListDataSource {
|
||||
private readonly int len;
|
||||
|
||||
public List<Scenario> Scenarios { get; set; }
|
||||
|
||||
public bool IsMarked (int item) => false;
|
||||
|
||||
public int Count => Scenarios.Count;
|
||||
|
||||
public int Length => len;
|
||||
|
||||
public ScenarioListDataSource (List<Scenario> itemList)
|
||||
{
|
||||
Scenarios = itemList;
|
||||
len = GetMaxLengthItem ();
|
||||
}
|
||||
|
||||
public void Render (ListView container, ConsoleDriver driver, bool selected, int item, int col, int line, int width, int start = 0)
|
||||
{
|
||||
container.Move (col, line);
|
||||
// Equivalent to an interpolated string like $"{Scenarios[item].Name, -widtestname}"; if such a thing were possible
|
||||
var s = String.Format (String.Format ("{{0,{0}}}", -_nameColumnWidth), Scenarios [item].GetName());
|
||||
RenderUstr (driver, $"{s} {Scenarios [item].GetDescription()}", col, line, width, start);
|
||||
}
|
||||
|
||||
public void SetMark (int item, bool value)
|
||||
{
|
||||
}
|
||||
|
||||
int GetMaxLengthItem ()
|
||||
{
|
||||
if (Scenarios?.Count == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int maxLength = 0;
|
||||
for (int i = 0; i < Scenarios.Count; i++) {
|
||||
var s = String.Format (String.Format ("{{0,{0}}}", -_nameColumnWidth), Scenarios [i].GetName());
|
||||
var sc = $"{s} {Scenarios [i].GetDescription()}";
|
||||
var l = sc.Length;
|
||||
if (l > maxLength) {
|
||||
maxLength = l;
|
||||
}
|
||||
}
|
||||
return maxLength;
|
||||
}
|
||||
|
||||
// A slightly adapted method from: https://github.com/gui-cs/Terminal.Gui/blob/fc1faba7452ccbdf49028ac49f0c9f0f42bbae91/Terminal.Gui/Views/ListView.cs#L433-L461
|
||||
private void RenderUstr (ConsoleDriver driver, ustring ustr, int col, int line, int width, int start = 0)
|
||||
{
|
||||
int used = 0;
|
||||
int index = start;
|
||||
while (index < ustr.Length) {
|
||||
(var rune, var size) = Utf8.DecodeRune (ustr, index, index - ustr.Length);
|
||||
var count = Rune.ColumnWidth (rune);
|
||||
if (used + count >= width) break;
|
||||
driver.AddRune (rune);
|
||||
used += count;
|
||||
index += size;
|
||||
}
|
||||
|
||||
while (used < width) {
|
||||
driver.AddRune (' ');
|
||||
used++;
|
||||
}
|
||||
}
|
||||
|
||||
public IList ToList ()
|
||||
{
|
||||
return Scenarios;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When Scenarios are running we need to override the behavior of the Menu
|
||||
/// and Statusbar to enable Scenarios that use those (or related key input)
|
||||
|
||||
Reference in New Issue
Block a user