Little cleanup with title bars code duplication

main
Elijah Voigt 2 years ago
parent 0129f1e41d
commit e0cd574a51

@ -260,22 +260,7 @@ fn initialize_ui(mut commands: Commands) {
}) })
.id(); .id();
parent.spawn(( parent.spawn((
NodeBundle { ui::TitleBarBase::new(Color::WHITE).bundle(),
style: Style {
border: UiRect::all(Val::Px(1.0)),
margin: UiRect::all(Val::Px(1.0)),
padding: UiRect::all(Val::Px(1.0)),
flex_direction: FlexDirection::Row,
overflow: Overflow::clip(),
align_items: AlignItems::Center,
align_content: AlignContent::Center,
justify_content: JustifyContent::SpaceBetween,
..default()
},
background_color: Color::WHITE.into(),
border_color: Color::BLACK.into(),
..default()
},
ui::Title { ui::Title {
text: "Assets".into(), text: "Assets".into(),
..default() ..default()
@ -1087,20 +1072,7 @@ mod monologues {
}) })
.with_children(|parent| { .with_children(|parent| {
parent.spawn(( parent.spawn((
NodeBundle { ui::TitleBarBase::new(Color::VIOLET).bundle(),
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,
justify_content: JustifyContent::SpaceBetween,
..default()
},
background_color: Color::VIOLET.into(),
border_color: Color::BLACK.into(),
..default()
},
ui::Title { ui::Title {
text: "Monologue".into(), text: "Monologue".into(),
..default() ..default()
@ -1123,7 +1095,7 @@ mod monologues {
)); ));
}); });
}); });
}) });
} }
// TODO: Sync Handle<Monologue> and TextStyle components to automagically generate and sync text // TODO: Sync Handle<Monologue> and TextStyle components to automagically generate and sync text

@ -61,6 +61,35 @@ mod title {
pub font: Option<Handle<Font>>, 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)]
pub struct Note { pub struct Note {
pub text: String, pub text: String,
@ -579,25 +608,13 @@ 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((
NodeBundle { TitleBarBase::new(color).bundle(),
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() ..default()
@ -607,7 +624,13 @@ pub mod alert {
}, },
Sorting(0), Sorting(0),
)); ));
parent.spawn(TextBundle::from_section(text, TextStyle { ..default() })); parent.spawn(TextBundle::from_section(
text,
TextStyle {
color: Color::BLACK.into(),
..default()
},
));
}); });
}); });
}); });

Loading…
Cancel
Save