Skip to content

Commit

Permalink
refactor: remove self.padding and add self.full-header (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
OrangeX4 authored Apr 4, 2024
1 parent 3c06ca1 commit 9851442
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 32 deletions.
60 changes: 48 additions & 12 deletions slide.typ
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,43 @@
return (result-arr, max-repetitions)
}

#let _get-negative-pad(self) = {
let margin = self.page-args.margin
if type(margin) != dictionary and type(margin) != length and type(margin) != relative {
return it => it
}
let cell = block.with(width: 100%, height: 100%, above: 0pt, below: 0pt, breakable: false)
if type(margin) == length or type(margin) == relative {
return it => pad(x: -margin, cell(it))
}
let pad-args = (:)
if "x" in margin {
pad-args.x = -margin.x
}
if "left" in margin {
pad-args.left = -margin.left
}
if "right" in margin {
pad-args.right = -margin.right
}
if "rest" in margin {
pad-args.rest = -margin.rest
}
it => pad(..pad-args, cell(it))
}

#let _get-header-footer(self) = {
let header = utils.call-or-display(self, self.page-args.at("header", default: none))
let footer = utils.call-or-display(self, self.page-args.at("footer", default: none))
if self.full-header or self.full-footer {
let negative-pad = _get-negative-pad(self)
if self.full-header {
header = negative-pad(header)
}
if self.full-footer {
footer = negative-pad(footer)
}
}
(header, footer)
}

Expand All @@ -341,9 +375,6 @@
..bodies,
) = {
assert(bodies.named().len() == 0, message: "unexpected named arguments:" + repr(bodies.named().keys()))
let setting-with-pad(body) = {
pad(..self.padding, setting(body))
}
let composer-with-side-by-side(..args) = {
if type(composer) == function {
composer(..args)
Expand Down Expand Up @@ -407,19 +438,21 @@
if repeat == none {
return {
header = _update-states(1) + header
page(..(self.page-args + (header: header, footer: footer)), setting-with-pad(
set page(..(self.page-args + (header: header, footer: footer)))
setting(
page-preamble(1) + composer-with-side-by-side(..bodies)
))
)
}
}

if self.handout {
self.subslide = repeat
let (conts, _) = _parse-content(self: self, index: repeat, ..bodies)
header = _update-states(1) + header
page(..(self.page-args + (header: header, footer: footer)), setting-with-pad(
set page(..(self.page-args + (header: header, footer: footer)))
setting(
page-preamble(1) + composer-with-side-by-side(..conts)
))
)
} else {
// render all the subslides
let result = ()
Expand All @@ -433,10 +466,10 @@
if i == 1 {
new-header = _update-states(repeat) + new-header
}
result.push(page(
..(self.page-args + (header: new-header, footer: footer)),
setting-with-pad(page-preamble(i) + composer-with-side-by-side(..conts)),
))
result.push({
set page(..(self.page-args + (header: new-header, footer: footer)))
setting(page-preamble(i) + composer-with-side-by-side(..conts))
})
}
// return the result
result.sum()
Expand Down Expand Up @@ -593,8 +626,11 @@
header: none,
footer: none,
fill: rgb("#ffffff"),
margin: (x: 7%, y: 12%),
),
padding: (x: 0em, y: 0em),
// full header / footer
full-header: true,
full-footer: true,
// datetime format
datetime-format: auto,
// register the methods
Expand Down
17 changes: 10 additions & 7 deletions themes/aqua.typ
Original file line number Diff line number Diff line change
Expand Up @@ -194,23 +194,26 @@
circle(radius: 13pt, fill: white))
}
let header(self) = {
place(center + top, dy: 45%,
rect(width: 100%, height: 100%, fill: self.colors.primary))
place(left + top, line(start: (30%, 30%), end: (27%, 200%), stroke: 7pt + white))
place(left + bottom, dx: 4%, dy: 15%,
text(fill:white, self.aqua-title))
place(center + top, dy: .5em,
rect(
width: 100%,
height: 1.8em,
fill: self.colors.primary,
align(left + horizon, h(1.5em) + text(fill:white, self.aqua-title))
)
)
place(left + top, line(start: (30%, 0%), end: (27%, 100%), stroke: .5em + white))
}
let footer(self) = {
set text(size: 0.8em)
place(right, dx: -5%, utils.call-or-display(self, self.aqua-footer))
}
self.page-args += (
paper: "presentation-" + aspect-ratio,
margin: (x: 0em, top: 10%, bottom: 10%),
margin: (x: 2em, top: 3.5em, bottom: 2em),
header: header,
footer: footer,
)
self.padding += (x: 5%, top: 7%)
self.methods.init = (self: none, body) => {
set text(size: 20pt)
body
Expand Down
7 changes: 3 additions & 4 deletions themes/dewdrop.typ
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,12 @@
header-ascent: 0em,
footer-descent: 0em,
) + if navigation == "sidebar" {(
margin: (top: 2em, bottom: 1em, x: 0em),
margin: (top: 2em, bottom: 1em, x: sidebar.width),
)} else if navigation == "mini-slides" {(
margin: (top: mini-slides.height, bottom: 2em, x: 0em),
margin: (top: mini-slides.height, bottom: 2em, x: mini-slides.x),
)} else {(
margin: (top: 2em, bottom: 2em, x: 0em),
margin: (top: 2em, bottom: 2em, x: mini-slides.x),
)}
self.padding = (x: if navigation == "sidebar" { sidebar.width } else { mini-slides.x }, y: 0em)
// register methods
self.methods.slide = slide
self.methods.title-slide = title-slide
Expand Down
3 changes: 1 addition & 2 deletions themes/metropolis.typ
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,8 @@
footer: footer,
header-ascent: 30%,
footer-descent: 30%,
margin: (top: 3em, bottom: 1.5em, x: 0em),
margin: (top: 3em, bottom: 1.5em, x: 2em),
)
self.padding = (x: 2em, y: 0em)
// register methods
self.methods.slide = slide
self.methods.title-slide = title-slide
Expand Down
6 changes: 4 additions & 2 deletions themes/simple.typ
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}

