diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 38b8184234..390e7bf303 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,4 +38,4 @@ jobs: - name: Check compilation of `todos` example run: cargo build --package todos --target wasm32-unknown-unknown - name: Check compilation of `integration_wgpu` example - run: cargo build --package integration_wgpu --target wasm32-unknown-unknown + run: cargo build --package integration --target wasm32-unknown-unknown diff --git a/Cargo.toml b/Cargo.toml index d26ec2b6b8..551e12ac9c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,21 +12,14 @@ keywords = ["gui", "ui", "graphics", "interface", "widgets"] categories = ["gui"] [features] -default = ["wgpu"] # Enables the `Image` widget -image = ["iced_wgpu?/image", "iced_glow?/image", "image_rs"] +image = ["iced_wgpu/image", "image_rs"] # Enables the `Svg` widget -svg = ["iced_wgpu?/svg", "iced_glow?/svg"] +svg = ["iced_wgpu/svg"] # Enables the `Canvas` widget canvas = ["iced_graphics/canvas"] # Enables the `QRCode` widget qr_code = ["iced_graphics/qr_code"] -# Enables the `iced_wgpu` renderer -wgpu = ["iced_wgpu"] -# Enables using system fonts -default_system_font = ["iced_wgpu?/default_system_font", "iced_glow?/default_system_font"] -# Enables the `iced_glow` renderer. Overrides `iced_wgpu` -glow = ["iced_glow", "iced_glutin"] # Enables a debug view in native platforms (press F12) debug = ["iced_winit/debug"] # Enables `tokio` as the `executor::Default` on native platforms @@ -42,9 +35,7 @@ system = ["iced_winit/system"] # Enables chrome traces chrome-trace = [ "iced_winit/chrome-trace", - "iced_glutin?/trace", - "iced_wgpu?/tracing", - "iced_glow?/tracing", + "iced_wgpu/tracing", ] [badges] @@ -55,8 +46,6 @@ members = [ "core", "futures", "graphics", - "glow", - "glutin", "lazy", "native", "style", @@ -71,8 +60,6 @@ iced_futures = { version = "0.6", path = "futures" } iced_native = { version = "0.9", path = "native" } iced_graphics = { version = "0.7", path = "graphics" } iced_winit = { version = "0.8", path = "winit", features = ["application"] } -iced_glutin = { version = "0.7", path = "glutin", optional = true } -iced_glow = { version = "0.7", path = "glow", optional = true } thiserror = "1.0" [dependencies.image_rs] @@ -81,10 +68,10 @@ package = "image" optional = true [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -iced_wgpu = { version = "0.9", path = "wgpu", optional = true } +iced_wgpu = { version = "0.9", path = "wgpu" } [target.'cfg(target_arch = "wasm32")'.dependencies] -iced_wgpu = { version = "0.9", path = "wgpu", features = ["webgl"], optional = true } +iced_wgpu = { version = "0.9", path = "wgpu", features = ["webgl"] } [package.metadata.docs.rs] rustdoc-args = ["--cfg", "docsrs"] diff --git a/core/src/font.rs b/core/src/font.rs index 3f9ad2b5a4..b67c08af15 100644 --- a/core/src/font.rs +++ b/core/src/font.rs @@ -1,24 +1,45 @@ +//! Load and use fonts. +use std::hash::Hash; + /// A font. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum Font { - /// The default font. - /// - /// This is normally a font configured in a renderer or loaded from the - /// system. - Default, + /// The name of a font family of choice. + Name(&'static str), + + /// Serif fonts represent the formal text style for a script. + Serif, + + /// Glyphs in sans-serif fonts, as the term is used in CSS, are generally low + /// contrast and have stroke endings that are plain — without any flaring, + /// cross stroke, or other ornamentation. + SansSerif, + + /// Glyphs in cursive fonts generally use a more informal script style, and + /// the result looks more like handwritten pen or brush writing than printed + /// letterwork. + Cursive, - /// An external font. - External { - /// The name of the external font - name: &'static str, + /// Fantasy fonts are primarily decorative or expressive fonts that contain + /// decorative or expressive representations of characters. + Fantasy, - /// The bytes of the external font - bytes: &'static [u8], - }, + /// The sole criterion of a monospace font is that all glyphs have the same + /// fixed width. + Monospace, } -impl Default for Font { - fn default() -> Font { - Font::Default - } +/// The weight of some text. +#[allow(missing_docs)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum Weight { + Thin, + ExtraLight, + Light, + Normal, + Medium, + Semibold, + Bold, + ExtraBold, + Black, } diff --git a/core/src/lib.rs b/core/src/lib.rs index d3596b4d04..d73148514c 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -25,6 +25,7 @@ #![forbid(unsafe_code, rust_2018_idioms)] #![allow(clippy::inherent_to_string, clippy::type_complexity)] pub mod alignment; +pub mod font; pub mod keyboard; pub mod mouse; pub mod time; @@ -32,7 +33,6 @@ pub mod time; mod background; mod color; mod content_fit; -mod font; mod length; mod padding; mod pixels; diff --git a/examples/checkbox/fonts/icons.ttf b/examples/checkbox/fonts/icons.ttf index a204684478..82f284819e 100644 Binary files a/examples/checkbox/fonts/icons.ttf and b/examples/checkbox/fonts/icons.ttf differ diff --git a/examples/checkbox/src/main.rs b/examples/checkbox/src/main.rs index 09950bb86f..7711149091 100644 --- a/examples/checkbox/src/main.rs +++ b/examples/checkbox/src/main.rs @@ -1,10 +1,9 @@ +use iced::executor; +use iced::font::{self, Font}; use iced::widget::{checkbox, column, container}; -use iced::{Element, Font, Length, Sandbox, Settings}; +use iced::{Application, Command, Element, Length, Settings, Theme}; -const ICON_FONT: Font = Font::External { - name: "Icons", - bytes: include_bytes!("../fonts/icons.ttf"), -}; +const ICON_FONT: Font = Font::Name("icons"); pub fn main() -> iced::Result { Example::run(Settings::default()) @@ -20,24 +19,35 @@ struct Example { enum Message { DefaultChecked(bool), CustomChecked(bool), + FontLoaded(Result<(), font::Error>), } -impl Sandbox for Example { +impl Application for Example { type Message = Message; + type Flags = (); + type Executor = executor::Default; + type Theme = Theme; - fn new() -> Self { - Default::default() + fn new(_flags: Self::Flags) -> (Self, Command) { + ( + Self::default(), + font::load(include_bytes!("../fonts/icons.ttf").as_ref()) + .map(Message::FontLoaded), + ) } fn title(&self) -> String { String::from("Checkbox - Iced") } - fn update(&mut self, message: Message) { + fn update(&mut self, message: Message) -> Command { match message { Message::DefaultChecked(value) => self.default_checkbox = value, Message::CustomChecked(value) => self.custom_checkbox = value, + Message::FontLoaded(_) => (), } + + Command::none() } fn view(&self) -> Element { diff --git a/examples/integration_wgpu/.gitignore b/examples/integration/.gitignore similarity index 100% rename from examples/integration_wgpu/.gitignore rename to examples/integration/.gitignore diff --git a/examples/integration_wgpu/Cargo.toml b/examples/integration/Cargo.toml similarity index 96% rename from examples/integration_wgpu/Cargo.toml rename to examples/integration/Cargo.toml index eaa1df7e17..200306aaa9 100644 --- a/examples/integration_wgpu/Cargo.toml +++ b/examples/integration/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "integration_wgpu" +name = "integration" version = "0.1.0" authors = ["Héctor Ramón Jiménez "] edition = "2021" diff --git a/examples/integration_wgpu/README.md b/examples/integration/README.md similarity index 100% rename from examples/integration_wgpu/README.md rename to examples/integration/README.md diff --git a/examples/integration_wgpu/index.html b/examples/integration/index.html similarity index 81% rename from examples/integration_wgpu/index.html rename to examples/integration/index.html index 461e67a41c..920bc4a063 100644 --- a/examples/integration_wgpu/index.html +++ b/examples/integration/index.html @@ -8,8 +8,8 @@

integration_wgpu