Merge X and Y scale factors into a vector

This commit is contained in:
pjht 2024-01-27 17:46:19 -06:00
parent c72094bfd3
commit 47f2c2d4ef
Signed by: pjht
GPG Key ID: CA239FC6934E6F3A

View File

@ -67,13 +67,9 @@ impl Widget for Frontpanel<'_> {
dbg!(fp_rect); dbg!(fp_rect);
let painter = Painter::new(ui.ctx().clone(), ui.layer_id(), ui.clip_rect().intersect(resp.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); painter.image(self.textures.fp.id(), painter.clip_rect(), NULL_UV, NULL_TINT);
let x_scale = painter.clip_rect().width() / 800.0; let scale_vec = painter.clip_rect().size() / vec2(800.0, 333.0);
let y_scale = painter.clip_rect().height() / 333.0;
for led in &LEDS { for led in &LEDS {
let mut pos = led.pos; let pos = (led.pos.to_vec2() * scale_vec).to_pos2() + fp_rect.left_top().to_vec2();
pos.x *= x_scale;
pos.y *= y_scale;
pos += fp_rect.left_top().to_vec2();
let led_data = 0xAAAA; let led_data = 0xAAAA;
let led_on = (led_data & led.mask) > 0; let led_on = (led_data & led.mask) > 0;
ui.allocate_ui_at_rect(Rect::from_center_size(pos, vec2(16.0, 16.0)), |ui| { 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 // 1..17: A/D left to right
// 17..25: Action left to right // 17..25: Action left to right
for (i, switch) in SWITCHES.iter().enumerate() { for (i, switch) in SWITCHES.iter().enumerate() {
let mut pos = switch.pos; let pos = (switch.pos.to_vec2() * scale_vec).to_pos2() + fp_rect.left_top().to_vec2();
pos.x *= x_scale;
pos.y *= y_scale;
pos += fp_rect.left_top().to_vec2();
if i == 0 { if i == 0 {
ui.allocate_ui_at_rect(Rect::from_center_size(pos, vec2(11.0, 25.0)), |ui| { ui.allocate_ui_at_rect(Rect::from_center_size(pos, vec2(11.0, 25.0)), |ui| {
let mut power_inv = !state.power; let mut power_inv = !state.power;