Skip to content

Commit acef4ff

Browse files
committed
WIP
1 parent d3ba981 commit acef4ff

35 files changed

+1586
-1149
lines changed

Cargo.lock

+45-7
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,6 @@ dependencies = [
15171517
name = "epaint"
15181518
version = "0.31.1"
15191519
dependencies = [
1520-
"ab_glyph",
15211520
"accesskit",
15221521
"ahash",
15231522
"backtrace",
@@ -1527,14 +1526,15 @@ dependencies = [
15271526
"ecolor",
15281527
"emath",
15291528
"epaint_default_fonts",
1529+
"etagere",
15301530
"log",
15311531
"nohash-hasher",
15321532
"parking_lot",
15331533
"parley",
15341534
"profiling",
15351535
"rayon",
15361536
"serde",
1537-
"swash",
1537+
"swash 0.2.1",
15381538
]
15391539

15401540
[[package]]
@@ -1563,6 +1563,25 @@ version = "3.3.1"
15631563
source = "registry+https://github.com/rust-lang/crates.io-index"
15641564
checksum = "a5d9305ccc6942a704f4335694ecd3de2ea531b114ac2d51f5f843750787a92f"
15651565

1566+
[[package]]
1567+
name = "etagere"
1568+
version = "0.2.15"
1569+
source = "registry+https://github.com/rust-lang/crates.io-index"
1570+
checksum = "fc89bf99e5dc15954a60f707c1e09d7540e5cd9af85fa75caa0b510bc08c5342"
1571+
dependencies = [
1572+
"euclid",
1573+
"svg_fmt",
1574+
]
1575+
1576+
[[package]]
1577+
name = "euclid"
1578+
version = "0.22.11"
1579+
source = "registry+https://github.com/rust-lang/crates.io-index"
1580+
checksum = "ad9cdb4b747e485a12abb0e6566612956c7a1bafa3bdb8d682c5b6d403589e48"
1581+
dependencies = [
1582+
"num-traits",
1583+
]
1584+
15661585
[[package]]
15671586
name = "event-listener"
15681587
version = "5.3.1"
@@ -2465,7 +2484,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
24652484
checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4"
24662485
dependencies = [
24672486
"cfg-if",
2468-
"windows-targets 0.48.5",
2487+
"windows-targets 0.52.6",
24692488
]
24702489

24712490
[[package]]
@@ -3096,7 +3115,7 @@ dependencies = [
30963115
"peniko",
30973116
"serde",
30983117
"skrifa",
3099-
"swash",
3118+
"swash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
31003119
]
31013120

31023121
[[package]]
@@ -3946,6 +3965,12 @@ version = "2.6.1"
39463965
source = "registry+https://github.com/rust-lang/crates.io-index"
39473966
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
39483967

3968+
[[package]]
3969+
name = "svg_fmt"
3970+
version = "0.4.4"
3971+
source = "registry+https://github.com/rust-lang/crates.io-index"
3972+
checksum = "ce5d813d71d82c4cbc1742135004e4a79fd870214c155443451c139c9470a0aa"
3973+
39493974
[[package]]
39503975
name = "svgtypes"
39513976
version = "0.13.0"
@@ -3958,13 +3983,22 @@ dependencies = [
39583983

39593984
[[package]]
39603985
name = "swash"
3961-
version = "0.2.0"
3986+
version = "0.2.1"
3987+
dependencies = [
3988+
"skrifa",
3989+
"yazi",
3990+
"zeno 0.3.2",
3991+
]
3992+
3993+
[[package]]
3994+
name = "swash"
3995+
version = "0.2.1"
39623996
source = "registry+https://github.com/rust-lang/crates.io-index"
3963-
checksum = "f0e25b48fd1c222c9fdb61148e2203b750f9840c07922fd61b87c6015560b8f6"
3997+
checksum = "13d5bbc2aa266907ed8ee977c9c9e16363cc2b001266104e13397b57f1d15f71"
39643998
dependencies = [
39653999
"skrifa",
39664000
"yazi",
3967-
"zeno",
4001+
"zeno 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
39684002
]
39694003

39704004
[[package]]
@@ -5415,6 +5449,10 @@ dependencies = [
54155449
"zvariant",
54165450
]
54175451

5452+
[[package]]
5453+
name = "zeno"
5454+
version = "0.3.2"
5455+
54185456
[[package]]
54195457
name = "zeno"
54205458
version = "0.3.2"

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ Light Theme:
145145
## Dependencies
146146
`egui` has a minimal set of default dependencies:
147147

148-
* [`ab_glyph`](https://crates.io/crates/ab_glyph)
149148
* [`ahash`](https://crates.io/crates/ahash)
150149
* [`bitflags`](https://crates.io/crates/bitflags)
151150
* [`nohash-hasher`](https://crates.io/crates/nohash-hasher)
152151
* [`parking_lot`](https://crates.io/crates/parking_lot)
152+
* [`parley`](https://crates.io/crates/parley)
153153

154154
Heavier dependencies are kept out of `egui`, even as opt-in.
155155
All code in `egui` is Wasm-friendly (even outside a browser).

crates/egui/src/context.rs

+41-32
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ impl ViewportRepaintInfo {
394394
#[derive(Default)]
395395
struct ContextImpl {
396396
fonts: Option<FontStore>,
397-
font_definitions: FontDefinitions,
398397

399398
memory: Memory,
400399
animation_manager: AnimationManager,
@@ -552,33 +551,29 @@ impl ContextImpl {
552551
fn update_fonts_mut(&mut self) {
553552
profiling::function_scope!();
554553
let input = &self.viewport().input;
555-
let pixels_per_point = input.pixels_per_point();
556554
let max_texture_side = input.max_texture_side;
557555

558-
if let Some(font_definitions) = self.memory.new_font_definitions.take() {
559-
// New font definition loaded, so we need to reload all fonts.
560-
self.fonts = None;
561-
self.font_definitions = font_definitions;
562-
#[cfg(feature = "log")]
563-
log::trace!("Loading new font definitions");
564-
}
556+
let mut new_font_definitions =
557+
if let Some(font_definitions) = self.memory.new_font_definitions.take() {
558+
Cow::Owned(font_definitions)
559+
} else if let Some(fonts) = &self.fonts {
560+
Cow::Borrowed(fonts.definitions())
561+
} else {
562+
Cow::Owned(FontDefinitions::default())
563+
};
565564

566565
if !self.memory.add_fonts.is_empty() {
567566
let fonts = self.memory.add_fonts.drain(..);
567+
let font_definitions = new_font_definitions.to_mut();
568568
for font in fonts {
569-
self.fonts = None; // recreate all the fonts
570569
for family in font.families {
571-
let fam = self
572-
.font_definitions
573-
.families
574-
.entry(family.family)
575-
.or_default();
570+
let fam = font_definitions.families.entry(family.family).or_default();
576571
match family.priority {
577572
FontPriority::Highest => fam.insert(0, font.name.clone()),
578573
FontPriority::Lowest => fam.push(font.name.clone()),
579574
}
580575
}
581-
self.font_definitions
576+
font_definitions
582577
.font_data
583578
.insert(font.name, Arc::new(font.data));
584579
}
@@ -587,28 +582,43 @@ impl ContextImpl {
587582
log::trace!("Adding new fonts");
588583
}
589584

590-
let mut is_new = false;
585+
let mut did_change_fonts = false;
591586

592-
let fonts = self.fonts.get_or_insert_with(|| {
593-
#[cfg(feature = "log")]
594-
log::trace!("Creating new Fonts for pixels_per_point={pixels_per_point}");
587+
// If we changed the font definitions this frame, or self.fonts previously did not exist, new_font_definitions
588+
// must be Cow::Owned. Set the font definitions.
589+
let fonts = if let Cow::Owned(new_font_definitions) = new_font_definitions {
590+
did_change_fonts = true;
591+
if let Some(fonts) = self.fonts.as_mut() {
592+
fonts.set_definitions(new_font_definitions);
593+
did_change_fonts = true;
594+
fonts
595+
} else {
596+
self.fonts.get_or_insert_with(|| {
597+
#[cfg(feature = "log")]
598+
log::trace!("Creating new FontStore");
595599

596-
is_new = true;
597-
profiling::scope!("FontStore::new");
598-
FontStore::new(max_texture_side, self.font_definitions.clone())
599-
});
600+
did_change_fonts = true;
601+
profiling::scope!("FontStore::new");
602+
FontStore::new(max_texture_side, new_font_definitions)
603+
})
604+
}
605+
} else {
606+
self.fonts
607+
.as_mut()
608+
.expect("new_font_definitions is borrowed, but we had nowhere to borrow it from")
609+
};
600610

601611
{
602612
profiling::scope!("FontStore::begin_pass");
603613
fonts.begin_pass(max_texture_side);
604614
}
605615

606-
if is_new && self.memory.options.preload_font_glyphs {
616+
if did_change_fonts && self.memory.options.preload_font_glyphs {
607617
profiling::scope!("preload_font_glyphs");
608618
// Preload the most common characters for the most common fonts.
609619
// This is not very important to do, but may save a few GPU operations.
610620
for font_id in self.memory.options.style().text_styles.values() {
611-
fonts.font(font_id).preload_common_characters();
621+
fonts.preload_common_characters(font_id);
612622
}
613623
}
614624
}
@@ -1490,11 +1500,10 @@ impl Context {
14901500

14911501
let font_id = TextStyle::Body.resolve(&self.style());
14921502
self.fonts(|f| {
1493-
let font = f.font(&font_id);
1494-
font.has_glyphs(alt)
1495-
&& font.has_glyphs(ctrl)
1496-
&& font.has_glyphs(shift)
1497-
&& font.has_glyphs(mac_cmd)
1503+
f.has_glyphs_for(&font_id, alt)
1504+
&& f.has_glyphs_for(&font_id, ctrl)
1505+
&& f.has_glyphs_for(&font_id, shift)
1506+
&& f.has_glyphs_for(&font_id, mac_cmd)
14981507
})
14991508
};
15001509

@@ -2904,7 +2913,7 @@ impl Context {
29042913
}
29052914

29062915
fn fonts_tweak_ui(&self, ui: &mut Ui) {
2907-
let mut font_definitions = self.write(|ctx| ctx.font_definitions.clone());
2916+
let mut font_definitions = self.fonts(|fonts| fonts.definitions().clone());
29082917
let mut changed = false;
29092918

29102919
for (name, data) in &mut font_definitions.font_data {

crates/egui/src/debug_text.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
//! The plugin registers itself onto a specific [`Context`]
66
//! to get callbacks on certain events ([`Context::on_begin_pass`], [`Context::on_end_pass`]).
77
8-
use crate::{
9-
text, Align, Align2, Color32, Context, FontFamily, FontId, Id, Rect, Shape, Vec2, WidgetText,
10-
};
8+
use epaint::text::{FontStyle, GenericFamily};
9+
10+
use crate::{text, Align, Align2, Color32, Context, Id, Rect, Shape, Vec2, WidgetText};
1111

1212
/// Register this plugin on the given egui context,
1313
/// so that it will be called every pass.
@@ -92,7 +92,7 @@ impl State {
9292
let mut bounding_rect = Rect::from_points(&[pos]);
9393

9494
let color = Color32::GRAY;
95-
let font_id = FontId::new(10.0, FontFamily::Proportional);
95+
let font_id = FontStyle::simple(10.0, GenericFamily::SystemUi);
9696

9797
for Entry { location, text } in entries {
9898
{

crates/egui/src/input_state/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::{
1414
};
1515

1616
pub use crate::Key;
17+
use epaint::text::GenericFamily;
1718
pub use touch_state::MultiTouchInfo;
1819
use touch_state::TouchState;
1920

@@ -1386,7 +1387,7 @@ impl InputState {
13861387
.text_styles
13871388
.get_mut(&crate::TextStyle::Body)
13881389
.unwrap()
1389-
.family = crate::FontFamily::Monospace;
1390+
.family = GenericFamily::Monospace.into();
13901391

13911392
ui.collapsing("Raw Input", |ui| raw.ui(ui));
13921393

crates/egui/src/introspection.rs

+10-15
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
//! Showing UI:s for egui/epaint types.
2+
use epaint::text::FontStyle;
3+
24
use crate::{
3-
epaint, memory, pos2, remap_clamp, vec2, Color32, CursorIcon, FontFamily, FontId, Label, Mesh,
4-
NumExt, Rect, Response, Sense, Shape, Slider, TextStyle, TextWrapMode, Ui, Widget,
5+
epaint, memory, pos2, remap_clamp, vec2, Color32, CursorIcon, FontFamily, Label, Mesh, NumExt,
6+
Rect, Response, Sense, Shape, Slider, TextStyle, TextWrapMode, Ui, Widget,
57
};
68

7-
pub fn font_family_ui(ui: &mut Ui, font_family: &mut FontFamily) {
8-
let families = ui.fonts(|f| f.families());
9-
ui.horizontal(|ui| {
10-
for alternative in families {
11-
let text = alternative.to_string();
12-
ui.radio_value(font_family, alternative, text);
13-
}
14-
});
15-
}
9+
// TODO(valadaptive): reinstate font_family_ui? It wasn't used anywhere, even in the demo app...
1610

17-
pub fn font_id_ui(ui: &mut Ui, font_id: &mut FontId) {
18-
let families = ui.fonts(|f| f.families());
11+
pub fn font_id_ui(ui: &mut Ui, font_id: &mut FontStyle) {
12+
// TODO(valadaptive)
13+
/*let families = ui.fonts(|f| f.families());
1914
ui.horizontal(|ui| {
2015
ui.add(Slider::new(&mut font_id.size, 4.0..=40.0).max_decimals(1));
2116
for alternative in families {
2217
let text = alternative.to_string();
23-
ui.radio_value(&mut font_id.family, alternative, text);
18+
ui.radio_value(&mut font_id.family, alternative.into(), text);
2419
}
25-
});
20+
});*/
2621
}
2722

2823
// Show font texture in demo Ui

crates/egui/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ pub use emath::{
464464
};
465465
pub use epaint::{
466466
mutex,
467-
text::{FontData, FontDefinitions, FontFamily, FontId, FontTweak},
467+
text::{FontData, FontDefinitions, FontFamily, FontStack, FontStyle, FontTweak},
468468
textures::{TextureFilter, TextureOptions, TextureWrapMode, TexturesDelta},
469469
ClippedPrimitive, ColorImage, CornerRadius, ImageData, Margin, Mesh, PaintCallback,
470470
PaintCallbackInfo, Shadow, Shape, Stroke, StrokeKind, TextureHandle, TextureId,

crates/egui/src/memory/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ pub struct Options {
277277
///
278278
/// This can lead to fewer texture operations, but may use up the texture atlas quicker
279279
/// if you are changing [`Style::text_styles`], or have a lot of text styles.
280+
///
281+
/// TODO(valadaptive): preload_font_glyphs used to do something, but the new text layout code rasterizes at subpixel
282+
/// offsets, and I don't feel like rasterizing all 4 offsets for every glyph ahead of time. Is preload_font_glyphs
283+
/// actually useful or just a placebo?
280284
pub preload_font_glyphs: bool,
281285

282286
/// Check reusing of [`Id`]s, and show a visual warning on screen when one is found.

0 commit comments

Comments
 (0)