Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed text position bug on resize #10

Merged
merged 1 commit into from Mar 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/systems/update_view_settings.rs
Expand Up @@ -27,22 +27,26 @@ pub fn update_view_settings (
mut app_state: ResMut<AppState>,
mut args: ResMut<FFTArgs>,
mut clear_color: ResMut<ClearColor>,
mut text_query: Query<&mut Text>,
mut text_query: Query<(&mut Transform, &mut Text)>,
mut differencing_args_query: Query<&mut FFTArgs>,
mut bar_query: Query<&mut Transform, Without<Text>>
mut bar_query: Query<&mut Transform, Without<Text>>,
) {
let mut differencing_args = differencing_args_query.get_single_mut().unwrap();

// Update bar sizes and positions on resize
let w = window.single_mut().width();
if differencing_args.window_width != w {
let h = window.single_mut().height();
let mut text = text_query.get_single_mut().unwrap().0;
text.translation.x = 10.0 - w / 2.0;
text.translation.y = h / 2.0 - 10.0;

let bar_size = w / app_state.fft[0].len() as f32;
for (i, b) in app_state.despawn_handles.chunks(2).enumerate() {
bar_query.get_mut(b[0]).unwrap().translation.x = bar_size * i as f32 + bar_size / 2.0 - w / 2.0;
bar_query.get_mut(b[1]).unwrap().translation.x = bar_size * i as f32 + bar_size / 2.0 - w / 2.0;
}


let outer_bar_size = bar_size / 2.0;
let inner_bar_size = (bar_size - args.border_size as f32) / 2.0;

Expand Down Expand Up @@ -89,10 +93,10 @@ pub fn update_view_settings (
if differencing_args.text_color != args.text_color || differencing_args.track_name != args.track_name || differencing_args.font_size != args.font_size {
for mut text in &mut text_query {
if args.track_name {
text.sections[0].style.color = args.text_color;
text.sections[0].style.font_size = args.font_size as f32;
text.1.sections[0].style.color = args.text_color;
text.1.sections[0].style.font_size = args.font_size as f32;
} else {
text.sections[0].style.color = Color::rgba(0.0, 0.0, 0.0, 0.0);
text.1.sections[0].style.color = Color::rgba(0.0, 0.0, 0.0, 0.0);
}
}

Expand Down