openvr: adjustable opacity
This commit is contained in:
@@ -397,7 +397,16 @@ impl<D, S> InteractionHandler for Canvas<D, S> {
|
||||
}
|
||||
}
|
||||
}
|
||||
fn on_scroll(&mut self, _app: &mut AppState, _hit: &PointerHit, _delta: f32) {}
|
||||
fn on_scroll(&mut self, app: &mut AppState, hit: &PointerHit, delta: f32) {
|
||||
let idx = self.hover_controls[hit.pointer];
|
||||
|
||||
if let Some(idx) = idx {
|
||||
let c = &mut self.controls[idx];
|
||||
if let Some(ref mut f) = c.on_scroll {
|
||||
f(c, &mut self.canvas.data, app, delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<D, S> OverlayRenderer for Canvas<D, S> {
|
||||
@@ -511,6 +520,7 @@ pub struct Control<D, S> {
|
||||
pub on_update: Option<fn(&mut Self, &mut D, &mut AppState)>,
|
||||
pub on_press: Option<fn(&mut Self, &mut D, &mut AppState, PointerMode)>,
|
||||
pub on_release: Option<fn(&mut Self, &mut D, &mut AppState)>,
|
||||
pub on_scroll: Option<fn(&mut Self, &mut D, &mut AppState, f32)>,
|
||||
pub test_highlight: Option<fn(&Self, &mut D, &mut AppState) -> Option<Vec4>>,
|
||||
|
||||
on_render_bg: Option<fn(&Self, &CanvasData<D>, &mut AppState, &mut WlxCommandBuffer)>,
|
||||
@@ -540,6 +550,7 @@ impl<D, S> Control<D, S> {
|
||||
test_highlight: None,
|
||||
on_press: None,
|
||||
on_release: None,
|
||||
on_scroll: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ where
|
||||
button.on_press = Some(btn_func_dn);
|
||||
}
|
||||
WatchElement::Batteries {
|
||||
rect,
|
||||
rect: [x, y, w, h],
|
||||
font_size,
|
||||
num_devices,
|
||||
normal_fg_color,
|
||||
@@ -156,11 +156,11 @@ where
|
||||
..
|
||||
} => {
|
||||
let num_buttons = num_devices as f32;
|
||||
let mut button_x = rect[0];
|
||||
let mut button_y = rect[1];
|
||||
let mut button_x = x;
|
||||
let mut button_y = y;
|
||||
let (button_w, button_h) = match layout {
|
||||
ListLayout::Horizontal => (rect[2] / num_buttons, rect[3]),
|
||||
ListLayout::Vertical => (rect[2], rect[3] / num_buttons),
|
||||
ListLayout::Horizontal => (w / num_buttons, h),
|
||||
ListLayout::Vertical => (w, h / num_buttons),
|
||||
};
|
||||
|
||||
canvas.font_size = font_size;
|
||||
@@ -187,34 +187,18 @@ where
|
||||
};
|
||||
}
|
||||
}
|
||||
WatchElement::OverlayList {
|
||||
rect,
|
||||
WatchElement::KeyboardButton {
|
||||
rect: [x, y, w, h],
|
||||
font_size,
|
||||
kbd_fg_color,
|
||||
kbd_bg_color,
|
||||
scr_fg_color,
|
||||
scr_bg_color,
|
||||
layout,
|
||||
fg_color,
|
||||
bg_color,
|
||||
text,
|
||||
} => {
|
||||
let num_buttons = screens.len() + 1;
|
||||
let mut button_x = rect[0];
|
||||
let mut button_y = rect[1];
|
||||
let (button_w, button_h) = match layout {
|
||||
ListLayout::Horizontal => (rect[2] / (num_buttons as f32), rect[3]),
|
||||
ListLayout::Vertical => (rect[2], rect[3] / (num_buttons as f32)),
|
||||
};
|
||||
|
||||
canvas.bg_color = color_parse(&kbd_bg_color).unwrap_or(FALLBACK_COLOR);
|
||||
canvas.fg_color = color_parse(&kbd_fg_color).unwrap_or(FALLBACK_COLOR);
|
||||
canvas.bg_color = color_parse(&bg_color).unwrap_or(FALLBACK_COLOR);
|
||||
canvas.fg_color = color_parse(&fg_color).unwrap_or(FALLBACK_COLOR);
|
||||
canvas.font_size = font_size;
|
||||
|
||||
let keyboard = canvas.button(
|
||||
button_x + 2.,
|
||||
button_y + 2.,
|
||||
button_w - 4.,
|
||||
button_h - 4.,
|
||||
KEYBOARD_NAME.into(),
|
||||
);
|
||||
let keyboard = canvas.button(x, y, w, h, text);
|
||||
keyboard.state = Some(ElemState::OverlayButton {
|
||||
pressed_at: Instant::now(),
|
||||
mode: PointerMode::Left,
|
||||
@@ -222,20 +206,28 @@ where
|
||||
});
|
||||
keyboard.on_press = Some(overlay_button_dn);
|
||||
keyboard.on_release = Some(overlay_button_up);
|
||||
keyboard.on_scroll = Some(overlay_button_scroll);
|
||||
}
|
||||
WatchElement::OverlayList {
|
||||
rect: [x, y, w, h],
|
||||
font_size,
|
||||
fg_color,
|
||||
bg_color,
|
||||
layout,
|
||||
} => {
|
||||
let num_buttons = screens.len() as f32;
|
||||
let mut button_x = x;
|
||||
let mut button_y = y;
|
||||
let (button_w, button_h) = match layout {
|
||||
ListLayout::Horizontal => (w / num_buttons, h),
|
||||
ListLayout::Vertical => (w, h / num_buttons),
|
||||
};
|
||||
|
||||
canvas.bg_color = color_parse(&scr_bg_color).unwrap_or(FALLBACK_COLOR);
|
||||
canvas.fg_color = color_parse(&scr_fg_color).unwrap_or(FALLBACK_COLOR);
|
||||
canvas.bg_color = color_parse(&bg_color).unwrap_or(FALLBACK_COLOR);
|
||||
canvas.fg_color = color_parse(&fg_color).unwrap_or(FALLBACK_COLOR);
|
||||
canvas.font_size = font_size;
|
||||
|
||||
for screen in screens.iter() {
|
||||
button_x += match layout {
|
||||
ListLayout::Horizontal => button_w,
|
||||
ListLayout::Vertical => 0.,
|
||||
};
|
||||
button_y += match layout {
|
||||
ListLayout::Horizontal => 0.,
|
||||
ListLayout::Vertical => button_h,
|
||||
};
|
||||
|
||||
let button = canvas.button(
|
||||
button_x + 2.,
|
||||
button_y + 2.,
|
||||
@@ -251,6 +243,16 @@ where
|
||||
|
||||
button.on_press = Some(overlay_button_dn);
|
||||
button.on_release = Some(overlay_button_up);
|
||||
button.on_scroll = Some(overlay_button_scroll);
|
||||
|
||||
button_x += match layout {
|
||||
ListLayout::Horizontal => button_w,
|
||||
ListLayout::Vertical => 0.,
|
||||
};
|
||||
button_y += match layout {
|
||||
ListLayout::Horizontal => 0.,
|
||||
ListLayout::Vertical => button_h,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -384,7 +386,7 @@ fn battery_update(control: &mut Control<(), ElemState>, _: &mut (), app: &mut Ap
|
||||
let text = match device {
|
||||
Some(d) => d
|
||||
.soc
|
||||
.map(|soc| format!("{}{}", tags[d.role as usize], (soc * 100.) as u32))
|
||||
.map(|soc| format!("{}{}", tags[d.role as usize], (soc * 100.).min(99.) as u32))
|
||||
.unwrap_or_else(|| "".into()),
|
||||
None => "".into(),
|
||||
};
|
||||
@@ -520,6 +522,38 @@ fn clock_update(control: &mut Control<(), ElemState>, _: &mut (), _: &mut AppSta
|
||||
}
|
||||
}
|
||||
|
||||
fn overlay_button_scroll(
|
||||
control: &mut Control<(), ElemState>,
|
||||
_: &mut (),
|
||||
app: &mut AppState,
|
||||
delta: f32,
|
||||
) {
|
||||
let ElemState::OverlayButton { overlay, .. } = control.state.as_mut().unwrap() else {
|
||||
log::error!("OverlayButton state not found");
|
||||
return;
|
||||
};
|
||||
|
||||
if delta > 0. {
|
||||
app.tasks.enqueue(TaskType::Overlay(
|
||||
overlay.clone(),
|
||||
Box::new(|_, o| {
|
||||
o.alpha = (o.alpha + 0.025).min(1.);
|
||||
o.dirty = true;
|
||||
log::debug!("{}: alpha {}", o.name, o.alpha);
|
||||
}),
|
||||
));
|
||||
} else {
|
||||
app.tasks.enqueue(TaskType::Overlay(
|
||||
overlay.clone(),
|
||||
Box::new(|_, o| {
|
||||
o.alpha = (o.alpha - 0.025).max(0.1);
|
||||
o.dirty = true;
|
||||
log::debug!("{}: alpha {}", o.name, o.alpha);
|
||||
}),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
fn overlay_button_dn(
|
||||
control: &mut Control<(), ElemState>,
|
||||
_: &mut (),
|
||||
@@ -666,13 +700,18 @@ enum WatchElement {
|
||||
charging_bg_color: Arc<str>,
|
||||
layout: ListLayout,
|
||||
},
|
||||
KeyboardButton {
|
||||
rect: [f32; 4],
|
||||
font_size: isize,
|
||||
fg_color: Arc<str>,
|
||||
bg_color: Arc<str>,
|
||||
text: Arc<str>,
|
||||
},
|
||||
OverlayList {
|
||||
rect: [f32; 4],
|
||||
font_size: isize,
|
||||
kbd_fg_color: Arc<str>,
|
||||
kbd_bg_color: Arc<str>,
|
||||
scr_fg_color: Arc<str>,
|
||||
scr_bg_color: Arc<str>,
|
||||
fg_color: Arc<str>,
|
||||
bg_color: Arc<str>,
|
||||
layout: ListLayout,
|
||||
},
|
||||
FuncButton {
|
||||
|
||||
@@ -50,14 +50,19 @@ watch_elements:
|
||||
func_middle: ~
|
||||
text: "W"
|
||||
|
||||
- type: KeyboardButton
|
||||
rect: [32, 162, 60, 36]
|
||||
font_size: 14
|
||||
fg_color: "#FFFFFF"
|
||||
bg_color: "#406050"
|
||||
text: "Kbd"
|
||||
|
||||
# bottom row, of keyboard + overlays
|
||||
- type: OverlayList
|
||||
rect: [30, 160, 370, 40]
|
||||
rect: [94, 160, 306, 40]
|
||||
font_size: 14
|
||||
kbd_fg_color: "#FFFFFF"
|
||||
kbd_bg_color: "#406050"
|
||||
scr_fg_color: "#FFFFFF"
|
||||
scr_bg_color: "#405060"
|
||||
fg_color: "#FFFFFF"
|
||||
bg_color: "#405060"
|
||||
layout: Horizontal
|
||||
|
||||
# main clock with date and day-of-week
|
||||
@@ -108,7 +113,7 @@ watch_elements:
|
||||
- type: Batteries
|
||||
rect: [0, 0, 400, 30]
|
||||
font_size: 14
|
||||
num_devices: 6
|
||||
num_devices: 9
|
||||
low_threshold: 15
|
||||
layout: Horizontal
|
||||
normal_fg_color: "#99BBAA"
|
||||
|
||||
Reference in New Issue
Block a user