Add monospace text style
Signed-off-by: kernelkind <kernelkind@gmail.com> Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
William Casarin
parent
bf23e778b3
commit
f6c46a1eb5
@@ -4,7 +4,7 @@ use crate::colors::{
|
|||||||
use egui::{
|
use egui::{
|
||||||
epaint::Shadow,
|
epaint::Shadow,
|
||||||
style::{WidgetVisuals, Widgets},
|
style::{WidgetVisuals, Widgets},
|
||||||
Button, Context, FontId, Rounding, Stroke, Style, TextStyle, Ui, Visuals,
|
Button, Context, FontFamily, FontId, Rounding, Stroke, Style, TextStyle, Ui, Visuals,
|
||||||
};
|
};
|
||||||
use strum::IntoEnumIterator;
|
use strum::IntoEnumIterator;
|
||||||
use strum_macros::EnumIter;
|
use strum_macros::EnumIter;
|
||||||
@@ -50,14 +50,14 @@ pub fn user_requested_visuals_change(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create custom text sizes for any FontSizes
|
/// Create custom text sizes for any FontSizes
|
||||||
pub fn create_text_styles(ctx: &Context, font_size: fn(NotedeckTextStyle) -> f32) -> Style {
|
pub fn create_text_styles(ctx: &Context, font_size: fn(&NotedeckTextStyle) -> f32) -> Style {
|
||||||
let mut style = (*ctx.style()).clone();
|
let mut style = (*ctx.style()).clone();
|
||||||
|
|
||||||
style.text_styles = NotedeckTextStyle::iter()
|
style.text_styles = NotedeckTextStyle::iter()
|
||||||
.map(|text_style| {
|
.map(|text_style| {
|
||||||
(
|
(
|
||||||
text_style.text_style(),
|
text_style.text_style(),
|
||||||
FontId::new(font_size(text_style), egui::FontFamily::Proportional),
|
FontId::new(font_size(&text_style), text_style.font_family()),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
@@ -65,24 +65,26 @@ pub fn create_text_styles(ctx: &Context, font_size: fn(NotedeckTextStyle) -> f32
|
|||||||
style
|
style
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn desktop_font_size(text_style: NotedeckTextStyle) -> f32 {
|
pub fn desktop_font_size(text_style: &NotedeckTextStyle) -> f32 {
|
||||||
match text_style {
|
match text_style {
|
||||||
NotedeckTextStyle::Heading => 48.0,
|
NotedeckTextStyle::Heading => 48.0,
|
||||||
NotedeckTextStyle::Heading2 => 24.0,
|
NotedeckTextStyle::Heading2 => 24.0,
|
||||||
NotedeckTextStyle::Heading3 => 20.0,
|
NotedeckTextStyle::Heading3 => 20.0,
|
||||||
NotedeckTextStyle::Body => 13.0,
|
NotedeckTextStyle::Body => 13.0,
|
||||||
|
NotedeckTextStyle::Monospace => 13.0,
|
||||||
NotedeckTextStyle::Button => 13.0,
|
NotedeckTextStyle::Button => 13.0,
|
||||||
NotedeckTextStyle::Small => 12.0,
|
NotedeckTextStyle::Small => 12.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mobile_font_size(text_style: NotedeckTextStyle) -> f32 {
|
pub fn mobile_font_size(text_style: &NotedeckTextStyle) -> f32 {
|
||||||
// TODO: tweak text sizes for optimal mobile viewing
|
// TODO: tweak text sizes for optimal mobile viewing
|
||||||
match text_style {
|
match text_style {
|
||||||
NotedeckTextStyle::Heading => 48.0,
|
NotedeckTextStyle::Heading => 48.0,
|
||||||
NotedeckTextStyle::Heading2 => 24.0,
|
NotedeckTextStyle::Heading2 => 24.0,
|
||||||
NotedeckTextStyle::Heading3 => 20.0,
|
NotedeckTextStyle::Heading3 => 20.0,
|
||||||
NotedeckTextStyle::Body => 13.0,
|
NotedeckTextStyle::Body => 13.0,
|
||||||
|
NotedeckTextStyle::Monospace => 13.0,
|
||||||
NotedeckTextStyle::Button => 13.0,
|
NotedeckTextStyle::Button => 13.0,
|
||||||
NotedeckTextStyle::Small => 12.0,
|
NotedeckTextStyle::Small => 12.0,
|
||||||
}
|
}
|
||||||
@@ -94,6 +96,7 @@ pub enum NotedeckTextStyle {
|
|||||||
Heading2,
|
Heading2,
|
||||||
Heading3,
|
Heading3,
|
||||||
Body,
|
Body,
|
||||||
|
Monospace,
|
||||||
Button,
|
Button,
|
||||||
Small,
|
Small,
|
||||||
}
|
}
|
||||||
@@ -105,10 +108,23 @@ impl NotedeckTextStyle {
|
|||||||
Self::Heading2 => TextStyle::Name("Heading2".into()),
|
Self::Heading2 => TextStyle::Name("Heading2".into()),
|
||||||
Self::Heading3 => TextStyle::Name("Heading3".into()),
|
Self::Heading3 => TextStyle::Name("Heading3".into()),
|
||||||
Self::Body => TextStyle::Body,
|
Self::Body => TextStyle::Body,
|
||||||
|
Self::Monospace => TextStyle::Monospace,
|
||||||
Self::Button => TextStyle::Button,
|
Self::Button => TextStyle::Button,
|
||||||
Self::Small => TextStyle::Small,
|
Self::Small => TextStyle::Small,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn font_family(&self) -> FontFamily {
|
||||||
|
match self {
|
||||||
|
Self::Heading => FontFamily::Proportional,
|
||||||
|
Self::Heading2 => FontFamily::Proportional,
|
||||||
|
Self::Heading3 => FontFamily::Proportional,
|
||||||
|
Self::Body => FontFamily::Proportional,
|
||||||
|
Self::Monospace => FontFamily::Monospace,
|
||||||
|
Self::Button => FontFamily::Proportional,
|
||||||
|
Self::Small => FontFamily::Proportional,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_themed_visuals(theme: ColorTheme, default: Visuals) -> Visuals {
|
pub fn create_themed_visuals(theme: ColorTheme, default: Visuals) -> Visuals {
|
||||||
|
|||||||
Reference in New Issue
Block a user