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 { ...@@ -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) { pub(crate) fn mark_all_as_new(&mut self) {
self.new_fonts self.new_fonts
.extend(self.font_handles.keys().map(|key| key.clone())); .extend(self.font_handles.keys().map(|key| key.clone()));
......
...@@ -300,6 +300,8 @@ define_styles! { ...@@ -300,6 +300,8 @@ define_styles! {
pub top: StyleProp<Units>, pub top: StyleProp<Units>,
/// The width of this widget /// The width of this widget
pub width: StyleProp<Units>, pub width: StyleProp<Units>,
/// The font style of the widget
pub font: StyleProp<String>,
} }
} }
...@@ -338,6 +340,7 @@ impl Style { ...@@ -338,6 +340,7 @@ impl Style {
row_between: StyleProp::Default, row_between: StyleProp::Default,
top: StyleProp::Default, top: StyleProp::Default,
width: StyleProp::Default, width: StyleProp::Default,
font: StyleProp::Default,
} }
} }
} }
......
...@@ -51,11 +51,11 @@ pub fn Text(props: TextProps) { ...@@ -51,11 +51,11 @@ pub fn Text(props: TextProps) {
.. ..
} = props.clone(); } = props.clone();
let font_name = font; let font_name = font;
let default_style = props.clone().styles.unwrap_or_default().font.resolve();
let font: Binding<Option<KayakFont>> = 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); context.bind(&font);
let mut should_render = true; let mut should_render = true;
// TODO: It might be worth caching the measurement here until content changes. // TODO: It might be worth caching the measurement here until content changes.
...@@ -84,13 +84,15 @@ pub fn Text(props: TextProps) { ...@@ -84,13 +84,15 @@ pub fn Text(props: TextProps) {
((0.0, 0.0), (0.0, 0.0)) ((0.0, 0.0), (0.0, 0.0))
}; };
if should_render { if should_render {
let render_command = RenderCommand::Text { let render_command = RenderCommand::Text {
content: content.clone(), content: content.clone(),
size, size,
parent_size, parent_size,
line_height: line_height.unwrap_or(size * 1.2), 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(); 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