Skip to content

Commit 4d85eca

Browse files
committed
allow for numeric face
1 parent 39303f5 commit 4d85eca

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

R/properties.R

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,31 @@ property_choice <- function(options, allow_null = FALSE, default = NULL) {
3737
)
3838
}
3939

40+
# This is like `property_choice`, but allows for integers that mean `1 = plain`,
41+
# `2 = bold`, `3 = italic`, `4 = bold italic`.
42+
property_fontface <- function(allow_null = TRUE, default = NULL) {
43+
options <- c("plain", "bold", "italic", "oblique", "bold.italic")
44+
class <- S7::new_union(S7::class_character, S7::class_numeric)
45+
class <- if (allow_null) S7::new_union(class, NULL) else class
46+
validator <- function(value) {
47+
if (allow_null && is.null(value)) {
48+
return(character())
49+
}
50+
if (is_integerish(value) && value %in% 1:4) {
51+
return(character())
52+
}
53+
if (value %in% options) {
54+
return(character())
55+
}
56+
as_cli("must be one of {.or {.val {options}}}.")
57+
}
58+
S7::new_property(
59+
class = class,
60+
validator = validator,
61+
default = NULL
62+
)
63+
}
64+
4065
property_nullable <- function(class = S7::class_any, ...) {
4166
S7::new_property(
4267
class = S7::new_union(NULL, class),

R/theme-elements.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ element_props <- list(
112112
size = property_nullable(S7::class_numeric),
113113
lineheight = property_nullable(S7::class_numeric),
114114
margin = property_nullable(margin),
115-
face = property_choice(c("plain", "bold", "italic", "oblique", "bold.italic"), allow_null = TRUE),
115+
face = property_fontface(allow_null = TRUE),
116116
linewidth = property_nullable(S7::class_numeric),
117117
linetype = property_nullable(S7::class_numeric | S7::class_character),
118118
lineend = property_choice(c("round", "butt", "square"), allow_null = TRUE),

0 commit comments

Comments
 (0)