Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow customizing slide title style #201

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/processing/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,17 @@ impl<'a> PresentationBuilder<'a> {
}

let style = self.theme.slide_title.clone();
text.apply_style(&TextStyle::default().bold().colors(style.colors.clone()));
let mut text_style = TextStyle::default().colors(style.colors.clone());
if style.bold {
text_style = text_style.bold();
}
if style.italics {
text_style = text_style.italics();
}
if style.underlined {
text_style = text_style.underlined();
}
text.apply_style(&text_style);

for _ in 0..style.padding_top.unwrap_or(0) {
self.push_line_break();
Expand Down
59 changes: 34 additions & 25 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,33 @@ pub(crate) struct TextStyle {

impl TextStyle {
/// Add bold to this style.
pub(crate) fn bold(mut self) -> Self {
self.flags |= TextFormatFlags::Bold as u8;
self
pub(crate) fn bold(self) -> Self {
self.add_flag(TextFormatFlags::Bold)
}

/// Add italics to this style.
pub(crate) fn italics(mut self) -> Self {
self.flags |= TextFormatFlags::Italics as u8;
self
pub(crate) fn italics(self) -> Self {
self.add_flag(TextFormatFlags::Italics)
}

/// Indicate this text is a piece of inline code.
pub(crate) fn code(mut self) -> Self {
self.flags |= TextFormatFlags::Code as u8;
self
pub(crate) fn code(self) -> Self {
self.add_flag(TextFormatFlags::Code)
}

/// Add strikethrough to this style.
pub(crate) fn strikethrough(mut self) -> Self {
self.flags |= TextFormatFlags::Strikethrough as u8;
self
pub(crate) fn strikethrough(self) -> Self {
self.add_flag(TextFormatFlags::Strikethrough)
}

/// Add underline to this style.
pub(crate) fn underlined(self) -> Self {
self.add_flag(TextFormatFlags::Underlined)
}

/// Indicate this is a link.
pub(crate) fn link(mut self) -> Self {
self.flags |= TextFormatFlags::Link as u8;
self
pub(crate) fn link(self) -> Self {
self.italics().underlined()
}

/// Set the colors for this text style.
Expand All @@ -53,27 +53,27 @@ impl TextStyle {

/// Check whether this text style is bold.
pub(crate) fn is_bold(&self) -> bool {
self.flags & TextFormatFlags::Bold as u8 != 0
self.has_flag(TextFormatFlags::Bold)
}

/// Check whether this text style has italics.
pub(crate) fn is_italics(&self) -> bool {
self.flags & TextFormatFlags::Italics as u8 != 0
self.has_flag(TextFormatFlags::Italics)
}

/// Check whether this text is code.
pub(crate) fn is_code(&self) -> bool {
self.flags & TextFormatFlags::Code as u8 != 0
self.has_flag(TextFormatFlags::Code)
}

/// Check whether this text style is strikethrough.
pub(crate) fn is_strikethrough(&self) -> bool {
self.flags & TextFormatFlags::Strikethrough as u8 != 0
self.has_flag(TextFormatFlags::Strikethrough)
}

/// Check whether this text is a link.
pub(crate) fn is_link(&self) -> bool {
self.flags & TextFormatFlags::Link as u8 != 0
/// Check whether this text style is underlined.
pub(crate) fn is_underlined(&self) -> bool {
self.has_flag(TextFormatFlags::Underlined)
}

/// Merge this style with another one.
Expand All @@ -96,8 +96,8 @@ impl TextStyle {
if self.is_strikethrough() {
styled = styled.crossed_out();
}
if self.is_link() {
styled = styled.italic().underlined();
if self.is_underlined() {
styled = styled.underlined();
}
if let Some(color) = self.colors.background {
styled = styled.on(color.into());
Expand All @@ -107,6 +107,15 @@ impl TextStyle {
}
styled
}

fn add_flag(mut self, flag: TextFormatFlags) -> Self {
self.flags |= flag as u8;
self
}

fn has_flag(&self, flag: TextFormatFlags) -> bool {
self.flags & flag as u8 != 0
}
}

#[derive(Debug)]
Expand All @@ -115,7 +124,7 @@ enum TextFormatFlags {
Italics = 2,
Code = 4,
Strikethrough = 8,
Link = 16,
Underlined = 16,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, SerializeDisplay, DeserializeFromStr)]
Expand Down
12 changes: 12 additions & 0 deletions src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@ pub(crate) struct SlideTitleStyle {
/// The colors to be used.
#[serde(default)]
pub(crate) colors: Colors,

/// Whether to use bold font for slide titles.
#[serde(default)]
pub(crate) bold: bool,

/// Whether to use italics font for slide titles.
#[serde(default)]
pub(crate) italics: bool,

/// Whether to use underlined font for slide titles.
#[serde(default)]
pub(crate) underlined: bool,
}

/// The style for all headings.
Expand Down
1 change: 1 addition & 0 deletions themes/catppuccin-mocha.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ slide_title:
padding_top: 1
colors:
foreground: "f9e2af"
bold: true

code:
alignment: center
Expand Down
1 change: 1 addition & 0 deletions themes/dark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ slide_title:
padding_top: 1
colors:
foreground: "ee9322"
bold: true

code:
alignment: center
Expand Down
1 change: 1 addition & 0 deletions themes/light.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ slide_title:
padding_top: 1
colors:
foreground: "f77f00"
bold: true

code:
alignment: center
Expand Down
1 change: 1 addition & 0 deletions themes/terminal-dark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ slide_title:
padding_top: 1
colors:
foreground: yellow
bold: true

code:
alignment: center
Expand Down
1 change: 1 addition & 0 deletions themes/terminal-light.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ slide_title:
padding_top: 1
colors:
foreground: dark_yellow
bold: true

code:
alignment: center
Expand Down
1 change: 1 addition & 0 deletions themes/tokyonight-storm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ slide_title:
padding_top: 1
colors:
foreground: "e0af68"
bold: true

code:
alignment: center
Expand Down
Loading