Skip to content

Commit acb0752

Browse files
committed
Update egui and use new egui::GuiRounding trait to round
1 parent ee78393 commit acb0752

File tree

40 files changed

+218
-248
lines changed

40 files changed

+218
-248
lines changed

Cargo.lock

+129-134
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ doc_markdown = { level = "allow", priority = 21 }
134134
#egui_kittest = { path = "../../IdeaProjects/egui/crates/egui_kittest" }
135135
#winit = { path = "../../IdeaProjects/github/winit" }
136136

137-
#
138-
#egui = { git = "https://github.com/emilk/egui", branch = "master" }
139-
#eframe = { git = "https://github.com/emilk/egui", branch = "master" }
140-
#egui_extras = { git = "https://github.com/emilk/egui", branch = "master" }
141-
#egui_kittest = { git = "https://github.com/emilk/egui", branch = "master" }
137+
138+
egui = { git = "https://github.com/emilk/egui", branch = "master" }
139+
eframe = { git = "https://github.com/emilk/egui", branch = "master" }
140+
egui_extras = { git = "https://github.com/emilk/egui", branch = "master" }
141+
egui_kittest = { git = "https://github.com/emilk/egui", branch = "master" }

crates/egui_flex/src/lib.rs

+13-38
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
mod flex_widget;
66

77
pub use crate::flex_widget::FlexWidget;
8-
use egui::emath::TSTransform;
8+
use egui::emath::{GuiRounding, TSTransform};
99
use egui::{
1010
Align, Align2, Direction, Frame, Id, InnerResponse, Layout, Margin, Pos2, Rect, Response,
1111
Sense, Ui, UiBuilder, Vec2, Widget,
@@ -497,7 +497,7 @@ impl Flex {
497497
let r = ui.scope_builder(
498498
UiBuilder::new()
499499
.layout(layout)
500-
.max_rect(round_rect(ui.available_rect_before_wrap())),
500+
.max_rect(ui.available_rect_before_wrap().round_ui()),
501501
|ui| {
502502
let gap = self.gap.unwrap_or(ui.spacing_mut().item_spacing);
503503
let original_item_spacing = mem::replace(&mut ui.spacing_mut().item_spacing, gap);
@@ -513,8 +513,8 @@ impl Flex {
513513
// let size_origin = parent_rect.size();
514514

515515
let size = [
516-
width.map(|w| round(w.get(size_origin.x))),
517-
height.map(|h| round(h.get(size_origin.y))),
516+
width.map(|w| w.get(size_origin.x).round_ui()),
517+
height.map(|h| h.get(size_origin.y).round_ui()),
518518
];
519519

520520
let direction = usize::from(!ui.layout().main_dir().is_horizontal());
@@ -530,7 +530,7 @@ impl Flex {
530530
ui.min_rect().min,
531531
);
532532

533-
let max_item_size = round_vec2(max_item_size.unwrap_or(available_size));
533+
let max_item_size = max_item_size.unwrap_or(available_size).round_ui();
534534

535535
let mut instance = FlexInstance {
536536
current_row: 0,
@@ -758,8 +758,8 @@ impl Flex {
758758
row.extra_start_gap = row.extra_gap;
759759
}
760760
}
761-
row.extra_gap = round(row.extra_gap).max(0.0);
762-
row.extra_start_gap = round(row.extra_start_gap).max(0.0);
761+
row.extra_gap = f32::max(row.extra_gap.round_ui(), 0.0);
762+
row.extra_start_gap = f32::max(row.extra_start_gap.round_ui(), 0.0);
763763
}
764764
}
765765
rows
@@ -1129,15 +1129,16 @@ impl FlexInstance<'_> {
11291129
}
11301130

11311131
let item = ItemState {
1132-
inner_size: round_vec2(inner_size),
1132+
inner_size: inner_size.round_ui(),
11331133
id: ui.id(),
1134-
inner_min_size: round_vec2(Vec2::max(
1134+
inner_min_size: Vec2::max(
11351135
Vec2::new(
11361136
item.min_size[0].unwrap_or_default(),
11371137
item.min_size[1].unwrap_or_default(),
11381138
) - frame.total_margin().sum(),
11391139
inner_size,
1140-
)),
1140+
)
1141+
.round_ui(),
11411142
config: item.into_state(),
11421143
remeasure_widget: res.remeasure_widget,
11431144
};
@@ -1408,7 +1409,8 @@ impl FlexContainerUi {
14081409
// If the size changed in the cross direction the widget might have grown in the main direction
14091410
// and wrapped, we need to remeasure the widget (draw it once with full available size)
14101411
let remeasure_widget = self.last_inner_size.is_some_and(|last_size| {
1411-
round(last_size[1 - self.direction]) != round(intrinsic_size[1 - self.direction])
1412+
last_size[1 - self.direction].round_ui()
1413+
!= intrinsic_size[1 - self.direction].round_ui()
14121414
}) && !self.remeasure_widget;
14131415

14141416
if remeasure_widget {
@@ -1424,30 +1426,3 @@ impl FlexContainerUi {
14241426
}
14251427
}
14261428
}
1427-
1428-
/// Round a float to 5 decimal places.
1429-
fn round(i: f32) -> f32 {
1430-
const PRECISION: f32 = 1e3;
1431-
let i = (i * PRECISION).round() / PRECISION;
1432-
// I've seen this flip from 0.0 to -0.0 in a discard-loop
1433-
if i == -0.0 {
1434-
0.0
1435-
} else {
1436-
i
1437-
}
1438-
}
1439-
1440-
fn round_vec2(v: Vec2) -> Vec2 {
1441-
Vec2::new(round(v.x), round(v.y))
1442-
}
1443-
1444-
fn round_pos2(p: Pos2) -> Pos2 {
1445-
Pos2::new(round(p.x), round(p.y))
1446-
}
1447-
1448-
fn round_rect(rect: Rect) -> Rect {
1449-
Rect {
1450-
min: round_pos2(rect.min),
1451-
max: round_pos2(rect.max),
1452-
}
1453-
}
+2-2
Loading
Loading
+2-2
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

crates/egui_form/screenshot.png

-71.8 KB
Loading
+2-2
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
+2-2
Loading
Loading

0 commit comments

Comments
 (0)