Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ isse = "isse" # part of @IsseW username
tye = "tye" # part of @tye-exe username
ro = "ro" # read-only, also part of the username @Phen-Ro
typ = "typ" # Often used because `type` is a keyword in Rust
wdth = "wdth" # The `wdth` tag is used in variable fonts

# I mistype these so often
tesalator = "tessellator"
Expand Down
6 changes: 6 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,7 @@ dependencies = [
"ecolor",
"emath",
"epaint_default_fonts",
"font-types",
"log",
"mimalloc",
"nohash-hasher",
Expand All @@ -1577,6 +1578,7 @@ dependencies = [
"serde",
"similar-asserts",
"skrifa",
"smallvec",
"vello_cpu",
]

Expand Down Expand Up @@ -1741,6 +1743,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1e4d2d0cf79d38430cc9dc9aadec84774bff2e1ba30ae2bf6c16cfce9385a23"
dependencies = [
"bytemuck",
"serde",
]

[[package]]
Expand Down Expand Up @@ -4136,6 +4139,9 @@ name = "smallvec"
version = "1.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
dependencies = [
"serde",
]

[[package]]
name = "smithay-client-toolkit"
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ document-features = "0.2.11"
ehttp = { version = "0.6.0", default-features = false }
enum-map = "2.7.3"
env_logger = { version = "0.11.8", default-features = false }
font-types = { version = "0.11.0", default-features = false, features = ["std"] }
glow = "0.16.0"
glutin = { version = "0.32.3", default-features = false }
glutin-winit = { version = "0.5.0", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3262,7 +3262,7 @@ impl Context {

for (name, data) in &mut font_definitions.font_data {
ui.collapsing(name, |ui| {
let mut tweak = data.tweak;
let mut tweak = data.tweak.clone();
if tweak.ui(ui).changed() {
Arc::make_mut(data).tweak = tweak;
changed = true;
Expand Down
53 changes: 51 additions & 2 deletions crates/egui/src/style.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
//! egui theme (spacing, colors, etc).

use emath::Align;
use epaint::{AlphaFromCoverage, CornerRadius, Shadow, Stroke, TextOptions, text::FontTweak};
use epaint::{
AlphaFromCoverage, CornerRadius, Shadow, Stroke, TextOptions,
mutex::Mutex,
text::{FontTweak, Tag},
};
use std::{collections::BTreeMap, ops::RangeInclusive, sync::Arc};

use crate::{
Expand Down Expand Up @@ -2837,7 +2841,7 @@ impl Widget for &mut crate::Frame {

impl Widget for &mut FontTweak {
fn ui(self, ui: &mut Ui) -> Response {
let original: FontTweak = *self;
let original: FontTweak = self.clone();

let mut response = Grid::new("font_tweak")
.num_columns(2)
Expand All @@ -2847,6 +2851,7 @@ impl Widget for &mut FontTweak {
y_offset_factor,
y_offset,
hinting_override,
coords,
} = self;

ui.label("Scale");
Expand Down Expand Up @@ -2874,6 +2879,50 @@ impl Widget for &mut FontTweak {
ui.selectable_value(hinting_override, Some(true), "Enable");
ui.selectable_value(hinting_override, Some(false), "Disable");
});
ui.end_row();

ui.label("coords");
ui.end_row();
let mut to_remove = None;
for (i, (tag, value)) in coords.as_mut().iter_mut().enumerate() {
let tag_text = ui.ctx().data_mut(|data| {
let tag = *tag;
Arc::clone(data.get_temp_mut_or_insert_with(ui.id().with(i), move || {
Arc::new(Mutex::new(tag.to_string()))
}))
});

let tag_text = &mut *tag_text.lock();
let response = ui.text_edit_singleline(tag_text);
if response.changed()
&& let Ok(new_tag) = Tag::new_checked(tag_text.as_bytes())
{
*tag = new_tag;
}
// Reset stale text when not actively editing
// (e.g. after an item was removed and indices shifted)
if !response.has_focus()
&& Tag::new_checked(tag_text.as_bytes()).ok() != Some(*tag)
{
*tag_text = tag.to_string();
}

ui.add(DragValue::new(value));
if ui.small_button("🗑").clicked() {
to_remove = Some(i);
}
ui.end_row();
}
if let Some(i) = to_remove {
coords.remove(i);
}
if ui.button("Add coord").clicked() {
coords.push(b"wght", 0.0);
}
if ui.button("Clear coords").clicked() {
coords.clear();
}
ui.end_row();
Comment thread
emilk marked this conversation as resolved.

if ui.button("Reset").clicked() {
*self = Default::default();
Expand Down
23 changes: 22 additions & 1 deletion crates/egui/src/widget_text.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use emath::GuiRounding as _;
use epaint::text::TextFormat;
use epaint::text::{IntoTag, TextFormat, VariationCoords};
use std::fmt::Formatter;
use std::{borrow::Cow, sync::Arc};

Expand Down Expand Up @@ -34,6 +34,7 @@ pub struct RichText {
background_color: Color32,
expand_bg: f32,
text_color: Option<Color32>,
coords: VariationCoords,
code: bool,
strong: bool,
weak: bool,
Expand All @@ -55,6 +56,7 @@ impl Default for RichText {
background_color: Default::default(),
expand_bg: 1.0,
text_color: Default::default(),
coords: Default::default(),
code: Default::default(),
strong: Default::default(),
weak: Default::default(),
Expand Down Expand Up @@ -196,6 +198,23 @@ impl RichText {
self
}

/// Add a variation coordinate.
#[inline]
pub fn variation(mut self, tag: impl IntoTag, coord: f32) -> Self {
self.coords.push(tag, coord);
self
}

/// Override the variation coordinates completely.
#[inline]
pub fn variations<T: IntoTag>(
mut self,
variations: impl IntoIterator<Item = (T, f32)>,
) -> Self {
self.coords = VariationCoords::new(variations);
self
}

/// Override the [`TextStyle`].
#[inline]
pub fn text_style(mut self, text_style: TextStyle) -> Self {
Expand Down Expand Up @@ -391,6 +410,7 @@ impl RichText {
background_color,
expand_bg,
text_color: _, // already used by `get_text_color`
coords,
code,
strong: _, // already used by `get_text_color`
weak: _, // already used by `get_text_color`
Expand Down Expand Up @@ -449,6 +469,7 @@ impl RichText {
line_height,
color: text_color,
background: background_color,
coords,
italics,
underline,
strikethrough,
Expand Down
4 changes: 3 additions & 1 deletion crates/epaint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mint = ["emath/mint"]
rayon = ["dep:rayon"]

## Allow serialization using [`serde`](https://docs.rs/serde).
serde = ["dep:serde", "ahash/serde", "emath/serde", "ecolor/serde"]
serde = ["dep:serde", "ahash/serde", "emath/serde", "ecolor/serde", "font-types/serde", "smallvec/serde"]

## Change Vertex layout to be compatible with unity
unity = []
Expand All @@ -62,12 +62,14 @@ emath.workspace = true
ecolor.workspace = true

ahash.workspace = true
font-types.workspace = true
log.workspace = true
nohash-hasher.workspace = true
parking_lot.workspace = true # Using parking_lot over std::sync::Mutex gives 50% speedups in some real-world scenarios.
profiling.workspace = true
self_cell.workspace = true
skrifa.workspace = true
smallvec.workspace = true
vello_cpu.workspace = true

#! ### Optional dependencies
Expand Down
Loading