Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Id::null() with Id::NULL #3544

Merged
merged 2 commits into from
Nov 11, 2023
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
4 changes: 2 additions & 2 deletions crates/egui/src/containers/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
3 changes: 3 additions & 0 deletions crates/egui/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/widgets/color_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
2 changes: 1 addition & 1 deletion crates/egui_extras/src/syntax_highlighting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
10 changes: 5 additions & 5 deletions crates/egui_plot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,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);
});
};
Expand Down Expand Up @@ -925,7 +925,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
Expand Down Expand Up @@ -954,7 +954,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);
Expand Down Expand Up @@ -1197,7 +1197,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,
Expand All @@ -1210,7 +1210,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 {
Expand Down
16 changes: 5 additions & 11 deletions crates/emath/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,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`].
Expand Down Expand Up @@ -105,7 +99,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.
Expand Down Expand Up @@ -172,7 +166,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)
Expand Down
Loading