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();
parent.spawn((
NodeBundle {
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::TitleBarBase::new(Color::WHITE).bundle(),
ui::Title {
text: "Assets".into(),
..default()
@ -1087,20 +1072,7 @@ mod monologues {
})
.with_children(|parent| {
parent.spawn((
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,
justify_content: JustifyContent::SpaceBetween,
..default()
},
background_color: Color::VIOLET.into(),
border_color: Color::BLACK.into(),
..default()
},
ui::TitleBarBase::new(Color::VIOLET).bundle(),
ui::Title {
text: "Monologue".into(),
..default()
@ -1123,7 +1095,7 @@ mod monologues {
));
});
});
})
});
}
// TODO: Sync Handle<Monologue> and TextStyle components to automagically generate and sync text

@ -61,6 +61,35 @@ mod title {
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)]
pub struct Note {
pub text: String,
@ -579,25 +608,13 @@ pub mod alert {
justify_self: JustifySelf::Center,
..default()
},
background_color: Color::WHITE.into(),
border_color: color.into(),
..default()
})
.with_children(|parent| {
parent.spawn((
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()
},
TitleBarBase::new(color).bundle(),
Title {
text: "Alert".into(),
..default()
@ -607,7 +624,13 @@ pub mod alert {
},
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