bevy_vello icon indicating copy to clipboard operation
bevy_vello copied to clipboard

Enhancement: FontVariant and FontStyle applied to ranges

Open RobertBrewitz opened this issue 9 months ago • 6 comments

Parley has support for applying font styles and variants to sub-sections of text, e.g: "The quick brown fox jumps over the lazy dog"

How this would be exposed I am not sure, maybe something like "BB Code".

Depends on #130

RobertBrewitz avatar Mar 25 '25 10:03 RobertBrewitz

In Bevy I believe they model this with TextSpans, where each span can have a different style and they get computed together with other spans.

nuzzles avatar Mar 25 '25 13:03 nuzzles

We may need a higher-order container to do something like this. Thoughts @RobertBrewitz ?

Could be related to #51 and #50

struct VelloText {
   sections: Vec<VelloTextSection>
   layout: VelloTextLayout,
}

struct VelloTextLayout {
   line_break_behavior: LineBreakBehavior,
   text_justify: TextJustify,
   max_width: f32,
   ...
}

nuzzles avatar Mar 25 '25 13:03 nuzzles

I'll dig a little what the plan is for bevy_ui to get a little better informed myself.

RobertBrewitz avatar Mar 25 '25 19:03 RobertBrewitz

We may need a higher-order container to do something like this. Thoughts @RobertBrewitz ?

Could be related to #51 and #50

struct VelloText { sections: Vec<VelloTextSection> layout: VelloTextLayout, }

struct VelloTextLayout { line_break_behavior: LineBreakBehavior, text_justify: TextJustify, max_width: f32, ... }

I have been think about this on and off; Might it be better to just leverage the component relation/hierarchy API in Bevy, and not use our own Vec of text sections? My gut feeling is that it might be a bit unnecessary complexity to start managing our own Vec.

Rust/pseudo code:

fn bold_text(value: &str) -> Bundle {
  VelloTextSection {
    value,
    style: VelloFontStyle {
      weight: 900.,
      ..default()
    },
    ..default()
  }
}

fn text(value: &str) -> Bundle {
  VelloTextSection {
    value,
    ..default()
  }
}

fn spawn_text(mut cmd: Commands) {
  cmd.spawn(Transform::from_xyz(1.,1.,1.))
    .with_children(|parent| {
      parent.spawn(text("I have some normal text,"));
      parent.spawn(bold_text("and some bold text,"));
      parent.spawn(text("that I want to render"));
    });
}

RobertBrewitz avatar Mar 29 '25 20:03 RobertBrewitz

On second thought, I recall entity relationships not having deterministic ordering, in that case your suggestion is more sound.

RobertBrewitz avatar Mar 31 '25 07:03 RobertBrewitz

Yeah, furthermore I think a text_spans example could be added, since the current text example is good as is. Very happy with it!

nuzzles avatar Apr 02 '25 16:04 nuzzles