Use explicit emath to math alias

egui exports `emath` under its original name AND under the alias `math`
(for historical reasons).
This commit is contained in:
Emil Ernerfeldt 2021-02-14 10:44:46 +01:00
parent c376d0bb7e
commit 6d255cd179
18 changed files with 28 additions and 27 deletions

View file

@ -1,6 +1,6 @@
use std::collections::HashMap;
use crate::{math::remap_clamp, Id, InputState};
use crate::{emath::remap_clamp, Id, InputState};
#[derive(Clone, Default)]
pub(crate) struct AnimationManager {

View file

@ -116,7 +116,7 @@ pub(crate) fn paint_icon(ui: &mut Ui, openness: f32, response: &Response) {
let rect = rect.expand(visuals.expansion);
let mut points = vec![rect.left_top(), rect.right_top(), rect.center_bottom()];
use std::f32::consts::TAU;
let rotation = math::Rot2::from_angle(remap(openness, 0.0..=1.0, -TAU / 4.0..=0.0));
let rotation = emath::Rot2::from_angle(remap(openness, 0.0..=1.0, -TAU / 4.0..=0.0));
for p in &mut points {
*p = rect.center() + rotation * (*p - rect.center());
}

View file

@ -749,7 +749,7 @@ impl TitleBar {
self.title_label = self.title_label.text_color(style.fg_stroke.color);
let full_top_rect = Rect::from_x_y_ranges(self.rect.x_range(), self.min_rect.y_range());
let text_pos = math::align::center_size_in_rect(self.title_galley.size, full_top_rect);
let text_pos = emath::align::center_size_in_rect(self.title_galley.size, full_top_rect);
let text_pos = text_pos.left_top() - 1.5 * Vec2::Y; // HACK: center on x-height of text (looks better)
self.title_label
.paint_galley(ui, text_pos, self.title_galley);

View file

@ -1,6 +1,6 @@
//! The input needed by egui.
use crate::math::*;
use crate::emath::*;
/// What the integrations provides to egui at the start of each frame.
///

View file

@ -1,7 +1,6 @@
use crate::{math::*, util::History};
use std::collections::HashSet;
use crate::data::input::*;
use crate::{emath::*, util::History};
use std::collections::HashSet;
pub use crate::data::input::Key;

View file

@ -1,7 +1,7 @@
//! Handles paint layers, i.e. how things
//! are sometimes painted behind or in front of other things.
use crate::{math::Rect, Id, *};
use crate::{Id, *};
use epaint::ahash::AHashMap;
use epaint::{ClippedShape, Shape};

View file

@ -1,4 +1,4 @@
use crate::{math::*, Align};
use crate::{emath::*, Align};
// ----------------------------------------------------------------------------

View file

@ -121,10 +121,12 @@ mod ui;
pub mod util;
pub mod widgets;
pub use emath as math;
pub use epaint as paint;
pub use epaint::emath;
// Can't add deprecation notice due to https://github.com/rust-lang/rust/issues/30827
pub use emath as math;
pub use emath::{
clamp, lerp, pos2, remap, remap_clamp, vec2, Align, Align2, NumExt, Pos2, Rect, Vec2,
};

View file

@ -1,6 +1,6 @@
use crate::{
emath::{Align2, Pos2, Rect, Vec2},
layers::{LayerId, ShapeIdx},
math::{Align2, Pos2, Rect, Vec2},
paint::{
text::{Fonts, Galley, TextStyle},
Shape, Stroke,
@ -264,7 +264,7 @@ impl Painter {
/// Show an arrow starting at `origin` and going in the direction of `vec`, with the length `vec.length()`.
pub fn arrow(&self, origin: Pos2, vec: Vec2, stroke: Stroke) {
use crate::math::*;
use crate::emath::*;
let rot = Rot2::from_angle(std::f32::consts::TAU / 10.0);
let tip_length = vec.length() / 4.0;
let tip = origin + vec;

View file

@ -1,5 +1,5 @@
use crate::{
math::{lerp, Align, Pos2, Rect},
emath::{lerp, Align, Pos2, Rect},
PointerButton, NUM_POINTER_BUTTONS,
};
use crate::{CtxRef, Id, LayerId, Sense, Ui};

View file

@ -4,7 +4,7 @@
use crate::{
color::*,
math::*,
emath::*,
paint::{Shadow, Stroke, TextStyle},
Response,
};

View file

@ -156,7 +156,7 @@ impl<'a> Widget for DragValue<'a> {
let auto_decimals = (aim_rad / speed.abs()).log10().ceil().at_least(0.0) as usize;
let max_decimals = max_decimals.unwrap_or(auto_decimals + 2);
let auto_decimals = clamp(auto_decimals, min_decimals..=max_decimals);
let value_text = math::format_with_decimals_in_range(value, auto_decimals..=max_decimals);
let value_text = emath::format_with_decimals_in_range(value, auto_decimals..=max_decimals);
let kb_edit_id = ui.auto_id_with("edit");
let is_kb_editing = ui.memory().has_kb_focus(kb_edit_id);
@ -200,7 +200,7 @@ impl<'a> Widget for DragValue<'a> {
let delta_value = speed * delta_points;
if delta_value != 0.0 {
let new_value = value + delta_value as f64;
let new_value = math::round_to_decimals(new_value, auto_decimals);
let new_value = emath::round_to_decimals(new_value, auto_decimals);
let new_value = clamp(new_value, clamp_range);
set(&mut value_function, new_value);
// TODO: To make use or `smart_aim` for `DragValue` we need to store some state somewhere,

View file

@ -246,7 +246,7 @@ impl<'a> Slider<'a> {
value = clamp(value, self.range.clone());
}
if let Some(max_decimals) = self.max_decimals {
value = math::round_to_decimals(value, max_decimals);
value = emath::round_to_decimals(value, max_decimals);
}
set(&mut self.get_set_value, value);
}
@ -291,7 +291,7 @@ impl<'a> Slider<'a> {
if let Some(pointer_pos) = response.interact_pointer_pos() {
let new_value = if self.smart_aim {
let aim_radius = ui.input().aim_radius();
crate::math::smart_aim::best_in_range_f64(
emath::smart_aim::best_in_range_f64(
self.value_from_x(pointer_pos.x - aim_radius, x_range.clone()),
self.value_from_x(pointer_pos.x + aim_radius, x_range.clone()),
)
@ -400,13 +400,13 @@ impl<'a> Slider<'a> {
let auto_decimals = clamp(auto_decimals, min_decimals..=max_decimals);
if min_decimals == max_decimals {
math::format_with_minimum_decimals(value, max_decimals)
emath::format_with_minimum_decimals(value, max_decimals)
} else if value == 0.0 {
"0".to_owned()
} else if range == 0.0 {
value.to_string()
} else {
math::format_with_decimals_in_range(value, auto_decimals..=max_decimals)
emath::format_with_decimals_in_range(value, auto_decimals..=max_decimals)
}
}
}
@ -439,7 +439,7 @@ impl<'a> Widget for Slider<'a> {
// Helpers for converting slider range to/from normalized [0-1] range.
// Always clamps.
// Logarithmic sliders are allowed to include zero and infinity,
// even though mathematically it doesn't make sense.
// even though emathematically it doesn't make sense.
use std::f64::INFINITY;

View file

@ -35,7 +35,7 @@ impl super::View for DancingStrings {
let (_id, rect) = ui.allocate_space(desired_size);
let to_screen =
math::RectTransform::from_to(Rect::from_x_y_ranges(0.0..=1.0, -1.0..=1.0), rect);
emath::RectTransform::from_to(Rect::from_x_y_ranges(0.0..=1.0, -1.0..=1.0), rect);
let mut shapes = vec![];

View file

@ -151,8 +151,8 @@ impl FractalClock {
];
let hand_rotors = [
hands[0].length * math::Rot2::from_angle(hand_rotations[0]),
hands[1].length * math::Rot2::from_angle(hand_rotations[1]),
hands[0].length * emath::Rot2::from_angle(hand_rotations[0]),
hands[1].length * emath::Rot2::from_angle(hand_rotations[1]),
];
#[derive(Clone, Copy)]

View file

@ -1,7 +1,7 @@
#![allow(deprecated)] // legacy implement_vertex macro
use {
egui::{math::clamp, paint::Mesh, Color32, Rect},
egui::{emath::clamp, paint::Mesh, Color32, Rect},
glium::{
implement_vertex,
index::PrimitiveType,

View file

@ -5,7 +5,7 @@ use {
};
use egui::{
math::clamp,
emath::clamp,
paint::{Color32, Texture},
vec2,
};

View file

@ -7,7 +7,7 @@ use {
};
use egui::{
math::clamp,
emath::clamp,
paint::{Color32, Texture},
vec2,
};