1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 21:00:03 -04:00

Add emath::OrderedFloat (moved from epaint::util::OrderedFloat) (#4389)

It makes much more sense in `emath`
This commit is contained in:
Emil Ernerfeldt
2024-04-21 20:36:32 +02:00
committed by GitHub
parent 46b241eb94
commit 87b294534e
14 changed files with 57 additions and 90 deletions

View File

@@ -8,7 +8,7 @@ use crate::{
},
TextureAtlas,
};
use emath::NumExt as _;
use emath::{NumExt as _, OrderedFloat};
// ----------------------------------------------------------------------------
@@ -56,7 +56,7 @@ impl std::hash::Hash for FontId {
#[inline(always)]
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
let Self { size, family } = self;
crate::f32_hash(state, *size);
emath::OrderedFloat(*size).hash(state);
family.hash(state);
}
}
@@ -567,21 +567,6 @@ impl FontsAndCache {
// ----------------------------------------------------------------------------
#[derive(Clone, Copy, Debug, PartialEq)]
struct HashableF32(f32);
#[allow(clippy::derived_hash_with_manual_eq)]
impl std::hash::Hash for HashableF32 {
#[inline(always)]
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
crate::f32_hash(state, self.0);
}
}
impl Eq for HashableF32 {}
// ----------------------------------------------------------------------------
/// The collection of fonts used by `epaint`.
///
/// Required in order to paint text.
@@ -591,7 +576,7 @@ pub struct FontsImpl {
definitions: FontDefinitions,
atlas: Arc<Mutex<TextureAtlas>>,
font_impl_cache: FontImplCache,
sized_family: ahash::HashMap<(HashableF32, FontFamily), Font>,
sized_family: ahash::HashMap<(OrderedFloat<f32>, FontFamily), Font>,
}
impl FontsImpl {
@@ -641,7 +626,7 @@ impl FontsImpl {
let FontId { size, family } = font_id;
self.sized_family
.entry((HashableF32(*size), family.clone()))
.entry((OrderedFloat(*size), family.clone()))
.or_insert_with(|| {
let fonts = &self.definitions.families.get(family);
let fonts = fonts

View File

@@ -185,7 +185,7 @@ impl std::hash::Hash for LayoutJob {
text.hash(state);
sections.hash(state);
wrap.hash(state);
crate::f32_hash(state, *first_row_min_height);
emath::OrderedFloat(*first_row_min_height).hash(state);
break_on_newline.hash(state);
halign.hash(state);
justify.hash(state);
@@ -214,7 +214,7 @@ impl std::hash::Hash for LayoutSection {
byte_range,
format,
} = self;
crate::f32_hash(state, *leading_space);
OrderedFloat(*leading_space).hash(state);
byte_range.hash(state);
format.hash(state);
}
@@ -293,9 +293,9 @@ impl std::hash::Hash for TextFormat {
valign,
} = self;
font_id.hash(state);
crate::f32_hash(state, *extra_letter_spacing);
emath::OrderedFloat(*extra_letter_spacing).hash(state);
if let Some(line_height) = *line_height {
crate::f32_hash(state, line_height);
emath::OrderedFloat(line_height).hash(state);
}
color.hash(state);
background.hash(state);
@@ -375,7 +375,7 @@ impl std::hash::Hash for TextWrapping {
break_anywhere,
overflow_character,
} = self;
crate::f32_hash(state, *max_width);
emath::OrderedFloat(*max_width).hash(state);
max_rows.hash(state);
break_anywhere.hash(state);
overflow_character.hash(state);