Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block title_style is not rendered #349

Closed
joshka opened this issue Jul 27, 2023 · 0 comments · Fixed by #363
Closed

Block title_style is not rendered #349

joshka opened this issue Jul 27, 2023 · 0 comments · Fixed by #363
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@joshka
Copy link
Member

joshka commented Jul 27, 2023

Description

In the recent PR to support multiple titles, we accidentally made title_style no longer effective. It's useful to have this as a fallback style as it makes it easy to apply a style to all titles except one:
e.g.

Block::new()
  .title_style(Style::new().bold())
  .title(Title::from("foo").alignment(Alignment::Left))
  .title(Title::from("bar").alignment(Alignment::Center))
  .title(Title::from("foo".not_bold().dim()).alignment(Alignment::Right))

To Reproduce

    frame.render_widget(
        Block::new()
            .borders(Borders::all())
            .title("Styled Title")
            .title_style(Style::new().yellow()),
        area1,
    );
    frame.render_widget(
        Block::new()
            .borders(Borders::all())
            .title(Title::from(Line::styled(
                "Styled Line",
                Style::new().yellow(),
            ))),
        area 2,
    );

Expected behavior

The Block's title style should be applied to the title.
The order which styles should effect the title (later styles should override earlier):

  1. Any style applied to the surrounding area
  2. Block.style
  3. Block.border_style
  4. Block.title_style - this is the missing piece
  5. Title.content.style (Line.style): Out of scope for this issue as Line currently doesn't have a style, but should
  6. Title.content.spans -> Span.style

Screenshots

image

Environment

  • OS: Mac
  • Terminal Emulator: iterm2
  • Font: FiraCode NF
  • Crate version: 0.22
  • Backend: crossterm

Additional context

This is the code that needs to be modified for this:

buf.set_line(
title_x + area.left(),
self.get_title_y(position, area),
&title.content,
title_area_width,
);

buf.set_line(
title_x + area.left(),
self.get_title_y(position, area),
&title.content,
title_area_width,
);

buf.set_line(
area.width.saturating_sub(title_x) + area.left(),
self.get_title_y(position, area),
&title.content,
title_area_width,
);

There's a simple ways to approach this (just create a new line from the old line with the appropriate title_style applied before the line's style).

There's also a more complex fix for this that changes the way line style is stored / rendered so that line style overrides can be consistently handled by any widget. If you decide to implement the complex approach, please implement the simple approach first so there is tests for the intended behavior, and discuss the API changes for this prior to implementation as this likely requires changes to the public api of ratatui.

@joshka joshka added bug Something isn't working good first issue Good for newcomers labels Jul 27, 2023
Valentin271 added a commit to Valentin271/ratatui that referenced this issue Aug 3, 2023
Valentin271 added a commit to Valentin271/ratatui that referenced this issue Aug 3, 2023
Valentin271 added a commit to Valentin271/ratatui that referenced this issue Aug 3, 2023
Valentin271 added a commit to Valentin271/ratatui that referenced this issue Aug 3, 2023
Valentin271 added a commit to Valentin271/ratatui that referenced this issue Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant