using Annulus;
using Azimuth;
using Clave;
using System.Collections.Generic;
namespace Glass.Testbed.TestCases.Rendering
{
///
/// Switches who draws the mouse cursor, so the three answers can be compared against each other live.
///
public class CursorTestCase : TestCase
{
private readonly World world;
private readonly Dictionary buttons = new Dictionary();
public CursorTestCase(World world)
{
this.world = world;
}
///
/// Stands in for a radio group: the chosen mode wears yellow.
///
private void ShowChoice()
{
foreach (KeyValuePair button in buttons)
{
button.Value.ButtonMaterial = button.Key == world.CursorMode
? UiPacksheetMaterials.YellowButton
: UiPacksheetMaterials.Button;
}
}
// The row is consumed a column at a time, so it has to be the caller's rect rather than a copy of it.
private void AddChoice(ref Rect row, CursorMode mode, string label, Vector buttonSize)
{
CursorMode chooseMe = mode;
Button choice = new Label(Widgets.ButtonLabelStyle, label).FillParent(new Button(ButtonBehavior.Default)
{
DebugName = $"{mode} cursor",
ButtonMaterial = UiPacksheetMaterials.Button,
Bounds = row.NewCol(buttonSize.X, margin: Gutter),
});
choice.OnActivate += delegate (ButtonBase _, in KeyboardSnapshot __, KeyboardManager ___)
{
world.CursorMode = chooseMe;
ShowChoice();
};
Add(choice);
buttons[mode] = choice;
}
protected override void Populate()
{
AddCaption("System leaves the pointer alone; hardware hands the art to the OS; software draws it here");
AddCaption("Software lands last in the frame, so nothing can cover it, but it trails by a tick");
// Every button shares the widest label's size, so switching modes never reflows the row.
Vector buttonSize = Vector.Max(
Widgets.ButtonLabel("System").PreferredSize(Constraints.Unbounded),
Widgets.ButtonLabel("Hardware").PreferredSize(Constraints.Unbounded),
Widgets.ButtonLabel("Software").PreferredSize(Constraints.Unbounded));
Rect row = ContentAggregator.NewRow(buttonSize.Y);
AddChoice(ref row, CursorMode.System, "System", buttonSize);
AddChoice(ref row, CursorMode.Hardware, "Hardware", buttonSize);
AddChoice(ref row, CursorMode.Software, "Software", buttonSize);
}
///
/// The mode outlives the case being hidden, so the buttons are re-marked rather than reset.
///
protected override void Setup()
{
ShowChoice();
}
}
}