diff --git a/Cargo.lock b/Cargo.lock index fe02a86dde8..bc17eaf6bfc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,6 +21,12 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" +[[package]] +name = "ahash" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217" + [[package]] name = "ahash" version = "0.4.5" @@ -519,10 +525,10 @@ checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" name = "egui" version = "0.2.0" dependencies = [ - "ahash", + "ahash 0.4.5", "criterion", + "fontdue", "parking_lot", - "rusttype", "serde", "serde_json", ] @@ -574,6 +580,15 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "fontdue" +version = "0.3.2" +source = "git+https://github.com/mooman219/fontdue#3e2f51fe70fd7ab21ff70652ff8c2798f6e9fc65" +dependencies = [ + "hashbrown", + "ttf-parser 0.8.2", +] + [[package]] name = "foreign-types" version = "0.3.2" @@ -716,6 +731,16 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d36fab90f82edc3c747f9d438e06cf0a491055896f2a279638bb5beed6c40177" +[[package]] +name = "hashbrown" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b62f79061a0bc2e046024cb7ba44b08419ed238ecbd9adbd787434b9e8c25" +dependencies = [ + "ahash 0.3.8", + "autocfg", +] + [[package]] name = "hermit-abi" version = "0.1.17" @@ -1143,7 +1168,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f923fb806c46266c02ab4a5b239735c144bdeda724a50ed058e5226f594cde3" dependencies = [ - "ttf-parser", + "ttf-parser 0.6.2", ] [[package]] @@ -1525,6 +1550,12 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e5d7cd7ab3e47dda6e56542f4bbf3824c15234958c6e1bd6aaa347e93499fdc" +[[package]] +name = "ttf-parser" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d973cfa0e6124166b50a1105a67c85de40bbc625082f35c0f56f84cb1fb0a827" + [[package]] name = "unicode-width" version = "0.1.8" diff --git a/egui/Cargo.toml b/egui/Cargo.toml index 214eaf484cd..92aa18ce800 100644 --- a/egui/Cargo.toml +++ b/egui/Cargo.toml @@ -17,7 +17,7 @@ include = [ "**/*.rs", "Cargo.toml", "fonts/ProggyClean.ttf", "fonts/Comfortaa-R [dependencies] ahash = { version = "0.4", features = ["std"], default-features = false } parking_lot = "0.11" -rusttype = "0.9" +fontdue = { version = "0.3", git = "https://github.com/mooman219/fontdue" } serde = { version = "1", features = ["derive"], optional = true } serde_json = { version = "1", optional = true } diff --git a/egui/src/containers/collapsing_header.rs b/egui/src/containers/collapsing_header.rs index 978d170686a..91e2b9b2a95 100644 --- a/egui/src/containers/collapsing_header.rs +++ b/egui/src/containers/collapsing_header.rs @@ -169,8 +169,9 @@ struct Prepared { impl CollapsingHeader { fn begin(self, ui: &mut Ui) -> Prepared { - assert!( - ui.layout().dir() == Direction::Vertical, + assert_eq!( + ui.layout().dir(), + Direction::Vertical, "Horizontal collapsing is unimplemented" ); let Self { @@ -186,14 +187,14 @@ impl CollapsingHeader { let available = ui.available_finite(); let text_pos = available.min + vec2(ui.style().spacing.indent, 0.0); - let galley = label.layout_width(ui, available.right() - text_pos.x); - let text_max_x = text_pos.x + galley.size.x; + let layout = label.layout_width(ui, available.right() - text_pos.x); + let text_max_x = text_pos.x + layout.size.x; let desired_width = text_max_x - available.left(); let desired_width = desired_width.max(available.width()); let mut desired_size = vec2( desired_width, - galley.size.y + 2.0 * ui.style().spacing.button_padding.y, + layout.size.y + 2.0 * ui.style().spacing.button_padding.y, ); desired_size = desired_size.at_least(ui.style().spacing.interact_size); let rect = ui.allocate_space(desired_size); @@ -201,7 +202,7 @@ impl CollapsingHeader { let header_response = ui.interact(rect, id, Sense::click()); let text_pos = pos2( text_pos.x, - header_response.rect.center().y - galley.size.y / 2.0, + header_response.rect.center().y - layout.size.y / 2.0, ); let mut state = State::from_memory_with_default_open(ui.ctx(), id, default_open); @@ -226,9 +227,9 @@ impl CollapsingHeader { } let painter = ui.painter(); - painter.galley( + painter.layout( text_pos, - galley, + layout, label.text_style_or_default(ui.style()), ui.style().interact(&header_response).text_color(), ); diff --git a/egui/src/containers/window.rs b/egui/src/containers/window.rs index 77ce625807f..0ae6af48ffc 100644 --- a/egui/src/containers/window.rs +++ b/egui/src/containers/window.rs @@ -2,9 +2,7 @@ use std::sync::Arc; -use crate::{paint::*, widgets::*, *}; - -use super::*; +use crate::{paint::fonts::GlyphLayout, paint::*, widgets::*, *}; /// Builder for a floating window which can be dragged, closed, collapsed, resized and scrolled (off by default). /// @@ -219,7 +217,7 @@ impl<'open> Window<'open> { // First interact (move etc) to avoid frame delay: let last_frame_outer_rect = area.state().rect(); let interaction = if possible.movable || possible.resizable { - let title_bar_height = title_label.font_height(ctx.fonts(), &ctx.style()) + let title_bar_height = title_label.font_height(&ctx.fonts().lock(), &ctx.style()) + 1.0 * ctx.style().spacing.item_spacing.y; // this could be better let margins = 2.0 * frame.margin + vec2(0.0, title_bar_height); @@ -599,7 +597,7 @@ fn paint_frame_interaction( struct TitleBar { title_label: Label, - title_galley: font::Galley, + title_layout: GlyphLayout, title_rect: Rect, rect: Rect, } @@ -613,7 +611,7 @@ fn show_title_bar( collapsible: bool, ) -> TitleBar { let (title_bar, response) = ui.horizontal(|ui| { - ui.set_min_height(title_label.font_height(ui.fonts(), ui.style())); + ui.set_min_height(title_label.font_height(&ui.fonts().lock(), ui.style())); let item_spacing = ui.style().spacing.item_spacing; let button_size = ui.style().spacing.icon_width; @@ -630,8 +628,8 @@ fn show_title_bar( collapsing_header::paint_icon(ui, openness, &collapse_button_response); } - let title_galley = title_label.layout(ui); - let title_rect = ui.allocate_space(title_galley.size); + let title_layout = title_label.layout(ui); + let title_rect = ui.allocate_space(title_layout.size); if show_close_button { // Reserve space for close button which will be added later (once we know our full width): @@ -649,7 +647,7 @@ fn show_title_bar( TitleBar { title_label, - title_galley, + title_layout, title_rect, rect: Rect::invalid(), // Will be filled in later } @@ -685,7 +683,7 @@ impl TitleBar { // TODO: pick style for title based on move interaction self.title_label - .paint_galley(ui, self.title_rect.min, self.title_galley); + .paint_layout(ui, self.title_rect.min, self.title_layout); if let Some(content_response) = &content_response { // paint separator between title and content: diff --git a/egui/src/context.rs b/egui/src/context.rs index 2463fa1c413..64af66563e9 100644 --- a/egui/src/context.rs +++ b/egui/src/context.rs @@ -25,7 +25,7 @@ struct Options { /// Controls the tessellator. paint_options: paint::PaintOptions, /// Font sizes etc. - font_definitions: FontDefinitions, + font_configuration: FontConfiguration, } /// Thi is the first thing you need when working with Egui. @@ -39,7 +39,7 @@ struct Options { pub struct Context { options: Mutex, /// None until first call to `begin_frame`. - fonts: Option>, + fonts: Option>>, memory: Arc>, animation_manager: Arc>, @@ -110,24 +110,24 @@ impl Context { /// Not valid until first call to `begin_frame()` /// That's because since we don't know the proper `pixels_per_point` until then. - pub fn fonts(&self) -> &Fonts { - &*self - .fonts + pub fn fonts(&self) -> Arc> { + self.fonts .as_ref() .expect("No fonts available until first call to Context::begin_frame()`") + .clone() } /// The Egui texture, containing font characters etc.. /// Not valid until first call to `begin_frame()` /// That's because since we don't know the proper `pixels_per_point` until then. pub fn texture(&self) -> Arc { - self.fonts().texture() + self.fonts().lock().texture() } /// Will become active at the start of the next frame. /// `pixels_per_point` will be ignored (overwritten at start of each frame with the contents of input) - pub fn set_fonts(&self, font_definitions: FontDefinitions) { - lock(&self.options, "options").font_definitions = font_definitions; + pub fn set_fonts(&self, font_configuration: FontConfiguration) { + lock(&self.options, "options").font_configuration = font_configuration; } pub fn style(&self) -> Arc