itwinjs-core icon indicating copy to clipboard operation
itwinjs-core copied to clipboard

TextBlockComponent children should implicitly inherit style and styleOverrides from parent TextBlockComponents

Open Alfonso-Martello opened this issue 9 months ago • 2 comments

Describe the bug TextBlockComponents (TextBlocks, Paragraphs, and Runs) all specify a style and can optionally specify styleOverrides. However, only the style on the RunLayout is used to create geometry. That style is a combination of the style/overrides on the Run and a subset of block level settings from the TextBlock. This means if you want to apply a style to a TextBlock or a Paragraph, you must apply the styling to each child Run.

This leads to confusion when a TextStyleSetting is set on a TextBlock, but it does not apply to the TextBlock’s Runs. It also leads to forced repetition. If you want to apply a style to an entire TextBlock, you must repeat that same style on each Run.

To Reproduce Steps to reproduce the behavior:

  1. Create an empty TextBlock.
  2. Set a fontName in the style overrides of the TextBlock.
  3. Create a TextRun without setting a fontName in the Run's styleOverrides. Include some text content like “Hello World”.
  4. Append the TextRun to the TextBlock.
  5. Create a TextAnnotation using the TextBlock.
  6. Produce geometry for the TextAnnotation.
  7. Observe that the text content “Hello World” does not render, because the font in the TextBlock’s override never made it into the RunLayout’s style.

Expected behavior Styles set on a TextBlockComponent should apply to its children, unless the child provides its own style/overrides. So TextBlock styles should apply to all child Paragraphs, and Paragraph styles should apply to all child Runs. Ideally, this should happen implicitly, so that you do not need to repeat the style nor overrides in the child classes.

Alfonso-Martello avatar Jun 04 '25 19:06 Alfonso-Martello

Expected behavior Styles set on a TextBlockComponent should apply to its children, unless the child provides its own style/overrides.

Do you agree with the following more comprehensive definition?

  • If a child specifies a style Id, then none of the parent's styling (including overrides) apply to the child, even if the parent and child specify the same style Id. It effectively resets all styling (similar to how specifying a subcategory Id in a geometry stream resets all appearance modifiers).
  • Otherwise:
    • The child uses the same style Id as the parent.
    • Each style property overridden or inherited by the parent is also applied to the child, unless the child explicitly provides its own override for that property.

Are you asking someone to implement this or planning to implement it yourself?

pmconne avatar Jun 05 '25 09:06 pmconne

Yes, I agree with the more comprehensive definition. Thank you for putting that together!

There has been some discussion within the Drawing Production team about whether we need to reference styles from paragraphs and runs, or if we can simply treat every style change as an override to the style specified in the text block. However, this feels more like a UX/application-level decision to me, so I plan to preserve the style property on those classes and implement things in accordance with your definition.

I am planning to implement it myself (hence why I assigned myself)

Alfonso-Martello avatar Jun 05 '25 20:06 Alfonso-Martello