@ -1,4 +1,4 @@
use crate ::{ egui_assert , e math ::* , Align } ;
use crate ::{ emath ::* , Align } ;
use std ::f32 ::INFINITY ;
use std ::f32 ::INFINITY ;
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
@ -66,9 +66,9 @@ impl Region {
}
}
pub fn sanity_check ( & self ) {
pub fn sanity_check ( & self ) {
egui _assert ! ( ! self . min_rect . any_nan ( ) ) ;
d ebu g_assert! ( ! self . min_rect . any_nan ( ) ) ;
egui _assert ! ( ! self . max_rect . any_nan ( ) ) ;
d ebu g_assert! ( ! self . max_rect . any_nan ( ) ) ;
egui _assert ! ( ! self . cursor . any_nan ( ) ) ;
d ebu g_assert! ( ! self . cursor . any_nan ( ) ) ;
}
}
}
}
@ -389,8 +389,8 @@ impl Layout {
/// ## Doing layout
/// ## Doing layout
impl Layout {
impl Layout {
pub fn align_size_within_rect ( & self , size : Vec2 , outer : Rect ) -> Rect {
pub fn align_size_within_rect ( & self , size : Vec2 , outer : Rect ) -> Rect {
egui _assert ! ( size . x > = 0.0 & & size . y > = 0.0 ) ;
d ebu g_assert! ( size . x > = 0.0 & & size . y > = 0.0 ) ;
egui _assert ! ( ! outer . is_negative ( ) ) ;
d ebu g_assert! ( ! outer . is_negative ( ) ) ;
self . align2 ( ) . align_size_within_rect ( size , outer )
self . align2 ( ) . align_size_within_rect ( size , outer )
}
}
@ -416,8 +416,8 @@ impl Layout {
}
}
pub ( crate ) fn region_from_max_rect ( & self , max_rect : Rect ) -> Region {
pub ( crate ) fn region_from_max_rect ( & self , max_rect : Rect ) -> Region {
egui _assert ! ( ! max_rect . any_nan ( ) ) ;
d ebu g_assert! ( ! max_rect . any_nan ( ) ) ;
egui _assert ! ( max_rect . is_finite ( ) ) ;
d ebu g_assert! ( max_rect . is_finite ( ) ) ;
let mut region = Region {
let mut region = Region {
min_rect : Rect ::NOTHING , // temporary
min_rect : Rect ::NOTHING , // temporary
max_rect ,
max_rect ,
@ -450,9 +450,9 @@ impl Layout {
/// Given the cursor in the region, how much space is available
/// Given the cursor in the region, how much space is available
/// for the next widget?
/// for the next widget?
fn available_from_cursor_max_rect ( & self , cursor : Rect , max_rect : Rect ) -> Rect {
fn available_from_cursor_max_rect ( & self , cursor : Rect , max_rect : Rect ) -> Rect {
egui _assert ! ( ! cursor . any_nan ( ) ) ;
d ebu g_assert! ( ! cursor . any_nan ( ) ) ;
egui _assert ! ( ! max_rect . any_nan ( ) ) ;
d ebu g_assert! ( ! max_rect . any_nan ( ) ) ;
egui _assert ! ( max_rect . is_finite ( ) ) ;
d ebu g_assert! ( max_rect . is_finite ( ) ) ;
// NOTE: in normal top-down layout the cursor has moved below the current max_rect,
// NOTE: in normal top-down layout the cursor has moved below the current max_rect,
// but the available shouldn't be negative.
// but the available shouldn't be negative.
@ -506,7 +506,7 @@ impl Layout {
avail . max . y = y ;
avail . max . y = y ;
}
}
egui _assert ! ( ! avail . any_nan ( ) ) ;
d ebu g_assert! ( ! avail . any_nan ( ) ) ;
avail
avail
}
}
@ -517,7 +517,7 @@ impl Layout {
/// Use `justify_and_align` to get the inner `widget_rect`.
/// Use `justify_and_align` to get the inner `widget_rect`.
pub ( crate ) fn next_frame ( & self , region : & Region , child_size : Vec2 , spacing : Vec2 ) -> Rect {
pub ( crate ) fn next_frame ( & self , region : & Region , child_size : Vec2 , spacing : Vec2 ) -> Rect {
region . sanity_check ( ) ;
region . sanity_check ( ) ;
egui _assert ! ( child_size . x > = 0.0 & & child_size . y > = 0.0 ) ;
d ebu g_assert! ( child_size . x > = 0.0 & & child_size . y > = 0.0 ) ;
if self . main_wrap {
if self . main_wrap {
let available_size = self . available_rect_before_wrap ( region ) . size ( ) ;
let available_size = self . available_rect_before_wrap ( region ) . size ( ) ;
@ -597,7 +597,7 @@ impl Layout {
fn next_frame_ignore_wrap ( & self , region : & Region , child_size : Vec2 ) -> Rect {
fn next_frame_ignore_wrap ( & self , region : & Region , child_size : Vec2 ) -> Rect {
region . sanity_check ( ) ;
region . sanity_check ( ) ;
egui _assert ! ( child_size . x > = 0.0 & & child_size . y > = 0.0 ) ;
d ebu g_assert! ( child_size . x > = 0.0 & & child_size . y > = 0.0 ) ;
let available_rect = self . available_rect_before_wrap ( region ) ;
let available_rect = self . available_rect_before_wrap ( region ) ;
@ -630,16 +630,16 @@ impl Layout {
frame_rect = frame_rect . translate ( Vec2 ::Y * ( region . cursor . top ( ) - frame_rect . top ( ) ) ) ;
frame_rect = frame_rect . translate ( Vec2 ::Y * ( region . cursor . top ( ) - frame_rect . top ( ) ) ) ;
}
}
egui _assert ! ( ! frame_rect . any_nan ( ) ) ;
d ebu g_assert! ( ! frame_rect . any_nan ( ) ) ;
egui _assert ! ( ! frame_rect . is_negative ( ) ) ;
d ebu g_assert! ( ! frame_rect . is_negative ( ) ) ;
frame_rect
frame_rect
}
}
/// Apply justify (fill width/height) and/or alignment after calling `next_space`.
/// Apply justify (fill width/height) and/or alignment after calling `next_space`.
pub ( crate ) fn justify_and_align ( & self , frame : Rect , mut child_size : Vec2 ) -> Rect {
pub ( crate ) fn justify_and_align ( & self , frame : Rect , mut child_size : Vec2 ) -> Rect {
egui _assert ! ( child_size . x > = 0.0 & & child_size . y > = 0.0 ) ;
d ebu g_assert! ( child_size . x > = 0.0 & & child_size . y > = 0.0 ) ;
egui _assert ! ( ! frame . is_negative ( ) ) ;
d ebu g_assert! ( ! frame . is_negative ( ) ) ;
if self . horizontal_justify ( ) {
if self . horizontal_justify ( ) {
child_size . x = child_size . x . at_least ( frame . width ( ) ) ; // fill full width
child_size . x = child_size . x . at_least ( frame . width ( ) ) ; // fill full width
@ -657,10 +657,10 @@ impl Layout {
) -> Rect {
) -> Rect {
let frame = self . next_frame_ignore_wrap ( region , size ) ;
let frame = self . next_frame_ignore_wrap ( region , size ) ;
let rect = self . align_size_within_rect ( size , frame ) ;
let rect = self . align_size_within_rect ( size , frame ) ;
egui _assert ! ( ! rect . any_nan ( ) ) ;
d ebu g_assert! ( ! rect . any_nan ( ) ) ;
egui _assert ! ( ! rect . is_negative ( ) ) ;
d ebu g_assert! ( ! rect . is_negative ( ) ) ;
egui _assert ! ( ( rect . width ( ) - size . x ) . abs ( ) < 1.0 | | size . x = = f32 ::INFINITY ) ;
d ebu g_assert! ( ( rect . width ( ) - size . x ) . abs ( ) < 1.0 | | size . x = = f32 ::INFINITY ) ;
egui _assert ! ( ( rect . height ( ) - size . y ) . abs ( ) < 1.0 | | size . y = = f32 ::INFINITY ) ;
d ebu g_assert! ( ( rect . height ( ) - size . y ) . abs ( ) < 1.0 | | size . y = = f32 ::INFINITY ) ;
rect
rect
}
}
@ -703,7 +703,7 @@ impl Layout {
widget_rect : Rect ,
widget_rect : Rect ,
item_spacing : Vec2 ,
item_spacing : Vec2 ,
) {
) {
egui _assert ! ( ! cursor . any_nan ( ) ) ;
d ebu g_assert! ( ! cursor . any_nan ( ) ) ;
if self . main_wrap {
if self . main_wrap {
if cursor . intersects ( frame_rect . shrink ( 1.0 ) ) {
if cursor . intersects ( frame_rect . shrink ( 1.0 ) ) {
// make row/column larger if necessary
// make row/column larger if necessary