Skip to content

Feature request: include a bordered, 'label'-ish style in standard style set #93

Closed

Description

@teunbrand

Essentially, I'd wish it were easier to draw a box around a phrase (like ggplot2::geom_label()).
Here is a style I'm proposing to include (perhaps a better name may be needed):

library(marquee)
library(grid)

style <- classic_style() |>
  modify_style(
    "button", 
    border = "black", 
    border_width = trbl(1), 
    border_radius = em(0.25),
    padding = trbl(em(0.1))
  )

g <- marquee_grob(
  "This is a {.button button} word",
  x = 0.5, y = 0.5, hjust = 0.5, width = NA,
  style = style
)
grid.newpage()
grid.draw(g)

As an aside, I don't think the horizontal spacing between words with padding is in sync with where borders are drawn. This is noticible when the padding is exaggerated.

g <- marquee_grob(
  "This is a {.button button} word",
  x = 0.5, y = 0.5, hjust = 0.5, width = NA,
  style = style |>
    modify_style("button", padding = trbl(10))
)
grid.newpage()
grid.draw(g)

Created on 2025-09-26 with reprex v2.1.1

Activity

  1. clauswilke commented on Sep 26, 2025

    @clauswilke
    Contributor

    I think this is a great idea. One thing to keep in mind, and why rendering this is non-trivial: The span that you want to enclose in a box can run over more than a single line. So then you need to think about drawing only the left part or only the right part of a box.

    Here is a quick example of how web browsers handle this: https://jsfiddle.net/7dbeL30g/1

  2. teunbrand commented on Sep 26, 2025

    @teunbrand
    ContributorAuthor

    So if we linebreak in the middle of the box span, browsers will display a box without a right border on the top line, and a box without left border on the bottom line. This is the snippet I used in the widget Claus linked:

    The quick brown fox jumps over the lazy dog.
    <span class="box">The quick brown <br>
      fox jumps over the lazy dog.</span>
    The quick brown fox jumps over the lazy dog.

    Which renders like so:

    Image

    marquee_grob() just draws two full-bordered boxes around the two parts, which I think is fine too as marquee isn't aiming to be/implement html.

    Details
    library(marquee)
    library(grid)
    
    style <- classic_style() |>
      modify_style(
        "button", 
        border = "black", 
        border_width = trbl(1), 
        border_radius = em(0.25),
        padding = trbl(em(0.1))
      )
    
    g <- marquee_grob(
      "The quick brown fox jumps over the lazy dog.
      {.button The quick brown  \n fox jumps over the lazy dog.}
      The quick brown fox jumps over the lazy dog.",
      x = 0.5, y = 0.5, hjust = 0.5, width = NA,
      style = style
    )
    grid.newpage()
    grid.draw(g)

    Created on 2025-09-26 with reprex v2.1.1

  3. clauswilke commented on Sep 26, 2025

    @clauswilke
    Contributor

    Oh, apologies, I misunderstood. I didn't realize marquee already can draw borders. Yes, I guess it's fine if it does it differently from HTML.

  4. teunbrand commented on Sep 26, 2025

    @teunbrand
    ContributorAuthor

    I didn't realize marquee already can draw borders.

    This feature request is merely a suggestion to make borders more accessible.

  5. added a commit that references this issue on Nov 11, 2026
    5f7f837
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions