using Annulus;
using Azimuth;
using Clave;
using Glass.Blacklight;
using System;
using Prism;
namespace Glass.Testbed.TestCases.Layout
{
public class PanelsTestCase : TestCase
{
private const int PanelHeight = 300;
private const int PanelLabelGap = 40;
private const int LabelTextWidth = 300;
// Matches the gap between the buttons it holds.
private static readonly Rect.BorderSize PanelPadding = new Rect.BorderSize(Gutter);
private readonly World world;
private int clickCount;
public PanelsTestCase(World world)
{
this.world = world;
}
///
/// Adds a yellow button to at , with
/// filling it.
///
private static Button AddButton(Control parent, Rect bounds, Label label)
{
var button = label.FillParent(new Button(ButtonBehavior.Default)
{
ButtonMaterial = UiPacksheetMaterials.YellowButton,
Bounds = bounds,
});
parent.CanvasChildren.Add(button);
return button;
}
protected override void Populate()
{
var paragraph = new Label(
new TextMaterialStyle { Font = Fonts.Philosopher32, VerticalAlignment = Alignment.Vertical.Top },
"Á | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor " +
"incididunt ut labore et dolore magna aliqua. gy ᚠ",
Constraints.Loose(new Vector(LabelTextWidth, Scalar.PositiveInfinity)));
// Measured up front so the row can be as tall as the taller of the two columns, which is what keeps
// ContentBounds covering the whole case.
Panel label =
paragraph.WrapIn(UiPacksheetMaterials.GreenPanel with { TintColor = Colors.Red });
Vector labelSize = label.Bounds.Size;
// Disable is the widest label, so it sets the size both buttons share.
var counterText = new Label(Widgets.ButtonLabelStyle, $"{clickCount}");
var disableText = new Label(Widgets.ButtonLabelStyle, "Disable");
Vector buttonSize = UiPacksheetMaterials.YellowButton.BoundsSizeFor(
disableText.PreferredSize(Constraints.Unbounded));
Vector panelSize = new Vector(
UiPacksheetMaterials.RedFlatPanel.BoundsSizeFor(PanelPadding.Expand(buttonSize)).X, PanelHeight);
Rect topRow = ContentAggregator.NewRow(Math.Max(panelSize.Y, labelSize.Y));
Rect panelSlot = topRow.NewCol(panelSize.X, margin: PanelLabelGap);
var panel = NewChild("panel");
panel.Material = UiPacksheetMaterials.RedFlatPanel;
panel.Bounds = panelSlot.NewRow(panelSize.Y);
Rect insidePanel = panel.CanvasRect.Erode(PanelPadding);
Rect counterRow = insidePanel.NewRow(buttonSize.Y, margin: Gutter);
Rect disableRow = insidePanel.NewRow(buttonSize.Y);
Button counterButton = AddButton(panel, counterRow, counterText);
counterButton.OnActivate += delegate (ButtonBase _, in KeyboardSnapshot __, KeyboardManager ___)
{
++clickCount;
counterText.Text = $"{clickCount}";
FontRenderer.LayoutDebug = !FontRenderer.LayoutDebug;
world.window.Invalidate();
};
Button disableButton = AddButton(panel, disableRow, disableText);
disableButton.OnActivate += delegate (ButtonBase _, in KeyboardSnapshot __, KeyboardManager ___)
{
counterButton.Enabled = !counterButton.Enabled;
world.window.Invalidate();
};
Rect labelColumn = topRow.NewCol(labelSize.X);
label.Bounds = labelColumn.NewRow(labelSize.Y);
Add(label);
}
}
}