summaryrefslogtreecommitdiff
path: root/library/src/text/shift.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-09 14:17:24 +0100
committerLaurenz <laurmaedje@gmail.com>2023-03-09 14:42:14 +0100
commitc38d72383d2068361d635d6c1c78ba97aa917801 (patch)
treee758418a2d704d69dee88faf4a9a9c69b25b47ca /library/src/text/shift.rs
parentd7a65fa26d131179d9d82226e5ee1b562084e48a (diff)
Make all optional fields settable
Diffstat (limited to 'library/src/text/shift.rs')
-rw-r--r--library/src/text/shift.rs38
1 files changed, 16 insertions, 22 deletions
diff --git a/library/src/text/shift.rs b/library/src/text/shift.rs
index 98718365..ccdb0197 100644
--- a/library/src/text/shift.rs
+++ b/library/src/text/shift.rs
@@ -16,11 +16,6 @@ use crate::prelude::*;
/// Category: text
#[node(Show)]
pub struct SubNode {
- /// The text to display in subscript.
- #[positional]
- #[required]
- pub body: Content,
-
/// Whether to prefer the dedicated subscript characters of the font.
///
/// If this is enabled, Typst first tries to transform the text to subscript
@@ -31,23 +26,25 @@ pub struct SubNode {
/// N#sub(typographic: true)[1]
/// N#sub(typographic: false)[1]
/// ```
- #[settable]
#[default(true)]
pub typographic: bool,
/// The baseline shift for synthetic subscripts. Does not apply if
/// `typographic` is true and the font has subscript codepoints for the
/// given `body`.
- #[settable]
#[default(Em::new(0.2).into())]
pub baseline: Length,
/// The font size for synthetic subscripts. Does not apply if
/// `typographic` is true and the font has subscript codepoints for the
/// given `body`.
- #[settable]
#[default(TextSize(Em::new(0.6).into()))]
pub size: TextSize,
+
+ /// The text to display in subscript.
+ #[positional]
+ #[required]
+ pub body: Content,
}
impl Show for SubNode {
@@ -59,7 +56,7 @@ impl Show for SubNode {
) -> SourceResult<Content> {
let body = self.body();
let mut transformed = None;
- if Self::typographic_in(styles) {
+ if self.typographic(styles) {
if let Some(text) = search_text(&body, true) {
if is_shapable(vt, &text, styles) {
transformed = Some(TextNode::packed(text));
@@ -68,8 +65,8 @@ impl Show for SubNode {
};
Ok(transformed.unwrap_or_else(|| {
- body.styled(TextNode::set_baseline(Self::baseline_in(styles)))
- .styled(TextNode::set_size(Self::size_in(styles)))
+ body.styled(TextNode::set_baseline(self.baseline(styles)))
+ .styled(TextNode::set_size(self.size(styles)))
}))
}
}
@@ -87,11 +84,6 @@ impl Show for SubNode {
/// Category: text
#[node(Show)]
pub struct SuperNode {
- /// The text to display in superscript.
- #[positional]
- #[required]
- pub body: Content,
-
/// Whether to prefer the dedicated superscript characters of the font.
///
/// If this is enabled, Typst first tries to transform the text to
@@ -102,23 +94,25 @@ pub struct SuperNode {
/// N#super(typographic: true)[1]
/// N#super(typographic: false)[1]
/// ```
- #[settable]
#[default(true)]
pub typographic: bool,
/// The baseline shift for synthetic superscripts. Does not apply if
/// `typographic` is true and the font has superscript codepoints for the
/// given `body`.
- #[settable]
#[default(Em::new(-0.5).into())]
pub baseline: Length,
/// The font size for synthetic superscripts. Does not apply if
/// `typographic` is true and the font has superscript codepoints for the
/// given `body`.
- #[settable]
#[default(TextSize(Em::new(0.6).into()))]
pub size: TextSize,
+
+ /// The text to display in superscript.
+ #[positional]
+ #[required]
+ pub body: Content,
}
impl Show for SuperNode {
@@ -130,7 +124,7 @@ impl Show for SuperNode {
) -> SourceResult<Content> {
let body = self.body();
let mut transformed = None;
- if Self::typographic_in(styles) {
+ if self.typographic(styles) {
if let Some(text) = search_text(&body, false) {
if is_shapable(vt, &text, styles) {
transformed = Some(TextNode::packed(text));
@@ -139,8 +133,8 @@ impl Show for SuperNode {
};
Ok(transformed.unwrap_or_else(|| {
- body.styled(TextNode::set_baseline(Self::baseline_in(styles)))
- .styled(TextNode::set_size(Self::size_in(styles)))
+ body.styled(TextNode::set_baseline(self.baseline(styles)))
+ .styled(TextNode::set_size(self.size(styles)))
}))
}
}