This is a demo implementation of MeasurableFont. The expectation is more often that you'd use a arsd.simpledisplay.OperatingSystemFont, which also implements this interface, but if you wanted to do your own thing this basic demo might help.
Represents the style of a span of text.
A selection has four pieces:
You use it by creating a TextLayouter and populating it with some data. Then you connect it to a user interface which calls TextLayouter.getDrawableText to know what and where to display the content and manipulates the content through the Selection object. Your text has styles applied to it through a TextStyle interface, which is deliberately minimal for the layouter - you are expected to cast it back to your implementation as-needed to get your other data out.
See the docs on each of those objects for more details.
BiDi and right-to-left text in general is not yet implemented. I'm pretty sure I can do it, but I need unicode tables that aren't available to arsd yet.
Doesn't do text kerning since the other implementations I've looked at on-screen don't do it either so it seems unnecessary. I might revisit this.
Also doesn't handle shaped text, which breaks click point detection on Windows for certain script families.
The edit implementation is a simple string. It performs surprisingly well, but I'll probably go back to it and change to a gap buffer later.
Relaying out and saving state is only partially incremental at this time.
The main interfaces are written with eventually fixing these in mind, but I might have to extend the MeasurableFont and TextStyle interfaces, and it might need some helper objects injected too. So possible they will be small breaking changes to support these, but I'm pretty sure it won't require any major rewrites of the code nor of user code when these are added, just adding methods to interfaces.
Written in December 2022. Released in arsd 11.0.
A homemade text layout and editing engine, designed for the needs of minigui's custom widgets to be good enough for me to use. May or may not work for you.