From 47f2c2d4ef8c4c5e07a6ce210ba2af701eabca32 Mon Sep 17 00:00:00 2001 From: pjht Date: Sat, 27 Jan 2024 17:46:19 -0600 Subject: [PATCH] Merge X and Y scale factors into a vector --- src/frontpanel.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/frontpanel.rs b/src/frontpanel.rs index 5d5de3b..41e9d31 100644 --- a/src/frontpanel.rs +++ b/src/frontpanel.rs @@ -67,13 +67,9 @@ impl Widget for Frontpanel<'_> { dbg!(fp_rect); let painter = Painter::new(ui.ctx().clone(), ui.layer_id(), ui.clip_rect().intersect(resp.rect)); painter.image(self.textures.fp.id(), painter.clip_rect(), NULL_UV, NULL_TINT); - let x_scale = painter.clip_rect().width() / 800.0; - let y_scale = painter.clip_rect().height() / 333.0; + let scale_vec = painter.clip_rect().size() / vec2(800.0, 333.0); for led in &LEDS { - let mut pos = led.pos; - pos.x *= x_scale; - pos.y *= y_scale; - pos += fp_rect.left_top().to_vec2(); + let pos = (led.pos.to_vec2() * scale_vec).to_pos2() + fp_rect.left_top().to_vec2(); let led_data = 0xAAAA; let led_on = (led_data & led.mask) > 0; ui.allocate_ui_at_rect(Rect::from_center_size(pos, vec2(16.0, 16.0)), |ui| { @@ -84,10 +80,7 @@ impl Widget for Frontpanel<'_> { // 1..17: A/D left to right // 17..25: Action left to right for (i, switch) in SWITCHES.iter().enumerate() { - let mut pos = switch.pos; - pos.x *= x_scale; - pos.y *= y_scale; - pos += fp_rect.left_top().to_vec2(); + let pos = (switch.pos.to_vec2() * scale_vec).to_pos2() + fp_rect.left_top().to_vec2(); if i == 0 { ui.allocate_ui_at_rect(Rect::from_center_size(pos, vec2(11.0, 25.0)), |ui| { let mut power_inv = !state.power;