using Annulus; using Azimuth; using Prism; namespace Glass.Testbed.TestCases.Controls { /// /// GroupBoxes with the caption on the baseline, through the middle and above the frame, then one with the frame art /// scaled up and one sized to hold a caption wider than its content. /// public class GroupBoxTestCase : TestCase { private static readonly Vector BoxSize = new Vector(220, 110); /// /// A solid cell that is a fixed thickness across the axes it is intrinsic on. /// public record LineCell : SolidColorMaterial { public Scalar Thickness { get; init; } protected override Vector PreferredSizeInModelSpace(Constraints constraints) { return new Vector( LayoutSizingX == LayoutSizing.Fill ? constraints.MinSize.X : Thickness, LayoutSizingY == LayoutSizing.Fill ? constraints.MinSize.Y : Thickness); } } private static LineCell Line(Color color, int thickness, bool fillX, bool fillY) { return new LineCell { Color = color, Thickness = thickness, LayoutSizingX = fillX ? LayoutSizing.Fill : LayoutSizing.Intrinsic, LayoutSizingY = fillY ? LayoutSizing.Fill : LayoutSizing.Intrinsic, }; } private static GroupBoxMaterial ThinFrame(Color line, Material background, int thickness) { // Nothing is drawn in the center, so the background shows through the line's square corners. Material corner = Line(line, thickness, fillX: false, fillY: false); Material horizontal = Line(line, thickness, fillX: true, fillY: false); Material vertical = Line(line, thickness, fillX: false, fillY: true); Material[] cells = { corner, horizontal, corner, vertical, Material.Invisible, vertical, corner, horizontal, corner, }; return new GroupBoxMaterial { Background = background, Frame = new NineSliceMaterial { ChildMaterials = cells, BorderSize = new Rect.BorderSize { Top = thickness, Bottom = thickness, Left = thickness, Right = thickness, }, }, FrameInset = 6, CaptionStyle = Widgets.MenuLabelStyle, }; } private static GroupBox NewBox(string text, CaptionPlacement placement, GroupBoxMaterial frame) { return new GroupBox { DebugName = text, Material = frame with { CaptionPlacement = placement }, Text = text, }; } private void Place(GroupBox box, Rect bounds, string inside) { box.Bounds = bounds; box.CanvasChildren.Add(new Label(Widgets.MenuLabelStyle, inside) { DebugName = "inside", Bounds = box.CanvasRect, }); Add(box); } protected override void Populate() { GroupBoxMaterial frame = ThinFrame( Color.FromArgb(170, 170, 170), UiPacksheetMaterials.Panel with { TintColor = Color.FromArgb(225, 225, 225) }, thickness: 2); const string Inside = "Inside the frame"; AddCaption("Caption on the baseline, through the middle, and above the frame."); Rect placements = ContentAggregator.NewRow(BoxSize.Y); Place(NewBox("Baseline", CaptionPlacement.Baseline, frame), placements.NewCol(BoxSize.X, margin: Gutter), Inside); Place(NewBox("Middle", CaptionPlacement.Middle, frame), placements.NewCol(BoxSize.X, margin: Gutter), Inside); Place(NewBox("Above", CaptionPlacement.Above, frame), placements.NewCol(BoxSize.X), Inside); AddCaption("Frame art at scale 2, and a box sized to its content with a caption wider than it."); Rect variations = ContentAggregator.NewRow(BoxSize.Y); Place(NewBox("Scaled", CaptionPlacement.Baseline, frame with { Frame = frame.Frame with { Scale = 2 } }), variations.NewCol(BoxSize.X, margin: Gutter), Inside); GroupBox sized = NewBox("A long caption", CaptionPlacement.Baseline, frame); Vector sizedBounds = sized.BoundsSizeFor(new Vector(40, 20)); Place(sized, Rect.FromPositionAndSize(variations.NewCol(sizedBounds.X).TopLeft, sizedBounds), "Hi"); } } }