Skip to content
Snippets Groups Projects
Unverified Commit 8bb264a3 authored by Ygg01's avatar Ygg01
Browse files

Add methods for setting default font

parent f1870f55
No related branches found
No related tags found
No related merge requests found
......@@ -62,6 +62,11 @@ impl FontMapping {
}
}
/// Set a default `KayakFont`
pub fn set_default(&mut self, handle: Handle<KayakFont>) {
self.add("", handle);
}
pub(crate) fn mark_all_as_new(&mut self) {
self.new_fonts
.extend(self.font_handles.keys().map(|key| key.clone()));
......
......@@ -300,6 +300,8 @@ define_styles! {
pub top: StyleProp<Units>,
/// The width of this widget
pub width: StyleProp<Units>,
/// The font style of the widget
pub font: StyleProp<String>,
}
}
......@@ -338,6 +340,7 @@ impl Style {
row_between: StyleProp::Default,
top: StyleProp::Default,
width: StyleProp::Default,
font: StyleProp::Default,
}
}
}
......
......@@ -51,11 +51,11 @@ pub fn Text(props: TextProps) {
..
} = props.clone();
let font_name = font;
let default_style = props.clone().styles.unwrap_or_default().font.resolve();
let font: Binding<Option<KayakFont>> =
context.get_asset(font_name.clone().unwrap_or("Roboto".into()));
context.get_asset(font_name.clone()
.unwrap_or(default_style.clone()));
context.bind(&font);
let mut should_render = true;
// TODO: It might be worth caching the measurement here until content changes.
......@@ -84,13 +84,15 @@ pub fn Text(props: TextProps) {
((0.0, 0.0), (0.0, 0.0))
};
if should_render {
let render_command = RenderCommand::Text {
content: content.clone(),
size,
parent_size,
line_height: line_height.unwrap_or(size * 1.2),
font: font_name.clone().unwrap_or("Roboto".into()),
font: font_name.clone().unwrap_or(default_style),
};
let styles = props.styles.clone().unwrap_or_default();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment