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:
parent
c376d0bb7e
commit
6d255cd179
18 changed files with 28 additions and 27 deletions
|
@ -1,6 +1,6 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::{math::remap_clamp, Id, InputState};
|
use crate::{emath::remap_clamp, Id, InputState};
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
pub(crate) struct AnimationManager {
|
pub(crate) struct AnimationManager {
|
||||||
|
|
|
@ -116,7 +116,7 @@ pub(crate) fn paint_icon(ui: &mut Ui, openness: f32, response: &Response) {
|
||||||
let rect = rect.expand(visuals.expansion);
|
let rect = rect.expand(visuals.expansion);
|
||||||
let mut points = vec![rect.left_top(), rect.right_top(), rect.center_bottom()];
|
let mut points = vec![rect.left_top(), rect.right_top(), rect.center_bottom()];
|
||||||
use std::f32::consts::TAU;
|
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 {
|
for p in &mut points {
|
||||||
*p = rect.center() + rotation * (*p - rect.center());
|
*p = rect.center() + rotation * (*p - rect.center());
|
||||||
}
|
}
|
||||||
|
|
|
@ -749,7 +749,7 @@ impl TitleBar {
|
||||||
self.title_label = self.title_label.text_color(style.fg_stroke.color);
|
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 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)
|
let text_pos = text_pos.left_top() - 1.5 * Vec2::Y; // HACK: center on x-height of text (looks better)
|
||||||
self.title_label
|
self.title_label
|
||||||
.paint_galley(ui, text_pos, self.title_galley);
|
.paint_galley(ui, text_pos, self.title_galley);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! The input needed by egui.
|
//! The input needed by egui.
|
||||||
|
|
||||||
use crate::math::*;
|
use crate::emath::*;
|
||||||
|
|
||||||
/// What the integrations provides to egui at the start of each frame.
|
/// What the integrations provides to egui at the start of each frame.
|
||||||
///
|
///
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::{math::*, util::History};
|
|
||||||
use std::collections::HashSet;
|
|
||||||
|
|
||||||
use crate::data::input::*;
|
use crate::data::input::*;
|
||||||
|
use crate::{emath::*, util::History};
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
pub use crate::data::input::Key;
|
pub use crate::data::input::Key;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Handles paint layers, i.e. how things
|
//! Handles paint layers, i.e. how things
|
||||||
//! are sometimes painted behind or in front of other 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::ahash::AHashMap;
|
||||||
use epaint::{ClippedShape, Shape};
|
use epaint::{ClippedShape, Shape};
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{math::*, Align};
|
use crate::{emath::*, Align};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -121,10 +121,12 @@ mod ui;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
pub mod widgets;
|
pub mod widgets;
|
||||||
|
|
||||||
pub use emath as math;
|
|
||||||
pub use epaint as paint;
|
pub use epaint as paint;
|
||||||
pub use epaint::emath;
|
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::{
|
pub use emath::{
|
||||||
clamp, lerp, pos2, remap, remap_clamp, vec2, Align, Align2, NumExt, Pos2, Rect, Vec2,
|
clamp, lerp, pos2, remap, remap_clamp, vec2, Align, Align2, NumExt, Pos2, Rect, Vec2,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
|
emath::{Align2, Pos2, Rect, Vec2},
|
||||||
layers::{LayerId, ShapeIdx},
|
layers::{LayerId, ShapeIdx},
|
||||||
math::{Align2, Pos2, Rect, Vec2},
|
|
||||||
paint::{
|
paint::{
|
||||||
text::{Fonts, Galley, TextStyle},
|
text::{Fonts, Galley, TextStyle},
|
||||||
Shape, Stroke,
|
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()`.
|
/// 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) {
|
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 rot = Rot2::from_angle(std::f32::consts::TAU / 10.0);
|
||||||
let tip_length = vec.length() / 4.0;
|
let tip_length = vec.length() / 4.0;
|
||||||
let tip = origin + vec;
|
let tip = origin + vec;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
math::{lerp, Align, Pos2, Rect},
|
emath::{lerp, Align, Pos2, Rect},
|
||||||
PointerButton, NUM_POINTER_BUTTONS,
|
PointerButton, NUM_POINTER_BUTTONS,
|
||||||
};
|
};
|
||||||
use crate::{CtxRef, Id, LayerId, Sense, Ui};
|
use crate::{CtxRef, Id, LayerId, Sense, Ui};
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
color::*,
|
color::*,
|
||||||
math::*,
|
emath::*,
|
||||||
paint::{Shadow, Stroke, TextStyle},
|
paint::{Shadow, Stroke, TextStyle},
|
||||||
Response,
|
Response,
|
||||||
};
|
};
|
||||||
|
|
|
@ -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 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 max_decimals = max_decimals.unwrap_or(auto_decimals + 2);
|
||||||
let auto_decimals = clamp(auto_decimals, min_decimals..=max_decimals);
|
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 kb_edit_id = ui.auto_id_with("edit");
|
||||||
let is_kb_editing = ui.memory().has_kb_focus(kb_edit_id);
|
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;
|
let delta_value = speed * delta_points;
|
||||||
if delta_value != 0.0 {
|
if delta_value != 0.0 {
|
||||||
let new_value = value + delta_value as f64;
|
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);
|
let new_value = clamp(new_value, clamp_range);
|
||||||
set(&mut value_function, new_value);
|
set(&mut value_function, new_value);
|
||||||
// TODO: To make use or `smart_aim` for `DragValue` we need to store some state somewhere,
|
// TODO: To make use or `smart_aim` for `DragValue` we need to store some state somewhere,
|
||||||
|
|
|
@ -246,7 +246,7 @@ impl<'a> Slider<'a> {
|
||||||
value = clamp(value, self.range.clone());
|
value = clamp(value, self.range.clone());
|
||||||
}
|
}
|
||||||
if let Some(max_decimals) = self.max_decimals {
|
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);
|
set(&mut self.get_set_value, value);
|
||||||
}
|
}
|
||||||
|
@ -291,7 +291,7 @@ impl<'a> Slider<'a> {
|
||||||
if let Some(pointer_pos) = response.interact_pointer_pos() {
|
if let Some(pointer_pos) = response.interact_pointer_pos() {
|
||||||
let new_value = if self.smart_aim {
|
let new_value = if self.smart_aim {
|
||||||
let aim_radius = ui.input().aim_radius();
|
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()),
|
||||||
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);
|
let auto_decimals = clamp(auto_decimals, min_decimals..=max_decimals);
|
||||||
|
|
||||||
if 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 {
|
} else if value == 0.0 {
|
||||||
"0".to_owned()
|
"0".to_owned()
|
||||||
} else if range == 0.0 {
|
} else if range == 0.0 {
|
||||||
value.to_string()
|
value.to_string()
|
||||||
} else {
|
} 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.
|
// Helpers for converting slider range to/from normalized [0-1] range.
|
||||||
// Always clamps.
|
// Always clamps.
|
||||||
// Logarithmic sliders are allowed to include zero and infinity,
|
// 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;
|
use std::f64::INFINITY;
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ impl super::View for DancingStrings {
|
||||||
let (_id, rect) = ui.allocate_space(desired_size);
|
let (_id, rect) = ui.allocate_space(desired_size);
|
||||||
|
|
||||||
let to_screen =
|
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![];
|
let mut shapes = vec![];
|
||||||
|
|
||||||
|
|
|
@ -151,8 +151,8 @@ impl FractalClock {
|
||||||
];
|
];
|
||||||
|
|
||||||
let hand_rotors = [
|
let hand_rotors = [
|
||||||
hands[0].length * math::Rot2::from_angle(hand_rotations[0]),
|
hands[0].length * emath::Rot2::from_angle(hand_rotations[0]),
|
||||||
hands[1].length * math::Rot2::from_angle(hand_rotations[1]),
|
hands[1].length * emath::Rot2::from_angle(hand_rotations[1]),
|
||||||
];
|
];
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#![allow(deprecated)] // legacy implement_vertex macro
|
#![allow(deprecated)] // legacy implement_vertex macro
|
||||||
|
|
||||||
use {
|
use {
|
||||||
egui::{math::clamp, paint::Mesh, Color32, Rect},
|
egui::{emath::clamp, paint::Mesh, Color32, Rect},
|
||||||
glium::{
|
glium::{
|
||||||
implement_vertex,
|
implement_vertex,
|
||||||
index::PrimitiveType,
|
index::PrimitiveType,
|
||||||
|
|
|
@ -5,7 +5,7 @@ use {
|
||||||
};
|
};
|
||||||
|
|
||||||
use egui::{
|
use egui::{
|
||||||
math::clamp,
|
emath::clamp,
|
||||||
paint::{Color32, Texture},
|
paint::{Color32, Texture},
|
||||||
vec2,
|
vec2,
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,7 @@ use {
|
||||||
};
|
};
|
||||||
|
|
||||||
use egui::{
|
use egui::{
|
||||||
math::clamp,
|
emath::clamp,
|
||||||
paint::{Color32, Texture},
|
paint::{Color32, Texture},
|
||||||
vec2,
|
vec2,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue