using Annulus; using Azimuth; using System; using System.Collections.Generic; namespace Glass.Testbed.TestCases.Controls { /// /// A ResizablePanel anyone can drag by its edges or corners, with a live readout of its current size, next to one /// that can also be moved by dragging its title strip. /// public class ResizablePanelTestCase : TestCase { /// /// A ResizablePanel with art a test case can set. /// private class ArtPanel : ResizablePanel { public new Material Material { get => base.Material; set => SetMaterial(value); } } /// /// A ResizablePanel whose drag handle is its title strip child. /// private sealed class TitledPanel : ArtPanel { public Control TitleStrip { get; set; } public override bool IsDragHandle(Vector position) { return TitleStrip != null && TitleStrip.Bounds.ContainsPoint(position - CanvasOrigin); } } private const int StageHeight = 320; private const int TitleHeight = 28; private static readonly Vector InitialOffset = new Vector(40, 40); private static readonly Vector InitialSize = new Vector(200, 150); private static readonly Vector MovableOffset = new Vector(300, 40); private static readonly Vector MinSize = new Vector(80, 60); private ArtPanel resizable; private Label sizeReadout; private TitledPanel movable; private Label titleLabel; protected override void Populate() { AddCaption("Drag the edges or corners to resize; MinSize keeps it from collapsing to nothing"); AddCaption("Drag the blue title strip to move the right-hand panel; a click brings a panel to the front"); Rect stage = ContentAggregator.NewRow(StageHeight); resizable = NewChild("resizable"); resizable.Material = UiPacksheetMaterials.GreenFlatPanel; resizable.MinSize = MinSize; resizable.ResizeCursors = ResizeCursorMaterials.ByZone; resizable.MoveToFrontOnClick = true; resizable.Bounds = Rect.FromPositionAndSize(stage.TopLeft + InitialOffset, InitialSize); sizeReadout = new Label(Widgets.FieldTextStyle, "") { DebugName = "size readout", Bounds = Rect.FromPositionAndSize(Vector.Zero, new Vector(160, 40)), }; resizable.CanvasChildren.Add(sizeReadout); movable = NewChild("movable"); movable.Material = UiPacksheetMaterials.GreenFlatPanel; movable.MinSize = MinSize; movable.ResizeCursors = ResizeCursorMaterials.ByZone; movable.MoveCursor = CursorExtraMaterials.Move; movable.MoveToFrontOnClick = true; movable.Bounds = Rect.FromPositionAndSize(stage.TopLeft + MovableOffset, InitialSize); var titleStrip = movable.CanvasChildren.NewChild("title strip"); titleStrip.Material = UiPacksheetMaterials.BlueFlatPanel; movable.TitleStrip = titleStrip; titleLabel = new Label(Widgets.SmallCaptionStyle, "Drag here to move") { DebugName = "title label" }; titleStrip.CanvasChildren.Add(titleLabel); resizable.OnSizeChanged += _ => UpdateSizeReadout(); movable.OnSizeChanged += _ => LayOutTitleStrip(); UpdateSizeReadout(); LayOutTitleStrip(); } private void UpdateSizeReadout() { sizeReadout.Text = $"{resizable.Bounds.Size.X:F0} x {resizable.Bounds.Size.Y:F0}"; } private void LayOutTitleStrip() { movable.TitleStrip.Bounds = Rect.FromPositionAndSize( Vector.Zero, new Vector(movable.CanvasLayout.CanvasRect.Width, TitleHeight)); titleLabel.Bounds = movable.TitleStrip.CanvasLayout.CanvasRect; } } }