5
5
mod flex_widget;
6
6
7
7
pub use crate :: flex_widget:: FlexWidget ;
8
- use egui:: emath:: TSTransform ;
8
+ use egui:: emath:: { GuiRounding , TSTransform } ;
9
9
use egui:: {
10
10
Align , Align2 , Direction , Frame , Id , InnerResponse , Layout , Margin , Pos2 , Rect , Response ,
11
11
Sense , Ui , UiBuilder , Vec2 , Widget ,
@@ -497,7 +497,7 @@ impl Flex {
497
497
let r = ui. scope_builder (
498
498
UiBuilder :: new ( )
499
499
. layout ( layout)
500
- . max_rect ( round_rect ( ui. available_rect_before_wrap ( ) ) ) ,
500
+ . max_rect ( ui. available_rect_before_wrap ( ) . round_ui ( ) ) ,
501
501
|ui| {
502
502
let gap = self . gap . unwrap_or ( ui. spacing_mut ( ) . item_spacing ) ;
503
503
let original_item_spacing = mem:: replace ( & mut ui. spacing_mut ( ) . item_spacing , gap) ;
@@ -513,8 +513,8 @@ impl Flex {
513
513
// let size_origin = parent_rect.size();
514
514
515
515
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 ( ) ) ,
518
518
] ;
519
519
520
520
let direction = usize:: from ( !ui. layout ( ) . main_dir ( ) . is_horizontal ( ) ) ;
@@ -530,7 +530,7 @@ impl Flex {
530
530
ui. min_rect ( ) . min ,
531
531
) ;
532
532
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 ( ) ;
534
534
535
535
let mut instance = FlexInstance {
536
536
current_row : 0 ,
@@ -758,8 +758,8 @@ impl Flex {
758
758
row. extra_start_gap = row. extra_gap ;
759
759
}
760
760
}
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 ) ;
763
763
}
764
764
}
765
765
rows
@@ -1129,15 +1129,16 @@ impl FlexInstance<'_> {
1129
1129
}
1130
1130
1131
1131
let item = ItemState {
1132
- inner_size : round_vec2 ( inner_size) ,
1132
+ inner_size : inner_size. round_ui ( ) ,
1133
1133
id : ui. id ( ) ,
1134
- inner_min_size : round_vec2 ( Vec2 :: max (
1134
+ inner_min_size : Vec2 :: max (
1135
1135
Vec2 :: new (
1136
1136
item. min_size [ 0 ] . unwrap_or_default ( ) ,
1137
1137
item. min_size [ 1 ] . unwrap_or_default ( ) ,
1138
1138
) - frame. total_margin ( ) . sum ( ) ,
1139
1139
inner_size,
1140
- ) ) ,
1140
+ )
1141
+ . round_ui ( ) ,
1141
1142
config : item. into_state ( ) ,
1142
1143
remeasure_widget : res. remeasure_widget ,
1143
1144
} ;
@@ -1408,7 +1409,8 @@ impl FlexContainerUi {
1408
1409
// If the size changed in the cross direction the widget might have grown in the main direction
1409
1410
// and wrapped, we need to remeasure the widget (draw it once with full available size)
1410
1411
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 ( )
1412
1414
} ) && !self . remeasure_widget ;
1413
1415
1414
1416
if remeasure_widget {
@@ -1424,30 +1426,3 @@ impl FlexContainerUi {
1424
1426
}
1425
1427
}
1426
1428
}
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
- }
0 commit comments