On Friday, 8 November 2024 at 21:13:19 UTC, IchorDev wrote:
That’s a tricky one!
I was thinking that an API to add shapes that the text ‘goes around’. The shape type would be a sumtype of different shapes, probably stored in an optimisation structure like a tree. But what if you want an *inline* rectangle that will move depending on the text layout? For that case we *could* ask that the user just get the position that the text ends, place their element manually, and then use a second layout object, with the first line set to start after the end of the element. I acknowledge that’s a lot of work on the user end, but I’d argue that it’s an obscure (and frankly absurd) use-case, and requires a lot of implementation-specific decisions that make it impossible to account for everyone’s needs with our own implementation. Can the rectangle overflow the margins at the end of a line, or does it wrap? How is the line with the inline rectangle on it vertically aligned? How and when can shapes intersect with text if at all?

Measurement and rendering uses the `TextRuler` struct (frankly more important than the Fluid-centric `StyledText` one we keep discussing), which I hope to keep super simple so it can be easily manipulated by the user. It keeps track of the pen position and text size.

The idea is `TextRuler` is fed pieces of unbreakable content ("words") which may be text, but it can be anything of known width. A textual word would be first measured and then placed in the ruler to place it in the correct spot in the text.

Whatever manipulates the ruler, like the `Text` struct, could handle other pieces through a hook that would run between words. I imagine it would have a signature like `void delegate(ref TextRuler, WordSize)`. `inline-block`-like content (images, buttons, etc.) would increase line height and add a single "word" both matching the image's size. `inline` elements could add multiple words. `float` content could be simulated by inserting a word on every line at its supposed location, and thus would even support non-rectangular elements anywhere within the line.

I'm not sure yet when to move the engine into its own project, but I would like to have this ability in Fluid soon; I thought I would let you know about this idea.

As for `TextRulerCache` I mentioned earlier, I'm almost sure I've ironed out all the quirks and bugs. I think it's OK now, but certainly coding a pretty weird and complex data structure while having a fever wasn't my brightest idea.
        • ... cookiewitch via Digitalmars-d-announce
  • Re: Fluid 0.7... IchorDev via Digitalmars-d-announce
    • Re: Flui... cookiewitch via Digitalmars-d-announce
      • Re: ... IchorDev via Digitalmars-d-announce
        • ... cookiewitch via Digitalmars-d-announce
          • ... IchorDev via Digitalmars-d-announce
            • ... cookiewitch via Digitalmars-d-announce
              • ... IchorDev via Digitalmars-d-announce
              • ... cookiewitch via Digitalmars-d-announce
              • ... IchorDev via Digitalmars-d-announce
              • ... cookiewitch via Digitalmars-d-announce
              • ... IchorDev via Digitalmars-d-announce
              • ... claptrap via Digitalmars-d-announce
              • ... cookiewitch via Digitalmars-d-announce
              • ... IchorDev via Digitalmars-d-announce
              • ... cookiewitch via Digitalmars-d-announce
              • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-announce
              • ... IchorDev via Digitalmars-d-announce
  • Re: Fluid 0.7... cookiewitch via Digitalmars-d-announce

Reply via email to