using Annulus; using Azimuth; using System; using System.Collections.Generic; namespace Glass.Testbed { /// /// 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 whose drag handle is its title strip child. /// private sealed class TitledPanel : ResizablePanel { 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 ResizablePanel resizable; private TextMaterial sizeReadoutMaterial; private TitledPanel movable; private Panel titleLabel; public ResizablePanelTestCase(string name) : base(name) { } 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); sizeReadoutMaterial = Widgets.FieldText(""); var sizeReadout = resizable.CanvasChildren.NewChild("size readout"); sizeReadout.Material = sizeReadoutMaterial; sizeReadout.Bounds = Rect.FromPositionAndSize(Vector.Zero, new Vector(160, 40)); movable = NewChild("movable"); movable.Material = UiPacksheetMaterials.GreenFlatPanel; movable.MinSize = MinSize; movable.ResizeCursors = ResizeCursorMaterials.ByZone; 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 = titleStrip.CanvasChildren.NewChild("title label"); titleLabel.Material = Widgets.SmallCaption("Drag here to move"); resizable.OnResized += _ => UpdateSizeReadout(); movable.OnResized += _ => LayOutTitleStrip(); UpdateSizeReadout(); LayOutTitleStrip(); } private void UpdateSizeReadout() { sizeReadoutMaterial.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; } } }