use super::state::*;
use bevy::prelude::*;
const SLIDER_TRACK_COLOR: Color = Color::srgba(0.3, 0.3, 0.3, 0.7);
const SLIDER_HANDLE_COLOR: Color = Color::srgba(0.9, 0.4, 0.2, 0.9);
pub fn spawn_strength_slider(commands: &mut Commands, throw_state: &ThrowControlState) {
commands
.spawn((
NodeBundle {
style: Style {
position_type: PositionType::Absolute,
left: Val::Px(60.0), bottom: Val::Px(60.0),
width: Val::Px(30.0),
height: Val::Px(200.0),
flex_direction: FlexDirection::Column,
align_items: AlignItems::Center,
..default()
},
..default()
},
StrengthSliderContainer,
crate::dice3d::types::DiceRollerRoot, ))
.with_children(|parent| {
parent.spawn(TextBundle::from_section(
"S",
TextStyle {
font_size: 18.0,
color: Color::srgba(0.9, 0.6, 0.3, 0.9),
..default()
},
));
parent
.spawn((
NodeBundle {
style: Style {
width: Val::Px(8.0),
height: Val::Px(160.0),
margin: UiRect::vertical(Val::Px(5.0)),
..default()
},
background_color: SLIDER_TRACK_COLOR.into(),
..default()
},
StrengthSliderTrack,
))
.with_children(|track| {
let normalized = (throw_state.max_strength - 1.0) / 9.0;
let handle_pos = (1.0 - normalized) * 100.0;
track.spawn((
NodeBundle {
style: Style {
position_type: PositionType::Absolute,
width: Val::Px(20.0),
height: Val::Px(20.0),
left: Val::Px(-6.0),
top: Val::Percent(handle_pos),
..default()
},
background_color: SLIDER_HANDLE_COLOR.into(),
..default()
},
StrengthSliderHandle,
));
});
parent.spawn(TextBundle::from_section(
"s",
TextStyle {
font_size: 14.0,
color: Color::srgba(0.7, 0.5, 0.3, 0.7),
..default()
},
));
});
}