From e9cd7b41c29183070d0c01743eec729fc0f8eea3 Mon Sep 17 00:00:00 2001 From: Schrottkatze Date: Sun, 16 Feb 2025 22:50:01 +0100 Subject: [PATCH] init --- .gitignore | 1 + präsi-test.typ | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib.typ | 30 ++++++++++++++++++ test.typ | 18 +++++++++++ 4 files changed, 132 insertions(+) create mode 100644 .gitignore create mode 100644 präsi-test.typ create mode 100644 src/lib.typ create mode 100644 test.typ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f08278d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pdf \ No newline at end of file diff --git a/präsi-test.typ b/präsi-test.typ new file mode 100644 index 0000000..d12abab --- /dev/null +++ b/präsi-test.typ @@ -0,0 +1,83 @@ +#let pgcounter = context [ + real page: #here().page() / #counter(page).final().first() +]; +#set page( + paper: "presentation-16-9", + fill: rgb("222"), + footer: align(center, pgcounter), +) +#set text(fill: white) + +#let s_topic = state("topic", (color: red)); +#let seite(n) = [#page( + background: context { + import "@preview/cetz:0.3.2" + + let pages = query(selector().before(query(selector().after(here())).first().location())) + let last = counter().final().first() + let size = 100 / last + + [ + #place( + bottom + left, + stack(dir: ltr, ..pages.map(pg => { + let seg_start = ((counter().at(pg.location()).first() + 1) / last) * 100 - 50; + link(pg.location(), box(width: size * 1%, height: 0.5%)) + }),) + ) + #place( + bottom + left, + cetz.canvas( + length: 1%, + { + import cetz.draw: * + for pg in pages.rev() { + let seg_start = ((counter().at(pg.location()).first() + 1) / last) * 100 - 50 + rect((seg_start - size - 0.1, 0), (seg_start, 0.5), fill: s_topic.at(pg.location()).color, stroke: none) + } + }, + ), + ) + ] + }, + )[#lorem(n * 20) + #align(bottom)[#text(size: 4em)[Slide #n] + ] + ] ]; + +#let s = state("foo", "bar"); + + + + + + + + + + + + + + +#for i in (1, 2, 3, 4) { + seite(i) +} +#s_topic.update((color: blue)) +#for i in (5, 6, 7) { + seite(i) +} +#page[= miau 1] +#page[= miau 2] +#s_topic.update((color: green)) +#for i in (8, 9) { + seite(i) +} +#page[= miau 3] +#s_topic.update((color: yellow)) +#for i in (10, 11, 12) { + seite(i) +} + +#text(context s.get()) + diff --git a/src/lib.typ b/src/lib.typ new file mode 100644 index 0000000..5a8945e --- /dev/null +++ b/src/lib.typ @@ -0,0 +1,30 @@ +#let s_topic_list = state("topics", ()) +#let s_topic = state("topic", 0) + +#let init-presentation(topics: ()) = { + // validation hell :3 + if type(topics) != "array" { + panic("Expected array of topics.") + } + if not ( + topics.all(it => type(it) == "string" or type(it) == content) + or topics.all(it => type(it) == "color") + or topics.all(it => ( + it.len() == 2 + and ( + (type(it.first()) == "string" or type(it.first() == "content")) and type(it.last()) == "color" + ) + )) + ) { + // TODO: more specific error, telling the exact wrong indices + panic("topics expected a uniform array of: ", "string | content", "color", "(string | content, color)") + } + + s_topic_list.update(topics) +} + +#let slide(paper: "presentation-16-9", body) = [ + #page(paper: paper)[ + #body + ] +] diff --git a/test.typ b/test.typ new file mode 100644 index 0000000..da0dd16 --- /dev/null +++ b/test.typ @@ -0,0 +1,18 @@ +#import "src/lib.typ": init-presentation, slide; + +#init-presentation( + topics: ( + ("Red", red), + ("Green", green), + ("Blue", blue), + ("Yellow", yellow), + ("Magenta", purple), + ), +) + +#set page(fill: rgb("222")) +#set text(fill: white) + +#slide[ + = Big Title Slide +]