Skip to content

Commit 9ba97e9

Browse files
committed
Fix force_body_margin
1 parent 584fbbe commit 9ba97e9

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* Fixed a bug when calculating em() of a relative sized style
44
* Fixed a bug in outline glyphs
5+
* Fixed a bug in `force_body_margin`
56

67
# marquee 1.2.0
78

R/grob.R

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ marquee_grob <- function(
277277
collapsed_margins,
278278
has_background,
279279
has_top,
280-
has_bottom
280+
has_bottom,
281+
if (force_body_margin) 0 else NULL
281282
)
282283
}
283284
# Body margin wins over any collapsing
@@ -1373,15 +1374,17 @@ get_last <- function(tree, background, border) {
13731374
tree$element
13741375
}
13751376
}
1376-
set_margins <- function(tree, margins, has_background, has_top, has_bottom) {
1377+
set_margins <- function(tree, margins, has_background, has_top, has_bottom, forced_margin = NULL) {
13771378
tops <- get_first(tree, has_background, has_top)
1378-
margins$top[tops[1]] <- max(margins$top[tops])
1379+
margins$top[tops[1]] <- forced_margin %||% max(margins$top[tops])
13791380
margins$top[tops[-1]] <- 0
13801381
bottoms <- get_last(tree, has_background, has_top)
1381-
margins$bottom[bottoms[1]] <- max(margins$bottom[bottoms])
1382+
margins$bottom[bottoms[1]] <- forced_margin %||% max(margins$bottom[bottoms])
13821383
margins$bottom[bottoms[-1]] <- 0
1383-
for (child in tree$children) {
1384-
margins <- set_margins(child, margins, has_background, has_top, has_bottom)
1384+
for (i in seq_along(tree$children)) {
1385+
child <- tree$children[[i]]
1386+
is_last <- i == length(tree$children)
1387+
margins <- set_margins(child, margins, has_background, has_top, has_bottom, if (is_last) forced_margin else NULL)
13851388
}
13861389
for (i in seq_along(tree$children)[-1]) {
13871390
margins$bottom[tree$children[[i - 1]]$element] <- max(

0 commit comments

Comments
 (0)