Skip to content

Commit

Permalink
Fix #5 rename box to trbl
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasp85 committed Apr 30, 2024
1 parent 4655db2 commit 1fe54de
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 75 deletions.
6 changes: 3 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
# Generated by roxygen2: do not edit by hand

S3method(format,marquee_box)
S3method(format,marquee_em)
S3method(format,marquee_relative)
S3method(format,marquee_rem)
S3method(format,marquee_skip_inherit)
S3method(format,marquee_style)
S3method(format,marquee_style_set)
S3method(format,marquee_trbl)
S3method(heightDetails,marquee_grob)
S3method(makeContent,marquee_grob)
S3method(makeContent,marquee_precalculated)
S3method(makeContent,svg_grob)
S3method(makeContext,marquee_grob)
S3method(makeContext,marquee_precalculated_grob)
S3method(print,marquee_box)
S3method(print,marquee_em)
S3method(print,marquee_relative)
S3method(print,marquee_rem)
S3method(print,marquee_skip_inherit)
S3method(print,marquee_style)
S3method(print,marquee_trbl)
S3method(str,marquee_style)
S3method(widthDetails,marquee_grob)
export(base_style)
export(box)
export(classic_style)
export(element_marquee)
export(em)
Expand All @@ -37,6 +36,7 @@ export(remove_style)
export(skip_inherit)
export(style)
export(style_set)
export(trbl)
import(grid)
import(rlang)
useDynLib(marquee, .registration = TRUE)
28 changes: 14 additions & 14 deletions R/classic_style.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ classic_style <- function(base_size = 12, body_font = "", header_font = "",
style_set(
base = base,
body = style(),
ul = style(padding = box(0, 0, 0, em(2)), background = NA, border = NA),
ol = style(padding = box(0, 0, 0, em(2)), background = NA, border = NA),
li = style(padding = box(0), background = NA, border = NA),
hr = style(padding = box(0, 0, 2), border = "#eeeeee", border_size = box(0, 0, 1)),
h1 = style(family = header_font, size = relative(2.25), weight = "bold", lineheight = 1.2, margin = box(em(1), NULL, NULL, NULL), padding = box(0, 0, em(0.3)), border = "#eeeeee", border_size = box(0, 0, 1)),
h2 = style(family = header_font, size = relative(1.75), weight = "bold", lineheight = 1.225, margin = box(em(1), NULL, NULL, NULL), padding = box(0, 0, em(0.3)), border = "#eeeeee", border_size = box(0, 0, 1)),
h3 = style(family = header_font, size = relative(1.5), weight = "bold", lineheight = 1.43, margin = box(em(1), NULL, NULL, NULL)),
h4 = style(family = header_font, size = relative(1.25), weight = "bold", lineheight = 1.4, margin = box(em(1), NULL, NULL, NULL)),
h5 = style(family = header_font, weight = "bold", lineheight = 1.4, margin = box(em(1), NULL, NULL, NULL)),
h6 = style(family = header_font, weight = "bold", lineheight = 1.4, margin = box(em(1), NULL, NULL, NULL), color = "#777777"),
cb = style(family = code_font, size = relative(0.85), lineheight = 1.45, padding = box(16), background = "#f7f7f7", border_radius = 3),
p = style(padding = box(0), background = NA, border = NA),
qb = style(color = "#777777", padding = box(em(0.2), 0, em(0.2), em(1)), border = "#dddddd", border_size = box(0, 0, 0, 4)),
ul = style(padding = trbl(0, 0, 0, em(2)), background = NA, border = NA),
ol = style(padding = trbl(0, 0, 0, em(2)), background = NA, border = NA),
li = style(padding = trbl(0), background = NA, border = NA),
hr = style(padding = trbl(0, 0, 2), border = "#eeeeee", border_size = trbl(0, 0, 1)),
h1 = style(family = header_font, size = relative(2.25), weight = "bold", lineheight = 1.2, margin = trbl(em(1), NULL, NULL, NULL), padding = trbl(0, 0, em(0.3)), border = "#eeeeee", border_size = trbl(0, 0, 1)),
h2 = style(family = header_font, size = relative(1.75), weight = "bold", lineheight = 1.225, margin = trbl(em(1), NULL, NULL, NULL), padding = trbl(0, 0, em(0.3)), border = "#eeeeee", border_size = trbl(0, 0, 1)),
h3 = style(family = header_font, size = relative(1.5), weight = "bold", lineheight = 1.43, margin = trbl(em(1), NULL, NULL, NULL)),
h4 = style(family = header_font, size = relative(1.25), weight = "bold", lineheight = 1.4, margin = trbl(em(1), NULL, NULL, NULL)),
h5 = style(family = header_font, weight = "bold", lineheight = 1.4, margin = trbl(em(1), NULL, NULL, NULL)),
h6 = style(family = header_font, weight = "bold", lineheight = 1.4, margin = trbl(em(1), NULL, NULL, NULL), color = "#777777"),
cb = style(family = code_font, size = relative(0.85), lineheight = 1.45, padding = trbl(16), background = "#f7f7f7", border_radius = 3),
p = style(padding = trbl(0), background = NA, border = NA),
qb = style(color = "#777777", padding = trbl(em(0.2), 0, em(0.2), em(1)), border = "#dddddd", border_size = trbl(0, 0, 0, 4)),
em = style(italic = TRUE),
str = style(weight = "bold"),
a = style(color = "#4078c0"),
code = style(family = code_font, size = relative(0.85), background = "#0000000A", padding = box(em(0.2), 0), border_radius = 3),
code = style(family = code_font, size = relative(0.85), background = "#0000000A", padding = trbl(em(0.2), 0), border_radius = 3),
u = style(underline = TRUE),
del = style(strikethrough = TRUE),
img = style(align = "center"),
Expand Down
2 changes: 1 addition & 1 deletion R/element_marquee.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ element_grob.element_marquee <- function(element, label = "", x = NULL, y = NULL
)
margin <- margin %||% element$margin
if (!is.null(margin)) {
pad <- skip_inherit(box(
pad <- skip_inherit(trbl(
if (margin_y) margin[1] else 0,
if (margin_x) margin[2] else 0,
if (margin_y) margin[3] else 0,
Expand Down
4 changes: 2 additions & 2 deletions R/geom_marquee.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
#' label_style <- modify_style(
#' classic_style(),
#' "body",
#' padding = skip_inherit(box(4)),
#' padding = skip_inherit(trbl(4)),
#' border = "black",
#' border_size = skip_inherit(box(1)),
#' border_size = skip_inherit(trbl(1)),
#' border_radius = 3
#' )
#' p + geom_marquee(aes(label = rownames(mtcars), fill = gear), style = label_style)
Expand Down
26 changes: 13 additions & 13 deletions R/style.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
#' parent hanging, [em()] in which case it is based on the font size in this
#' style, or [rem()] in which case it is based on the font size of the body
#' element.
#' @param margin The margin around the element, given as a call to [box()]
#' @param padding The padding around the element, given as a call to [box()]
#' @param margin The margin around the element, given as a call to [trbl()]
#' @param padding The padding around the element, given as a call to [trbl()]
#' @param background The color of the background fill. The background includes
#' the padding but not the margin. Can be a solid color or a gradient or pattern
#' made with `grid::linearGradient()`/`grid::radialGradient()`/`grid::pattern()`
#' @param border The color of the background stroke. The background includes
#' the padding but not the margin
#' @param border_size The line width of the background stroke, given as a call
#' to [box()]
#' to [trbl()]
#' @param border_radius The corner radius of the background, given in points
#' @param bullets A vector of strings to use for bullets in unordered lists.
#' `marquee_bullets` provides a selection
Expand Down Expand Up @@ -106,11 +106,11 @@ style <- function(family = NULL, weight = NULL, italic = NULL, width = NULL,

if (!is_modifier(hanging)) check_number_decimal(hanging, allow_null = TRUE)

if (is.null(margin)) margin <- box()
if (!is_box(margin)) stop_input_type(margin, "a marquee_box object", allow_null = TRUE)
if (is.null(margin)) margin <- trbl()
if (!is_trbl(margin)) stop_input_type(margin, "a marquee_trbl object", allow_null = TRUE)

if (is.null(padding)) padding <- box()
if (!is_box(padding)) stop_input_type(padding, "a marquee_box object", allow_null = TRUE)
if (is.null(padding)) padding <- trbl()
if (!is_trbl(padding)) stop_input_type(padding, "a marquee_trbl object", allow_null = TRUE)

if (!inherits(background, "GridPattern")) {
check_string(unclass(background), allow_null = TRUE, allow_na = TRUE)
Expand All @@ -120,8 +120,8 @@ style <- function(family = NULL, weight = NULL, italic = NULL, width = NULL,
check_string(border, allow_null = TRUE, allow_na = TRUE)
if (!is.null(border) && is.na(border)) border[] <- NA_character_

if (is.null(border_size)) border_size <- box()
if (!is_box(border_size)) stop_input_type(border_size, "a marquee_box object", allow_null = TRUE)
if (is.null(border_size)) border_size <- trbl()
if (!is_trbl(border_size)) stop_input_type(border_size, "a marquee_trbl object", allow_null = TRUE)

if (!is_modifier(border_radius)) check_number_decimal(border_radius, allow_null = TRUE)

Expand Down Expand Up @@ -208,10 +208,10 @@ base_style <- function(family = "", weight = "normal", italic = FALSE,
width = "normal", features = systemfonts::font_feature(),
size = 12, color = "black", lineheight = 1.6,
align = "left", tracking = 0, indent = 0, hanging = 0,
margin = box(0, 0, rem(1)), padding = box(0), background = NA,
border = NA, border_size = box(0), border_radius = 0,
bullets = marquee_bullets, underline = FALSE,
strikethrough = FALSE, img_asp = 1.65) {
margin = trbl(0, 0, rem(1)), padding = trbl(0),
background = NA, border = NA, border_size = trbl(0),
border_radius = 0, bullets = marquee_bullets,
underline = FALSE, strikethrough = FALSE, img_asp = 1.65) {
style(
family = family,
weight = weight,
Expand Down
32 changes: 17 additions & 15 deletions R/style_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
#' relative to the font size of the current style. If the font size is `12`, and
#' indent is set to `em(2)`, then the indent will be equivalent to 24. `rem()`
#' works like `em()` but rather than using the font size of the current style it
#' uses the font size of the root style (which is the body element). `box()`
#' helps you construct styles that refers to sides of a box (margin, padding,
#' and border size). `skip_inherit()` tells the style inheritance to ignore this
#' value and look for the value one above in the stack. `marquee_bullets` is
#' just a character vector with 6 sensible bullet glyphs for unordered lists.
#' uses the font size of the root style (which is the body element). `trbl()`
#' helps you construct styles that refers to sides of a rectangle (margin,
#' padding, and border size). The function names refers to the order of the
#' arguments (top, right, bottom, left). `skip_inherit()` tells the style
#' inheritance to ignore this value and look for the value one above in the
#' stack. `marquee_bullets` is just a character vector with 6 sensible bullet
#' glyphs for unordered lists.
#'
#' @param x A decimal number. If a vector is provided only the first element
#' will be used
#' @param top,right,bottom,left Values for the sides of the box. Either numbers
#' or modifiers (relative, em, or rem)
#' @param top,right,bottom,left Values for the sides of the rectangles. Either
#' numbers or modifiers (relative, em, or rem)
#'
#' @return Objects of the relevant class
#'
Expand All @@ -31,7 +33,7 @@
#' rem(1.2)
#'
#' # Argument default means it recycles like CSS if fewer values are specified
#' box(6, em(1.5))
#' trbl(6, em(1.5))
#'
#' skip_inherit("sans")
#'
Expand Down Expand Up @@ -88,32 +90,32 @@ is_modifier <- function(x) inherits(x, c("marquee_relative", "marquee_em", "marq

#' @rdname style_helpers
#' @export
box <- function(top = NULL, right = top, bottom = top, left = right) {
trbl <- function(top = NULL, right = top, bottom = top, left = right) {
if (!is.null(top) && !is_modifier(top)) check_number_decimal(top, allow_null = TRUE)
if (!is.null(right) && !is_modifier(right)) check_number_decimal(right, allow_null = TRUE)
if (!is.null(bottom) && !is_modifier(bottom)) check_number_decimal(bottom)
if (!is.null(left) && !is_modifier(left)) check_number_decimal(left, allow_null = TRUE)
structure(list(top, right, bottom, left), class = "marquee_box")
structure(list(top, right, bottom, left), class = "marquee_trbl")
}

is_box <- function(x) inherits(x, "marquee_box")
is_trbl <- function(x) inherits(x, "marquee_trbl")

#' @export
format.marquee_box <- function(x, ...) {
format.marquee_trbl <- function(x, ...) {
paste0(c(" top: ", " right: ", "bottom: ", " left: "), vapply(x, format, character(1), ...))
}

#' @export
print.marquee_box <- function(x, ...) {
cat("A marquee box\n")
print.marquee_trbl <- function(x, ...) {
cat("A marquee trbl\n")
cat(format(x, ...), sep = "\n")
invisible(NULL)
}

#' @rdname style_helpers
#' @export
skip_inherit <- function(x) {
if (is_box(x)) x[] <- lapply(x[], skip_inherit)
if (is_trbl(x)) x[] <- lapply(x[], skip_inherit)
else class(x) <- c("marquee_skip_inherit", class(x))
x
}
Expand Down
2 changes: 1 addition & 1 deletion R/style_set.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ modify_style <- function(style_set, tag, ...) {
for (i in seq_along(opts)) {
opt <- opts[[i]]
if (is.null(opt) || is_style(opt) || is_modifier(opt) ||
is_box(opt) || inherits(opt, "marquee_skip_inherit") ||
is_trbl(opt) || inherits(opt, "marquee_skip_inherit") ||
inherits(opt, "font_feature") || inherits(opt, "GridPattern")) {
opt <- list(opt)
}
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ grob based on markdown text and a style that can be rendered with grid:
readme <- paste(readLines("README.Rmd")[-seq_len(17)], collapse = "\n")

library(marquee)
#>
#> Attaching package: 'marquee'
#> The following object is masked from 'package:graphics':
#>
#> box
library(grid)

fancy_style <- classic_style(
Expand Down
6 changes: 3 additions & 3 deletions man/classic_style.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified man/figures/README-unnamed-chunk-2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions man/geom_marquee.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions man/style.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions man/style_helpers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1fe54de

Please sign in to comment.