Skip to content

Conversation

@ickshonpe
Copy link
Contributor

@ickshonpe ickshonpe commented Jan 20, 2026

Objective

Add support for responsive font sizes supporting rem and viewport units.

Solution

The font_size field of TextFont is now a FontSize.

New FontSize enum:

pub enum FontSize {
    /// Font Size in logical pixels.
    Px(f32),
    /// Font size as a percentage of the viewport width.
    Vw(f32),
    /// Font size as a percentage of the viewport height.
    Vh(f32),
    /// Font size as a percentage of the smaller of the viewport width and height.
    VMin(f32),
    /// Font size as a percentage of the larger of the viewport width and height.
    VMax(f32),
    /// Font Size relative to the value of the `RemSize` resource.
    Rem(f32),
}

FontSize has an eval method that takes viewport and rem values and resolves the actual logical font size.

The text implementations have to pass in the viewport and rem values to TextPipeline's update_buffer and create_text_measure functions, so the font sizes can be evaluated.

Text2d uses the size of the primary window to resolve viewport values (or Vec2::splat(1000) if no primary window found).

There are some limitations because we don't have any sort of font style inheritance yet:

  • FontSize values are only reevaluated on changes to TextFont atm, not on changes to the viewport and rem base values.
  • Rem units aren't really rem units, and just based on the value of a resource.
  • No support for em units.

Testing

The examples should work, but bound to be mistakes as there are so many changes.

The text example has some text that has size in Vh units.

@ickshonpe ickshonpe added C-Feature A new feature, making something new possible A-UI Graphical user interfaces, styles, layouts, and widgets A-Text Rendering and layout for characters M-Deliberate-Rendering-Change An intentional change to how tests and examples are rendered labels Jan 20, 2026
@alice-i-cecile alice-i-cecile added M-Release-Note Work that should be called out in the blog due to impact S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 20, 2026
@ickshonpe ickshonpe added the D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes label Jan 20, 2026
@mnmaita
Copy link
Member

mnmaita commented Jan 21, 2026

Wondering if this PR supersedes #9524?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Text Rendering and layout for characters A-UI Graphical user interfaces, styles, layouts, and widgets C-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes M-Deliberate-Rendering-Change An intentional change to how tests and examples are rendered M-Release-Note Work that should be called out in the blog due to impact S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants