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

Update to egui 0 26 #41

Merged
merged 2 commits into from
Feb 13, 2024
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
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "egui-gizmo"
version = "0.15.0"
version = "0.16.0"
authors = ["Urho Laukkarinen <[email protected]>"]
edition = "2021"

Expand All @@ -17,7 +17,7 @@ exclude = ["/docs"]
members = ["demo"]

[dependencies]
egui = "0.25.0"
egui = "0.26"
glam = { version = "0.25.0", features = ["mint"] }
mint = "0.5"

Expand Down Expand Up @@ -176,4 +176,6 @@ undocumented_unsafe_blocks = "allow"
unwrap_used = "allow"
wildcard_imports = "allow"
large-types-passed-by-value = "allow"
needless-pass-by-value = "allow"
needless-pass-by-value = "allow"
needless_pass_by_ref_mut = "allow"
redundant_pub_crate = "allow"
7 changes: 2 additions & 5 deletions demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ edition = "2021"
license = "MIT"

[dependencies]
egui = "0.25"
bevy_egui_next = "0.26"
egui = "0.26"
egui-gizmo = { path = ".." }

[dependencies.bevy]
Expand All @@ -17,10 +18,6 @@ version = "0.12.1"
version = "0.12.1"
features = ["mint"]

[dependencies.bevy_egui]
git = "https://github.com/urholaukkarinen/bevy_egui.git"
rev="bc3dd1559e24ca0178ed1d2dfef07cb784437505"

[dependencies.bevy_infinite_grid]
git = "https://github.com/pcwalton/bevy_infinite_grid.git"
rev = "c752a23063b2b05163e307889eb276d6574115ab"
Expand Down
2 changes: 1 addition & 1 deletion demo/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::prelude::*;
use bevy::render::texture::{CompressedImageFormats, ImageFormat, ImageSampler, ImageType};
use bevy::window::PresentMode;
use bevy_egui::{egui, EguiContexts, EguiPlugin};
use bevy_egui_next::{egui, EguiContexts, EguiPlugin};
use bevy_infinite_grid::{InfiniteGridBundle, InfiniteGridPlugin, InfiniteGridSettings};
use egui::color_picker::Alpha;
use egui::{pos2, Align2, Color32, FontId, LayerId, Ui, Widget};
Expand Down
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,49 +83,49 @@ impl Gizmo {
}