#let centered-slide(self: none, section: none, ..args) = {
self = utils.empty-page(self)
self = utils.empty-page(self, margin: none)
(self.methods.touying-slide)(self: self, repeat: none, section: section, ..args.named(),
align(center + horizon, if section != none { heading(level: 1, utils.unify-section(section).title) } + args.pos().sum(default: []))
)
Expand All @@ -33,7 +33,7 @@
}

#let focus-slide(self: none, background: auto, foreground: white, body) = {
self = utils.empty-page(self)
self = utils.empty-page(self, margin: none)
self.page-args.fill = if background == auto { self.colors.primary } else { background }
set text(fill: foreground, size: 1.5em)
centered-slide(self: self, align(center + horizon, body))
Expand Down Expand Up @@ -75,6 +75,8 @@
footer-descent: 1em,
header-ascent: 1em,
)
self.full-header = false
self.full-footer = false
// register methods
self.methods.slide = slide
self.methods.title-slide = title-slide
Expand Down
3 changes: 1 addition & 2 deletions themes/university.typ
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,8 @@
footer: footer,
header-ascent: 0em,
footer-descent: 0em,
margin: (top: 2.5em, bottom: 1em, x: 0em),
margin: (top: 2.5em, bottom: 1em, x: 2em),
)
self.padding = (x: 2em, y: 0em)
// register methods
self.methods.slide = slide
self.methods.title-slide = title-slide
Expand Down
7 changes: 4 additions & 3 deletions utils/utils.typ
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
}

// OOP: empty page
#let empty-page(self) = {
#let empty-page(self, margin: (x: 0em, y: 0em)) = {
self.page-args += (
header: none,
footer: none,
margin: (x: 0em, y: 0em),
)
self.padding = (x: 0em, y: 0em)
if margin != none {
self.page-args += (margin: margin)
}
self
}

Expand Down

0 comments on commit 9851442

Please sign in to comment.