using Xui.Core.Canvas; using Xui.Core.Math2D; using Xui.Core.UI; using NFloat = System.Runtime.InteropServices.NFloat; public sealed class ResponsiveExample : ViewCollection { private readonly Border first = Panel("The sketch", 0xD6B8F4FF); private readonly Border second = Panel("The notes", 0xEADCFBFF); public ResponsiveExample() { Add(first); Add(second); } protected override Size MeasureCore(Size available, IMeasureContext context) { NFloat width = NFloat.IsFinite(available.Width) ? available.Width : 400; NFloat height = NFloat.IsFinite(available.Height) ? available.Height : 320; var wide = width >= 560; var childSize = wide ? new Size((width - 16) / 2, height) : new Size(width, (height - 16) / 2); first.Measure(childSize, context); second.Measure(childSize, context); return new Size(width, height); } protected override void ArrangeCore(Rect rect, IMeasureContext context) { if (rect.Width >= 560) { var width = NFloat.Max(0, (rect.Width - 16) / 2); first.Arrange(new Rect(rect.X, rect.Y, width, rect.Height), context); second.Arrange(new Rect(rect.X + width + 16, rect.Y, width, rect.Height), context); } else { var height = NFloat.Max(0, (rect.Height - 16) / 2); first.Arrange(new Rect(rect.X, rect.Y, rect.Width, height), context); second.Arrange(new Rect(rect.X, rect.Y + height + 16, rect.Width, height), context); } } private static Border Panel(string title, uint color) => new() { Padding = 24, BackgroundColor = new Color(color), Content = new Label { Text = title, FontFamily = "Inter", FontSize = 20 } }; }