mirror of
https://github.com/emilk/egui.git
synced 2026-07-10 00:37:27 +00:00
5f88d89f74
* Speed up galley cache by only using the hash as key This hashes the job but doesn't compare them with Eq, which speeds up demo_with_tessellate__realistic by 5-6%, winning back all the performance lost in https://github.com/emilk/egui/pull/682 * Remove custom Eq/PartialEq code for LayoutJob and friends * Silence clippy * Unrelated clippy fixes
49 lines
1.2 KiB
Rust
49 lines
1.2 KiB
Rust
#![allow(clippy::derive_hash_xor_eq)] // We need to impl Hash for f32, but we don't implement Eq, which is fine
|
|
|
|
use super::*;
|
|
|
|
/// Describes the width and color of a line.
|
|
///
|
|
/// The default stroke is the same as [`Stroke::none`].
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
|
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
|
|
pub struct Stroke {
|
|
pub width: f32,
|
|
pub color: Color32,
|
|
}
|
|
|
|
impl Stroke {
|
|
/// Same as [`Stroke::default`].
|
|
#[inline(always)]
|
|
pub fn none() -> Self {
|
|
Self::new(0.0, Color32::TRANSPARENT)
|
|
}
|
|
|
|
#[inline]
|
|
pub fn new(width: impl Into<f32>, color: impl Into<Color32>) -> Self {
|
|
Self {
|
|
width: width.into(),
|
|
color: color.into(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<Color> From<(f32, Color)> for Stroke
|
|
where
|
|
Color: Into<Color32>,
|
|
{
|
|
#[inline(always)]
|
|
fn from((width, color): (f32, Color)) -> Stroke {
|
|
Stroke::new(width, color)
|
|
}
|
|
}
|
|
|
|
impl std::hash::Hash for Stroke {
|
|
#[inline(always)]
|
|
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
|
let Self { width, color } = *self;
|
|
crate::f32_hash(state, width);
|
|
color.hash(state);
|
|
}
|
|
}
|