@ -3,29 +3,27 @@ use crate::ui::{
geometry ::{ Grid , Rect } ,
} ;
pub enum DialogMsg < T , L , R > {
use super ::{ theme , Button } ;
pub enum DialogMsg < T , U > {
Content ( T ) ,
Left ( L ) ,
Right ( R ) ,
Controls ( U ) ,
}
pub struct Dialog < T , L, R > {
pub struct Dialog < T , U > {
content : Child < T > ,
left : Child < L > ,
right : Child < R > ,
controls : Child < U > ,
}
impl < T , L, R > Dialog < T , L , R >
impl < T , U> Dialog < T , U >
where
T : Component ,
L : Component ,
R : Component ,
U : Component ,
{
pub fn new ( content : T , left: L , right : R ) -> Self {
pub fn new ( content : T , controls: U ) -> Self {
Self {
content : Child ::new ( content ) ,
left : Child ::new ( left ) ,
right : Child ::new ( right ) ,
controls : Child ::new ( controls ) ,
}
}
@ -34,19 +32,17 @@ where
}
}
impl < T , L, R > Component for Dialog < T , L, R >
impl < T , U > Component for Dialog < T , U >
where
T : Component ,
L : Component ,
R : Component ,
U : Component ,
{
type Msg = DialogMsg < T ::Msg , L::Msg , R ::Msg > ;
type Msg = DialogMsg < T ::Msg , U ::Msg > ;
fn place ( & mut self , bounds : Rect ) -> Rect {
let layout = DialogLayout ::middle ( bounds ) ;
self . content . place ( layout . content ) ;
self . left . place ( layout . left ) ;
self . right . place ( layout . right ) ;
self . controls . place ( layout . controls ) ;
bounds
}
@ -54,55 +50,48 @@ where
self . content
. event ( ctx , event )
. map ( Self ::Msg ::Content )
. or_else ( | | self . left . event ( ctx , event ) . map ( Self ::Msg ::Left ) )
. or_else ( | | self . right . event ( ctx , event ) . map ( Self ::Msg ::Right ) )
. or_else ( | | self . controls . event ( ctx , event ) . map ( Self ::Msg ::Controls ) )
}
fn paint ( & mut self ) {
self . content . paint ( ) ;
self . left . paint ( ) ;
self . right . paint ( ) ;
self . controls . paint ( ) ;
}
fn bounds ( & self , sink : & mut dyn FnMut ( Rect ) ) {
self . content . bounds ( sink ) ;
self . left . bounds ( sink ) ;
self . right . bounds ( sink ) ;
self . controls . bounds ( sink ) ;
}
}
pub struct DialogLayout {
pub content : Rect ,
pub left : Rect ,
pub right : Rect ,
pub controls : Rect ,
}
impl DialogLayout {
pub fn middle ( area : Rect ) -> Self {
let grid = Grid ::new ( area , 5 , 2 ) ;
let grid = Grid ::new ( area , 5 , 1 ) ;
Self {
content : Rect ::new (
grid . row_col ( 0 , 0 ) . top_left ( ) ,
grid . row_col ( 3 , 1 ) . bottom_right ( ) ,
grid . row_col ( 3 , 0 ) . bottom_right ( ) ,
) ,
left : grid . row_col ( 4 , 0 ) ,
right : grid . row_col ( 4 , 1 ) ,
controls : grid . row_col ( 4 , 0 ) ,
}
}
}
#[ cfg(feature = " ui_debug " ) ]
impl < T , L, R > crate ::trace ::Trace for Dialog < T , L, R >
impl < T , U > crate ::trace ::Trace for Dialog < T , U >
where
T : crate ::trace ::Trace ,
L : crate ::trace ::Trace ,
R : crate ::trace ::Trace ,
U : crate ::trace ::Trace ,
{
fn trace ( & self , t : & mut dyn crate ::trace ::Tracer ) {
t . open ( "Dialog" ) ;
t . field ( "content" , & self . content ) ;
t . field ( "left" , & self . left ) ;
t . field ( "right" , & self . right ) ;
t . field ( "controls" , & self . controls ) ;
t . close ( ) ;
}
}