using Annulus; using Azimuth; namespace Glass.Testbed { /// /// A grid of fixed-size labels holding more text than fits: a column per vertical alignment, a row per /// overflow behaviour. /// public class TextOverflowTestCase : TestCase { public TextOverflowTestCase(string name) : base(name) { } /// /// A box whose text fits, so the same rule that gave the six grid cells a tooltip declines to give this one. /// private void AddShortSample() { var shortBox = new Vector(300, 40); AddCaption("Short enough to fit, so it gets no tooltip"); TextMaterial material = Widgets.Paragraph("Nothing cut here.", Alignment.Vertical.Top, TextOverflow.Ellipsis); Panel label = material .BuildControl(Constraints.Tight(shortBox), out TextOverflow? truncation) .WrapIn(UiPacksheetMaterials.GreenFlatPanel, ContentAggregator.NewRow(shortBox.Y).TopLeft); if (truncation != null) { label.Tooltip = Widgets.WrappedTooltip("Nothing cut here.", shortBox.X); } Add(label); } protected override void Populate() { // Long enough to run to roughly twice the box, so vertically centred overflow loses its opening line // outright rather than just cropping it. const string paragraph = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud " + "exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."; // The half line is deliberate: it puts a partly visible line on show alongside the fully hidden ones, // which is the case the two overflow behaviours disagree about. The margins have to be added back on // top, since the renderer erodes them off the box before it works out how many lines fit. Scalar lineHeight = Fonts.Philosopher32.LineHeight; Scalar verticalMargin = Widgets.Paragraph("", Alignment.Vertical.Top, TextOverflow.Clip).VerticalMargin; var boxSize = new Vector(300, lineHeight * 5.5 + 2 * verticalMargin); var alignments = new[] { Alignment.Vertical.Top, Alignment.Vertical.Center, Alignment.Vertical.Bottom, }; var behaviours = new[] { TextOverflow.Clip, TextOverflow.Ellipsis }; foreach (TextOverflow behaviour in behaviours) { Rect row = ContentAggregator.NewRow(boxSize.Y + lineHeight + 4, margin: Gutter * 2); foreach (Alignment.Vertical alignment in alignments) { Rect cell = row.NewCol(boxSize.X, margin: 20); AddCaption($"{alignment} / {behaviour}", ref cell); TextMaterial material = Widgets.Paragraph(paragraph, alignment, behaviour); Panel label = material .BuildControl(Constraints.Tight(boxSize), out TextOverflow? truncation) .WrapIn(UiPacksheetMaterials.GreenFlatPanel, cell.TopLeft); // Every box on this tab is deliberately smaller than its text, so all six take the tooltip. // The check is here rather than assumed so the rule reads the same as it would anywhere else. if (truncation != null) { label.Tooltip = Widgets.WrappedTooltip(paragraph, boxSize.X); } Add(label); } } AddShortSample(); } } }