Trim switches down to interaction area only
This commit is contained in:
parent
c7ce618b25
commit
c72094bfd3
Binary file not shown.
Before Width: | Height: | Size: 436 B After Width: | Height: | Size: 4.1 KiB |
Binary file not shown.
Before Width: | Height: | Size: 397 B After Width: | Height: | Size: 4.1 KiB |
Binary file not shown.
Before Width: | Height: | Size: 423 B After Width: | Height: | Size: 4.1 KiB |
@ -89,7 +89,7 @@ impl Widget for Frontpanel<'_> {
|
||||
pos.y *= y_scale;
|
||||
pos += fp_rect.left_top().to_vec2();
|
||||
if i == 0 {
|
||||
ui.allocate_ui_at_rect(Rect::from_center_size(pos, vec2(32.0, 32.0)), |ui| {
|
||||
ui.allocate_ui_at_rect(Rect::from_center_size(pos, vec2(11.0, 25.0)), |ui| {
|
||||
let mut power_inv = !state.power;
|
||||
if ui
|
||||
.add(switch::ToggleSwitch::new(&mut power_inv, &sw_textures))
|
||||
@ -108,7 +108,7 @@ impl Widget for Frontpanel<'_> {
|
||||
if (1..17).contains(&i) {
|
||||
let bit_mask = 1 << (16 - i);
|
||||
let mut sw_state = state.ad_sws & bit_mask > 0;
|
||||
ui.allocate_ui_at_rect(Rect::from_center_size(pos, vec2(32.0, 32.0)), |ui| {
|
||||
ui.allocate_ui_at_rect(Rect::from_center_size(pos, vec2(11.0, 25.0)), |ui| {
|
||||
if ui.add(switch::ToggleSwitch::new(&mut sw_state, &sw_textures)).drag_started() {
|
||||
self.audio_tx.send(AudioMessage::PlaySwitchClick).unwrap();
|
||||
};
|
||||
@ -127,7 +127,7 @@ impl Widget for Frontpanel<'_> {
|
||||
24 => &mut state.aux2,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
ui.allocate_ui_at_rect(Rect::from_center_size(pos, vec2(32.0, 32.0)), |ui| {
|
||||
ui.allocate_ui_at_rect(Rect::from_center_size(pos, vec2(11.0, 25.0)), |ui| {
|
||||
if ui.add(switch::ThreePosSwitch::new(state, &sw_textures)).drag_started() {
|
||||
self.audio_tx.send(AudioMessage::PlaySwitchClick).unwrap();
|
||||
};
|
||||
|
@ -64,23 +64,21 @@ impl<'a> ThreePosSwitch<'a> {
|
||||
|
||||
impl Widget for ThreePosSwitch<'_> {
|
||||
fn ui(self, ui: &mut eframe::egui::Ui) -> eframe::egui::Response {
|
||||
let (resp, painter) = ui.allocate_painter((32.0, 32.0).into(), Sense::drag());
|
||||
let (resp, painter) = ui.allocate_painter((11.0, 25.0).into(), Sense::drag());
|
||||
painter.image(
|
||||
self.textures.get_for_state(*self.state),
|
||||
Rect::from_min_size(painter.clip_rect().left_top(), vec2(32.0, 32.0)),
|
||||
Rect::from_min_size(painter.clip_rect().left_top(), vec2(11.0, 25.0)),
|
||||
NULL_UV,
|
||||
NULL_TINT,
|
||||
);
|
||||
if resp.drag_started() {
|
||||
let interact_pos = resp.interact_pointer_pos().unwrap();
|
||||
let sw_center = painter.clip_rect().left_top() + vec2(15.0, 16.0);
|
||||
if Rect::from_center_size(interact_pos, (10.0, 24.0).into()).contains(sw_center) {
|
||||
if interact_pos.y > sw_center.y {
|
||||
*self.state = SwitchState::Down;
|
||||
} else {
|
||||
*self.state = SwitchState::Up;
|
||||
};
|
||||
}
|
||||
let sw_center = painter.clip_rect().left_top() + vec2(5.0, 12.0);
|
||||
if interact_pos.y > sw_center.y {
|
||||
*self.state = SwitchState::Down;
|
||||
} else {
|
||||
*self.state = SwitchState::Up;
|
||||
};
|
||||
} else if resp.drag_released() {
|
||||
*self.state = SwitchState::Neut;
|
||||
}
|
||||
@ -101,19 +99,15 @@ impl<'a> ToggleSwitch<'a> {
|
||||
|
||||
impl Widget for ToggleSwitch<'_> {
|
||||
fn ui(self, ui: &mut eframe::egui::Ui) -> eframe::egui::Response {
|
||||
let (resp, painter) = ui.allocate_painter((32.0, 32.0).into(), Sense::drag());
|
||||
let (resp, painter) = ui.allocate_painter((11.0, 25.0).into(), Sense::drag());
|
||||
painter.image(
|
||||
self.textures.get_for_bool(*self.state),
|
||||
Rect::from_min_size(painter.clip_rect().left_top(), vec2(32.0, 32.0)),
|
||||
Rect::from_min_size(painter.clip_rect().left_top(), vec2(11.0, 25.0)),
|
||||
NULL_UV,
|
||||
NULL_TINT,
|
||||
);
|
||||
if resp.drag_started() {
|
||||
let interact_pos = resp.interact_pointer_pos().unwrap();
|
||||
let sw_center = painter.clip_rect().left_top() + vec2(15.0, 16.0);
|
||||
if Rect::from_center_size(interact_pos, (10.0, 24.0).into()).contains(sw_center) {
|
||||
*self.state = !*self.state;
|
||||
}
|
||||
*self.state = !*self.state;
|
||||
}
|
||||
resp
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user