Skip to content

Commit

Permalink
Merge pull request #1697 from iced-rs/text-glyphon
Browse files Browse the repository at this point in the history
Text shaping, font fallback, and `iced_wgpu` overhaul
  • Loading branch information
hecrj authored Feb 24, 2023
2 parents 573d27e + 8059c40 commit 368cadd
Show file tree
Hide file tree
Showing 94 changed files with 1,639 additions and 5,387 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 5 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -55,8 +46,6 @@ members = [
"core",
"futures",
"graphics",
"glow",
"glutin",
"lazy",
"native",
"style",
Expand All @@ -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]
Expand All @@ -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"]
Expand Down
55 changes: 38 additions & 17 deletions core/src/font.rs
Original file line number Diff line number Diff line change
@@ -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,
}
2 changes: 1 addition & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
#![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;

mod background;
mod color;
mod content_fit;
mod font;
mod length;
mod padding;
mod pixels;
Expand Down
Binary file modified examples/checkbox/fonts/icons.ttf
Binary file not shown.
28 changes: 19 additions & 9 deletions examples/checkbox/src/main.rs
Original file line number Diff line number Diff line change
@@ -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())
Expand All @@ -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<Message>) {
(
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<Message> {
match message {
Message::DefaultChecked(value) => self.default_checkbox = value,
Message::CustomChecked(value) => self.custom_checkbox = value,
Message::FontLoaded(_) => (),
}

Command::none()
}

fn view(&self) -> Element<Message> {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "integration_wgpu"
name = "integration"
version = "0.1.0"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2021"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<h1>integration_wgpu</h1>
<canvas id="iced_canvas"></canvas>
<script type="module">
import init from "./integration_wgpu.js";
init('./integration_wgpu_bg.wasm');
import init from "./integration.js";
init('./integration_bg.wasm');
</script>
<style>
body {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,18 @@ pub fn main() {

let mut resized = false;

// Initialize staging belt
let mut staging_belt = wgpu::util::StagingBelt::new(5 * 1024);

// Initialize scene and GUI controls
let scene = Scene::new(&device, format);
let controls = Controls::new();

// Initialize iced
let mut debug = Debug::new();
let mut renderer =
Renderer::new(Backend::new(&device, Settings::default(), format));
let mut renderer = Renderer::new(Backend::new(
&device,
&queue,
Settings::default(),
format,
));

let mut state = program::State::new(
controls,
Expand Down Expand Up @@ -247,8 +248,9 @@ pub fn main() {
renderer.with_primitives(|backend, primitive| {
backend.present(
&device,
&mut staging_belt,
&queue,
&mut encoder,
None,
&view,
primitive,
&viewport,
Expand All @@ -257,7 +259,6 @@ pub fn main() {
});

// Then we submit the work
staging_belt.finish();
queue.submit(Some(encoder.finish()));
frame.present();

Expand All @@ -267,10 +268,6 @@ pub fn main() {
state.mouse_interaction(),
),
);

// And recall staging buffers
staging_belt.recall();

}
Err(error) => match error {
wgpu::SurfaceError::OutOfMemory => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 0 additions & 12 deletions examples/integration_opengl/Cargo.toml

This file was deleted.

16 changes: 0 additions & 16 deletions examples/integration_opengl/README.md

This file was deleted.

Loading

0 comments on commit 368cadd

Please sign in to comment.