@ -31,10 +31,10 @@ impl Plugin for GameUiPlugin {
fn build ( & self , app : & mut App ) {
fn build ( & self , app : & mut App ) {
app . add_event ::< Alert > ( )
app . add_event ::< Alert > ( )
. add_systems ( Startup , init_alerts )
. add_systems ( Startup , init_alerts )
. add_systems ( PreUpdate , create_titles )
. add_systems (
. add_systems (
Update ,
Update ,
(
(
create_titles ,
manage_titles ,
manage_titles ,
manage_button_interaction ,
manage_button_interaction ,
manage_select_active ,
manage_select_active ,
@ -55,39 +55,9 @@ pub use title::*;
mod title {
mod title {
use super ::* ;
use super ::* ;
#[ derive(Debug, Component , Default )]
#[ derive(Debug, Component )]
pub struct Title {
pub struct Title {
pub text : String ,
pub text : String ,
pub font : Option < Handle < Font > > ,
}
#[ derive(Debug) ]
pub struct TitleBarBase {
bg_color : Color ,
}
impl TitleBarBase {
pub fn new ( bg_color : Color ) -> Self {
Self { bg_color }
}
pub fn bundle ( & self ) -> NodeBundle {
NodeBundle {
style : Style {
padding : UiRect ::all ( Val ::Px ( 1.0 ) ) ,
margin : UiRect ::all ( Val ::Px ( 1.0 ) ) ,
border : UiRect ::all ( Val ::Px ( 1.0 ) ) ,
flex_direction : FlexDirection ::Row ,
align_items : AlignItems ::Center ,
align_content : AlignContent ::Center ,
justify_content : JustifyContent ::SpaceBetween ,
.. default ( )
} ,
background_color : self . bg_color . into ( ) ,
border_color : Color ::BLACK . into ( ) ,
.. default ( )
}
}
}
}
#[ derive(Debug, Component) ]
#[ derive(Debug, Component) ]
@ -123,24 +93,16 @@ mod title {
) {
) {
events . for_each ( | ( entity , title , note , minimize , close ) | {
events . for_each ( | ( entity , title , note , minimize , close ) | {
commands . entity ( entity ) . with_children ( | parent | {
commands . entity ( entity ) . with_children ( | parent | {
let style = match & title . font {
Some ( handle ) = > TextStyle {
color : Color ::BLACK ,
font : handle . clone ( ) ,
.. default ( )
} ,
None = > TextStyle {
color : Color ::BLACK ,
.. default ( )
} ,
} ;
parent . spawn ( (
parent . spawn ( (
TextBundle {
TextBundle {
text : Text {
text : Text {
sections : vec ! [
sections : vec ! [
TextSection {
TextSection {
value : title . text . clone ( ) ,
value : title . text . clone ( ) ,
style ,
style : TextStyle {
color : Color ::BLACK ,
.. default ( )
} ,
} ,
} ,
TextSection {
TextSection {
value : note
value : note
@ -329,19 +291,19 @@ mod collapse {
collapses : Query < & Collapse , With < Button > > ,
collapses : Query < & Collapse , With < Button > > ,
mut styles : Query < & mut Style > ,
mut styles : Query < & mut Style > ,
) {
) {
// Removed collapse, hide the target entity
// Added collapse, display the target entity
remov ed. iter ( ) . for_each ( | e | {
add ed. iter ( ) . for_each ( | e | {
if let Ok ( Collapse { target } ) = collapses . get ( e ) {
if let Ok ( Collapse { target } ) = collapses . get ( e ) {
if let Ok ( mut style ) = styles . get_mut ( * target ) {
if let Ok ( mut style ) = styles . get_mut ( * target ) {
style . display = Display ::None ;
style . display = Display ::Flex ;
}
}
}
}
} ) ;
} ) ;
// Added collapse, display the target entity
// Removed collapse, hide the target entity
add ed. iter ( ) . for_each ( | e | {
remov ed. iter ( ) . for_each ( | e | {
if let Ok ( Collapse { target } ) = collapses . get ( e ) {
if let Ok ( Collapse { target } ) = collapses . get ( e ) {
if let Ok ( mut style ) = styles . get_mut ( * target ) {
if let Ok ( mut style ) = styles . get_mut ( * target ) {
style . display = Display ::Flex ;
style . display = Display ::None ;
}
}
}
}
} ) ;
} ) ;
@ -390,14 +352,14 @@ mod buttons {
mut removed_active : RemovedComponents < Active > ,
mut removed_active : RemovedComponents < Active > ,
mut bg_colors : Query < & mut BackgroundColor > ,
mut bg_colors : Query < & mut BackgroundColor > ,
) {
) {
removed_active. iter ( ) . for_each ( | e | {
added_active . for_each ( | e | {
if let Ok ( mut bg_color ) = bg_colors . get_mut ( e ) {
if let Ok ( mut bg_color ) = bg_colors . get_mut ( e ) {
* bg_color = Color ::WHIT E. into ( ) ;
* bg_color = Color ::ORANG E. into ( ) ;
}
}
} ) ;
} ) ;
added_active . for_each ( | e | {
removed_active. iter ( ) . for_each ( | e | {
if let Ok ( mut bg_color ) = bg_colors . get_mut ( e ) {
if let Ok ( mut bg_color ) = bg_colors . get_mut ( e ) {
* bg_color = Color ::ORANG E. into ( ) ;
* bg_color = Color ::WHIT E. into ( ) ;
}
}
} ) ;
} ) ;
events . for_each ( | ( entity , interaction , active ) | {
events . for_each ( | ( entity , interaction , active ) | {
@ -608,43 +570,36 @@ pub mod alert {
justify_self : JustifySelf ::Center ,
justify_self : JustifySelf ::Center ,
.. default ( )
.. default ( )
} ,
} ,
background_color : Color ::WHITE . into ( ) ,
border_color : color . into ( ) ,
border_color : color . into ( ) ,
.. default ( )
.. default ( )
} )
} )
. with_children ( | parent | {
. with_children ( | parent | {
parent . spawn ( (
parent . spawn ( (
TitleBarBase ::new ( color ) . bundle ( ) ,
NodeBundle {
style : Style {
padding : UiRect ::all ( Val ::Px ( 1.0 ) ) ,
margin : UiRect ::all ( Val ::Px ( 1.0 ) ) ,
border : UiRect ::all ( Val ::Px ( 1.0 ) ) ,
flex_direction : FlexDirection ::Row ,
align_items : AlignItems ::Center ,
align_content : AlignContent ::Center ,
justify_content : JustifyContent ::SpaceBetween ,
.. default ( )
} ,
background_color : color . into ( ) ,
.. default ( )
} ,
Title {
Title {
text : "Alert" . into ( ) ,
text : "Alert" . into ( ) ,
.. default ( )
} ,
} ,
Close {
Close {
target : parent . parent_entity ( ) ,
target : parent . parent_entity ( ) ,
} ,
} ,
Sorting ( 0 ) ,
Sorting ( 0 ) ,
) ) ;
) ) ;
parent . spawn ( TextBundle ::from_section (
parent . spawn ( TextBundle ::from_section ( text , TextStyle { .. default ( ) } ) ) ;
text ,
TextStyle {
color : Color ::BLACK . into ( ) ,
.. default ( )
} ,
) ) ;
} ) ;
} ) ;
} ) ;
} ) ;
} ) ;
} ) ;
}
}
}
}
use dragndrop ::* ;
pub mod dragndrop {
use super ::* ;
#[ derive(Debug, Component) ]
struct DragNDrop ;
pub fn dragndrop ( ) {
todo! ( )
}
}