Replace `Id::null()` with `Id::NULL` (#3544)
Shorter and more idiomatic
This commit is contained in:
parent
b27aa27e94
commit
6ba356d3d8
|
@ -13,11 +13,11 @@ pub(crate) struct TooltipState {
|
|||
|
||||
impl TooltipState {
|
||||
pub fn load(ctx: &Context) -> Option<Self> {
|
||||
ctx.data_mut(|d| d.get_temp(Id::null()))
|
||||
ctx.data_mut(|d| d.get_temp(Id::NULL))
|
||||
}
|
||||
|
||||
fn store(self, ctx: &Context) {
|
||||
ctx.data_mut(|d| d.insert_temp(Id::null(), self));
|
||||
ctx.data_mut(|d| d.insert_temp(Id::NULL, self));
|
||||
}
|
||||
|
||||
fn individual_tooltip_size(&self, common_id: Id, index: usize) -> Option<Vec2> {
|
||||
|
|
|
@ -35,6 +35,9 @@ impl Id {
|
|||
///
|
||||
/// The null [`Id`] is still a valid id to use in all circumstances,
|
||||
/// though obviously it will lead to a lot of collisions if you do use it!
|
||||
pub const NULL: Self = Self(0);
|
||||
|
||||
#[deprecated = "Use Id::NULL"]
|
||||
pub fn null() -> Self {
|
||||
Self(0)
|
||||
}
|
||||
|
|
|
@ -442,5 +442,5 @@ fn color_cache_set(ctx: &Context, rgba: impl Into<Rgba>, hsva: Hsva) {
|
|||
|
||||
// To ensure we keep hue slider when `srgba` is gray we store the full [`Hsva`] in a cache:
|
||||
fn use_color_cache<R>(ctx: &Context, f: impl FnOnce(&mut FixedCache<Rgba, Hsva>) -> R) -> R {
|
||||
ctx.data_mut(|d| f(d.get_temp_mut_or_default(Id::null())))
|
||||
ctx.data_mut(|d| f(d.get_temp_mut_or_default(Id::NULL)))
|
||||
}
|
||||
|
|
|
@ -248,7 +248,7 @@ impl CodeTheme {
|
|||
/// Show UI for changing the color theme.
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui) {
|
||||
ui.horizontal_top(|ui| {
|
||||
let selected_id = egui::Id::null();
|
||||
let selected_id = egui::Id::NULL;
|
||||
let mut selected_tt: TokenType =
|
||||
ui.data_mut(|d| *d.get_persisted_mut_or(selected_id, TokenType::Comment));
|
||||
|
||||
|
|
|
@ -807,7 +807,7 @@ impl Plot {
|
|||
if let Some((name, _)) = linked_axes.as_ref() {
|
||||
ui.memory_mut(|memory| {
|
||||
let link_groups: &mut BoundsLinkGroups =
|
||||
memory.data.get_temp_mut_or_default(Id::null());
|
||||
memory.data.get_temp_mut_or_default(Id::NULL);
|
||||
link_groups.0.remove(name);
|
||||
});
|
||||
};
|
||||
|
@ -892,7 +892,7 @@ impl Plot {
|
|||
// Find the cursors from other plots we need to draw
|
||||
let draw_cursors: Vec<Cursor> = if let Some((id, _)) = linked_cursors.as_ref() {
|
||||
ui.memory_mut(|memory| {
|
||||
let frames: &mut CursorLinkGroups = memory.data.get_temp_mut_or_default(Id::null());
|
||||
let frames: &mut CursorLinkGroups = memory.data.get_temp_mut_or_default(Id::NULL);
|
||||
let cursors = frames.0.entry(*id).or_default();
|
||||
|
||||
// Look for our previous frame
|
||||
|
@ -921,7 +921,7 @@ impl Plot {
|
|||
if let Some((id, axes)) = linked_axes.as_ref() {
|
||||
ui.memory_mut(|memory| {
|
||||
let link_groups: &mut BoundsLinkGroups =
|
||||
memory.data.get_temp_mut_or_default(Id::null());
|
||||
memory.data.get_temp_mut_or_default(Id::NULL);
|
||||
if let Some(linked_bounds) = link_groups.0.get(id) {
|
||||
if axes.x {
|
||||
bounds.set_x(&linked_bounds.bounds);
|
||||
|
@ -1164,7 +1164,7 @@ impl Plot {
|
|||
if let Some((id, _)) = linked_cursors.as_ref() {
|
||||
// Push the frame we just drew to the list of frames
|
||||
ui.memory_mut(|memory| {
|
||||
let frames: &mut CursorLinkGroups = memory.data.get_temp_mut_or_default(Id::null());
|
||||
let frames: &mut CursorLinkGroups = memory.data.get_temp_mut_or_default(Id::NULL);
|
||||
let cursors = frames.0.entry(*id).or_default();
|
||||
cursors.push(PlotFrameCursors {
|
||||
id: plot_id,
|
||||
|
@ -1177,7 +1177,7 @@ impl Plot {
|
|||
// Save the linked bounds.
|
||||
ui.memory_mut(|memory| {
|
||||
let link_groups: &mut BoundsLinkGroups =
|
||||
memory.data.get_temp_mut_or_default(Id::null());
|
||||
memory.data.get_temp_mut_or_default(Id::NULL);
|
||||
link_groups.0.insert(
|
||||
*id,
|
||||
LinkedBounds {
|
||||
|
|
|
@ -55,21 +55,15 @@ pub use {
|
|||
|
||||
/// Helper trait to implement [`lerp`] and [`remap`].
|
||||
pub trait One {
|
||||
fn one() -> Self;
|
||||
const ONE: Self;
|
||||
}
|
||||
|
||||
impl One for f32 {
|
||||
#[inline(always)]
|
||||
fn one() -> Self {
|
||||
1.0
|
||||
}
|
||||
const ONE: Self = 1.0;
|
||||
}
|
||||
|
||||
impl One for f64 {
|
||||
#[inline(always)]
|
||||
fn one() -> Self {
|
||||
1.0
|
||||
}
|
||||
const ONE: Self = 1.0;
|
||||
}
|
||||
|
||||
/// Helper trait to implement [`lerp`] and [`remap`].
|
||||
|
@ -107,7 +101,7 @@ where
|
|||
R: Copy + Add<R, Output = R>,
|
||||
{
|
||||
let range = range.into();
|
||||
(T::one() - t) * *range.start() + t * *range.end()
|
||||
(T::ONE - t) * *range.start() + t * *range.end()
|
||||
}
|
||||
|
||||
/// Where in the range is this value? Returns 0-1 if within the range.
|
||||
|
@ -174,7 +168,7 @@ where
|
|||
crate::emath_assert!(from.start() != from.end());
|
||||
let t = (x - *from.start()) / (*from.end() - *from.start());
|
||||
// Ensure no numerical inaccuracies sneak in:
|
||||
if T::one() <= t {
|
||||
if T::ONE <= t {
|
||||
*to.end()
|
||||
} else {
|
||||
lerp(to, t)
|
||||
|
|
Loading…
Reference in New Issue