using Annulus;
using Azimuth;
using Clave;
using Glass.Markdown;
using System.Collections.Generic;
using Prism;
namespace Glass.Testbed.TestCases.Text
{
///
/// One Markdown document in two views of different widths, so the wrapping is easy to compare. The buttons under
/// each view scroll it to a heading.
///
public class MarkdownTestCase : TestCase
{
private const string Document = """
# Reading the grid
Everything in this document is Markdown, parsed into blocks and laid out down the width of the view.
Resize a view and the paragraphs wrap again. Inline marks such as **bold** and `code` are shown as
written until text can be styled in runs.
## Callouts
1. Play/Pause button - toggles the game between running and paused.
2. Step button - runs the game forward one tick.
12. Numbers are kept as written, so a callout can match a number drawn on a screenshot.
---
## Lists and pictures
- A bulleted item with enough text to wrap onto a second line when the view is narrow.
- Another item.

## Code
```
if (islanded)
{
Synchronize(generator, grid);
}
```
## The end
That is all of it. Scroll up with the wheel, or jump to a heading from the list.
""";
private static TextMaterialStyle Styled(SpriteFontDefinition font)
{
return new TextMaterialStyle { Font = font, TintColor = Colors.Black };
}
private static MarkdownStyle NewStyle()
{
return new MarkdownStyle
{
Body = Styled(Fonts.LiberationSans16),
Headings = new[] { Styled(Fonts.LiberationSansBold32), Styled(Fonts.LiberationSansBold16) },
Code = Styled(Fonts.LiberationMono16),
CodeBackground = new SolidColorMaterial { Color = Color.FromArgb(40, 0, 0, 0) },
Rule = new SolidColorMaterial { Color = Color.FromArgb(160, 0, 0, 0) },
BlockSpacing = 6,
Padding = 8,
};
}
private MarkdownView NewView(Scalar width, Scalar height)
{
var images = new Dictionary
{
["cursor.png"] = ResizeCursorMaterials.DiagonalNwSe with { LockAspectRatio = true },
};
var view = new MarkdownView(Document, NewStyle(), images);
view.ScrollViewMaterial = new ScrollViewMaterial
{
Background = Material.Invisible,
Canvas = UiPacksheetMaterials.GreenFlatPanel,
HorizontalScrollBar = UiPacksheetMaterials.HorizontalScrollBar,
VerticalScrollBar = UiPacksheetMaterials.VerticalScrollBar,
};
view.Bounds = Rect.FromPositionAndSize(Vector.Zero, new Vector(width, height));
return view;
}
private Button HeadingButton(MarkdownView view, int index)
{
Button returnMe = new Label(Widgets.ButtonLabelStyle, view.Headings[index].Text, Constraints.Unbounded)
.WrapIn(UiPacksheetMaterials.YellowButton, ButtonBehavior.Default);
returnMe.OnActivate += (ButtonBase _, in KeyboardSnapshot __, KeyboardManager ___) =>
view.ScrollToHeading(index);
return returnMe;
}
private List