Replace Program::fonts with simpler font method

This commit is contained in:
Héctor Ramón Jiménez 2024-03-16 16:58:48 +01:00
parent bad3b1ac47
commit cfc0383bbf
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
2 changed files with 5 additions and 13 deletions

View file

@ -5,7 +5,7 @@ const ICON_FONT: Font = Font::with_name("icons");
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::sandbox("Checkbox - Iced", Example::update, Example::view) iced::sandbox("Checkbox - Iced", Example::update, Example::view)
.fonts([include_bytes!("../fonts/icons.ttf").as_slice().into()]) .font(include_bytes!("../fonts/icons.ttf").as_slice())
.run() .run()
} }

View file

@ -312,18 +312,10 @@ impl<P: Definition> Program<P> {
} }
} }
/// Sets the fonts that will be loaded at the start of the [`Program`]. /// Adds a font to the list of fonts that will be loaded at the start of the [`Program`].
pub fn fonts( pub fn font(mut self, font: impl Into<Cow<'static, [u8]>>) -> Self {
self, self.settings.fonts.push(font.into());
fonts: impl IntoIterator<Item = Cow<'static, [u8]>>, self
) -> Self {
Self {
settings: Settings {
fonts: fonts.into_iter().collect(),
..self.settings
},
..self
}
} }
/// Sets the [`window::Settings::position`] to [`window::Position::Centered`] in the [`Program`]. /// Sets the [`window::Settings::position`] to [`window::Position::Centered`] in the [`Program`].