Fix front panel not allocating size correctly
This commit is contained in:
parent
a3b0bdbf7b
commit
9e0073df41
@ -1,7 +1,7 @@
|
|||||||
use std::{path::Path, sync::mpsc::Sender};
|
use std::{path::Path, sync::mpsc::Sender};
|
||||||
|
|
||||||
use eframe::{
|
use eframe::{
|
||||||
egui::{self, Id, Painter, Sense, TextureOptions, Ui, Widget},
|
egui::{self, Id, Painter, Response, Sense, TextureOptions, Ui, Widget},
|
||||||
epaint::{pos2, vec2, Color32, Pos2, Rect, TextureHandle},
|
epaint::{pos2, vec2, Color32, Pos2, Rect, TextureHandle},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -55,24 +55,19 @@ impl Widget for Frontpanel<'_> {
|
|||||||
);
|
);
|
||||||
let led_textures =
|
let led_textures =
|
||||||
led::Textures::new(self.textures.led_on.clone(), self.textures.led_off.clone());
|
led::Textures::new(self.textures.led_on.clone(), self.textures.led_off.clone());
|
||||||
let (resp, painter) = ui.allocate_painter(
|
let resp = ui.allocate_response(
|
||||||
(800.0, 333.0).into(),
|
vec2(800.0, 333.0),
|
||||||
Sense {
|
Sense {
|
||||||
click: false,
|
click: false,
|
||||||
drag: false,
|
drag: false,
|
||||||
focusable: false,
|
focusable: false,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
let fp_rect = painter.clip_rect();
|
let fp_rect = resp.rect;
|
||||||
painter.image(
|
ui.allocate_ui_at_rect(fp_rect, |ui| {
|
||||||
self.textures.fp.id(),
|
ui.image(&self.textures.fp);
|
||||||
painter.clip_rect(),
|
|
||||||
NULL_UV,
|
|
||||||
NULL_TINT,
|
|
||||||
);
|
|
||||||
let scale_vec = painter.clip_rect().size() / vec2(800.0, 333.0);
|
|
||||||
for led in &LEDS {
|
for led in &LEDS {
|
||||||
let pos = (led.pos.to_vec2() * scale_vec).to_pos2() + fp_rect.left_top().to_vec2();
|
let pos = led.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| {
|
||||||
@ -83,7 +78,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 pos = (switch.pos.to_vec2() * scale_vec).to_pos2() + fp_rect.left_top().to_vec2();
|
let pos = switch.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;
|
||||||
@ -136,6 +131,7 @@ impl Widget for Frontpanel<'_> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
ui.data_mut(|data| data.insert_temp(self.id, state));
|
ui.data_mut(|data| data.insert_temp(self.id, state));
|
||||||
resp
|
resp
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ impl<'a> ThreePosSwitch<'a> {
|
|||||||
|
|
||||||
impl Widget for ThreePosSwitch<'_> {
|
impl Widget for ThreePosSwitch<'_> {
|
||||||
fn ui(self, ui: &mut eframe::egui::Ui) -> eframe::egui::Response {
|
fn ui(self, ui: &mut eframe::egui::Ui) -> eframe::egui::Response {
|
||||||
let (resp, painter) = ui.allocate_painter((11.0, 25.0).into(), Sense::drag());
|
let (mut resp, painter) = ui.allocate_painter((11.0, 25.0).into(), Sense::drag());
|
||||||
painter.image(
|
painter.image(
|
||||||
self.textures.get_for_state(*self.state),
|
self.textures.get_for_state(*self.state),
|
||||||
Rect::from_min_size(painter.clip_rect().left_top(), vec2(11.0, 25.0)),
|
Rect::from_min_size(painter.clip_rect().left_top(), vec2(11.0, 25.0)),
|
||||||
@ -79,8 +79,10 @@ impl Widget for ThreePosSwitch<'_> {
|
|||||||
} else {
|
} else {
|
||||||
*self.state = SwitchState::Up;
|
*self.state = SwitchState::Up;
|
||||||
};
|
};
|
||||||
|
resp.mark_changed();
|
||||||
} else if resp.drag_released() {
|
} else if resp.drag_released() {
|
||||||
*self.state = SwitchState::Neut;
|
*self.state = SwitchState::Neut;
|
||||||
|
resp.mark_changed();
|
||||||
}
|
}
|
||||||
resp
|
resp
|
||||||
}
|
}
|
||||||
@ -99,7 +101,7 @@ impl<'a> ToggleSwitch<'a> {
|
|||||||
|
|
||||||
impl Widget for ToggleSwitch<'_> {
|
impl Widget for ToggleSwitch<'_> {
|
||||||
fn ui(self, ui: &mut eframe::egui::Ui) -> eframe::egui::Response {
|
fn ui(self, ui: &mut eframe::egui::Ui) -> eframe::egui::Response {
|
||||||
let (resp, painter) = ui.allocate_painter((11.0, 25.0).into(), Sense::drag());
|
let (mut resp, painter) = ui.allocate_painter((11.0, 25.0).into(), Sense::drag());
|
||||||
painter.image(
|
painter.image(
|
||||||
self.textures.get_for_bool(*self.state),
|
self.textures.get_for_bool(*self.state),
|
||||||
Rect::from_min_size(painter.clip_rect().left_top(), vec2(11.0, 25.0)),
|
Rect::from_min_size(painter.clip_rect().left_top(), vec2(11.0, 25.0)),
|
||||||
@ -108,6 +110,7 @@ impl Widget for ToggleSwitch<'_> {
|
|||||||
);
|
);
|
||||||
if resp.drag_started() {
|
if resp.drag_started() {
|
||||||
*self.state = !*self.state;
|
*self.state = !*self.state;
|
||||||
|
resp.mark_changed();
|
||||||
}
|
}
|
||||||
resp
|
resp
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,7 @@ impl eframe::App for AltairEmulator {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
ui.add(Label::new("Hello"));
|
ui.style_mut().debug.debug_on_hover = true;
|
||||||
ui.add(Frontpanel::new(
|
ui.add(Frontpanel::new(
|
||||||
Id::new("frontpanel"),
|
Id::new("frontpanel"),
|
||||||
&self.textures,
|
&self.textures,
|
||||||
@ -589,6 +589,8 @@ impl eframe::App for AltairEmulator {
|
|||||||
// self.cpu.finish_m_cycle(data);
|
// self.cpu.finish_m_cycle(data);
|
||||||
// self.update_fp();
|
// self.update_fp();
|
||||||
// }
|
// }
|
||||||
|
//
|
||||||
|
ui.add(Label::new("Hello"));
|
||||||
});
|
});
|
||||||
|
|
||||||
// let old_fan_enabled = self.options.fan_enabled;
|
// let old_fan_enabled = self.options.fan_enabled;
|
||||||
|
Loading…
Reference in New Issue
Block a user