/// Bounds of the viewport in pixels
pub fn viewport(mut self, viewport: Rect) -> Self {
pub const fn viewport(mut self, viewport: Rect) -> Self {
self.config.viewport = viewport;
self
}

/// Gizmo mode to use
pub fn mode(mut self, mode: GizmoMode) -> Self {
pub const fn mode(mut self, mode: GizmoMode) -> Self {
self.config.mode = mode;
self
}

/// Gizmo orientation to use
pub fn orientation(mut self, orientation: GizmoOrientation) -> Self {
pub const fn orientation(mut self, orientation: GizmoOrientation) -> Self {
self.config.orientation = orientation;
self
}

/// Whether snapping is enabled
pub fn snapping(mut self, snapping: bool) -> Self {
pub const fn snapping(mut self, snapping: bool) -> Self {
self.config.snapping = snapping;
self
}

/// Snap angle to use for rotation when snapping is enabled
pub fn snap_angle(mut self, snap_angle: f32) -> Self {
pub const fn snap_angle(mut self, snap_angle: f32) -> Self {
self.config.snap_angle = snap_angle;
self
}

/// Snap distance to use for translation when snapping is enabled
pub fn snap_distance(mut self, snap_distance: f32) -> Self {
pub const fn snap_distance(mut self, snap_distance: f32) -> Self {
self.config.snap_distance = snap_distance;
self
}

/// Snap distance to use for scaling when snapping is enabled
pub fn snap_scale(mut self, snap_scale: f32) -> Self {
pub const fn snap_scale(mut self, snap_scale: f32) -> Self {
self.config.snap_scale = snap_scale;
self
}

/// Visual configuration of the gizmo, such as colors and size
pub fn visuals(mut self, visuals: GizmoVisuals) -> Self {
pub const fn visuals(mut self, visuals: GizmoVisuals) -> Self {
self.config.visuals = visuals;
self
}
Expand Down
10 changes: 5 additions & 5 deletions src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub fn segment_to_segment(a1: DVec3, a2: DVec3, b1: DVec3, b2: DVec3) -> (f64, f
let d1 = a1 - b1;
let d = da.dot(d1);
let e = db.dot(d1);
let n = la * lb - dd * dd;
let n = la.mul_add(lb, -dd * dd);

let mut sn;
let mut tn;
Expand All @@ -72,8 +72,8 @@ pub fn segment_to_segment(a1: DVec3, a2: DVec3, b1: DVec3, b2: DVec3) -> (f64, f
tn = e;
td = lb;
} else {
sn = dd * e - lb * d;
tn = la * e - dd * d;
sn = dd.mul_add(e, -lb * d);
tn = la.mul_add(e, -dd * d);
if sn < 0.0 {
sn = 0.0;
tn = e;
Expand Down Expand Up @@ -176,8 +176,8 @@ pub fn world_to_screen(viewport: Rect, mvp: DMat4, pos: DVec3) -> Option<Pos2> {

/// Calculates 3d world coordinates from 2d screen coordinates
pub fn screen_to_world(viewport: Rect, mat: DMat4, pos: Pos2, z: f64) -> DVec3 {
let x = (((pos.x - viewport.min.x) / viewport.width()) * 2.0 - 1.0) as f64;
let y = (((pos.y - viewport.min.y) / viewport.height()) * 2.0 - 1.0) as f64;
let x = ((pos.x - viewport.min.x) / viewport.width()).mul_add(2.0, -1.0) as f64;
let y = ((pos.y - viewport.min.y) / viewport.height()).mul_add(2.0, -1.0) as f64;

let mut world_pos = mat * DVec4::new(x, -y, z, 1.0);

Expand Down
2 changes: 1 addition & 1 deletion src/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct Painter3d {
}

impl Painter3d {
pub fn new(painter: egui::Painter, mvp: DMat4, viewport: Rect) -> Self {
pub const fn new(painter: egui::Painter, mvp: DMat4, viewport: Rect) -> Self {
Self {
painter,
mvp,
Expand Down
17 changes: 10 additions & 7 deletions src/subgizmo/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ pub(crate) fn pick_arrow<T: SubGizmoKind>(
let width = (subgizmo.config.scale_factor * subgizmo.config.visuals.stroke_width) as f64;

let dir = gizmo_normal(&subgizmo.config, direction);
let start =
subgizmo.config.translation + (dir * (width * 0.5 + inner_circle_radius(&subgizmo.config)));
let start = subgizmo.config.translation
+ (dir * (width.mul_add(0.5, inner_circle_radius(&subgizmo.config))));

let length = (subgizmo.config.scale_factor * subgizmo.config.visuals.gizmo_size) as f64;

Expand Down Expand Up @@ -154,7 +154,7 @@ pub(crate) fn draw_arrow<T: SubGizmoKind>(
let width = (subgizmo.config.scale_factor * subgizmo.config.visuals.stroke_width) as f64;
let length = (subgizmo.config.scale_factor * subgizmo.config.visuals.gizmo_size) as f64;

let start = direction * (width * 0.5 + inner_circle_radius(&subgizmo.config));
let start = direction * width.mul_add(0.5, inner_circle_radius(&subgizmo.config));
let end = direction * length;
painter.line_segment(start, end, (subgizmo.config.visuals.stroke_width, color));

Expand Down Expand Up @@ -257,7 +257,7 @@ pub(crate) fn draw_circle<T: SubGizmoKind>(
}
}

pub(crate) fn plane_bitangent(direction: GizmoDirection) -> DVec3 {
pub(crate) const fn plane_bitangent(direction: GizmoDirection) -> DVec3 {
match direction {
GizmoDirection::X => DVec3::Y,
GizmoDirection::Y => DVec3::Z,
Expand All @@ -266,7 +266,7 @@ pub(crate) fn plane_bitangent(direction: GizmoDirection) -> DVec3 {
}
}

pub(crate) fn plane_tangent(direction: GizmoDirection) -> DVec3 {
pub(crate) const fn plane_tangent(direction: GizmoDirection) -> DVec3 {
match direction {
GizmoDirection::X => DVec3::Z,
GizmoDirection::Y => DVec3::X,
Expand All @@ -276,8 +276,11 @@ pub(crate) fn plane_tangent(direction: GizmoDirection) -> DVec3 {
}

pub(crate) fn plane_size(config: &GizmoConfig) -> f64 {
(config.scale_factor * (config.visuals.gizmo_size * 0.1 + config.visuals.stroke_width * 2.0))
as f64
(config.scale_factor
* config
.visuals
.gizmo_size
.mul_add(0.1, config.visuals.stroke_width * 2.0)) as f64
}

pub(crate) fn plane_local_origin(config: &GizmoConfig, direction: GizmoDirection) -> DVec3 {
Expand Down
6 changes: 3 additions & 3 deletions src/subgizmo/rotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl SubGizmo for RotationSubGizmo {
if config.snapping {
let stroke_width = stroke.0 / 2.0;
for i in 0..((TAU / config.snap_angle as f64) as usize + 1) {
let angle = i as f64 * config.snap_angle as f64 + end_angle;
let angle = (i as f64).mul_add(config.snap_angle as f64, end_angle);
let pos = DVec3::new(angle.cos(), 0.0, angle.sin());
painter.line_segment(
pos * radius * 1.1,
Expand All @@ -182,8 +182,8 @@ fn arc_angle(subgizmo: &SubGizmoConfig<Rotation>) -> f64 {
let min_dot = 0.990;
let max_dot = 0.995;

let mut angle =
f64::min(1.0, f64::max(0.0, dot - min_dot) / (max_dot - min_dot)) * FRAC_PI_2 + FRAC_PI_2;
let mut angle = f64::min(1.0, f64::max(0.0, dot - min_dot) / (max_dot - min_dot))
.mul_add(FRAC_PI_2, FRAC_PI_2);
if (angle - PI).abs() < 1e-2 {
angle = PI;
}
Expand Down
Loading