using Annulus; using Azimuth; namespace Glass.Testbed.TestCases.Text { /// /// 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 { /// /// 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"); var text = new Label(Widgets.ParagraphStyle(Alignment.Vertical.Top, TextOverflow.Ellipsis), "Nothing cut here.", Constraints.Tight(shortBox)); Panel label = text.WrapIn(UiPacksheetMaterials.GreenFlatPanel, ContentAggregator.NewRow(shortBox.Y).TopLeft); if (text.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.ParagraphStyle(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); var text = new Label(Widgets.ParagraphStyle(alignment, behaviour), paragraph, Constraints.Tight(boxSize)); Panel label = text.WrapIn(UiPacksheetMaterials.GreenFlatPanel, cell.TopLeft); // Every box in this case 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 (text.Truncation != null) { label.Tooltip = Widgets.WrappedTooltip(paragraph, boxSize.X); } Add(label); } } AddShortSample(); } } }