-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMenu.cs
More file actions
100 lines (78 loc) · 2.53 KB
/
Menu.cs
File metadata and controls
100 lines (78 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using Meadow;
using Meadow.Foundation.Graphics;
using Meadow.Foundation.Graphics.MicroLayout;
namespace MicroLayoutMenu;
public class Menu
{
private Label[] _labels;
private Box _highlightBox;
private const int ItemHeight = 30;
public int SelectedRow { get; set; } = 0;
public readonly Color UnselectedTextColor = Color.AntiqueWhite;
public readonly Color SelectedTextColor = Color.Black;
public readonly Color SelectionColor = Color.Orange;
public readonly IFont MenuFont = new Font12x20();
public Menu(string[] items, DisplayScreen screen)
{
_labels = new Label[items.Length];
var x = 2;
var y = 0;
var height = ItemHeight;
// we compose the screen from the back forward, so put the box on first
_highlightBox = new Box(0, -1, screen.Width, ItemHeight + 2)
{
ForegroundColor = SelectionColor,
IsFilled = true,
};
screen.Controls.Add(_highlightBox);
for (var i = 0; i < items.Length; i++)
{
_labels[i] = new Label(
left: x,
top: i * height,
width: screen.Width,
height: height)
{
Text = items[i],
Font = MenuFont,
BackgroundColor = Color.Transparent,
VerticalAlignment = VerticalAlignment.Center,
};
// select the first item
if (i == 0)
{
_labels[i].TextColor = SelectedTextColor;
}
else
{
_labels[i].TextColor = UnselectedTextColor;
}
screen.Controls.Add(_labels[i]);
y += height;
}
}
public void Down()
{
if (SelectedRow < _labels.Length - 1)
{
SelectedRow++;
Resolver.Log.Info($"MENU SELECTED: {_labels[SelectedRow].Text}");
Draw(SelectedRow - 1, SelectedRow);
}
}
public void Up()
{
if (SelectedRow > 0)
{
SelectedRow--;
Resolver.Log.Info($"MENU SELECTED: {_labels[SelectedRow].Text}");
Draw(SelectedRow + 1, SelectedRow);
}
}
public void Draw(int oldRow, int newRow)
{
_labels[oldRow].TextColor = UnselectedTextColor;
_labels[newRow].TextColor = SelectedTextColor;
_highlightBox.Top = _labels[newRow].Top - 1;
}
}