git clone https://garage44.eu/jeroen/pinnacle.git.. /layout/src/bluetooth.rs
//! The Bluetooth app: this device's line, then the devices found as rows;
//! a device's page with what was read from it as rows, a back button and
//! a button to act on it.
use crate::{Rect, center, column, margin};
pub const ROW: i32 = 96;
pub const GAP: i32 = 8;
/// Where the rows start: under the title and this device's line.
pub const TOP: i32 = 190;
pub const BUTTON: i32 = 64;
/// The column the rows and the card sit in.
pub fn pane(width: i32) -> (i32, i32) {
column(width, 760)
}
/// Row `i` of the devices found.
pub fn device(width: i32, i: usize) -> Rect {
let (x, w) = pane(width);
Rect::new(x, TOP + i as i32 * (ROW + GAP), w, ROW)
}
pub fn device_center(width: i32, i: usize) -> (i32, i32) {
center(device(width, i))
}
/// How many device rows fit above the window's bottom.
pub fn rows(height: i32) -> usize {
((height - TOP - 24).max(0) / (ROW + GAP)) as usize
}
/// On a device's page: the way back, top left.
pub fn back(width: i32) -> Rect {
Rect::new(margin(width), 28, 112, 56)
}
pub fn back_center(width: i32) -> (i32, i32) {
center(back(width))
}
/// The card of what was read from the device, `n` rows of [`VALUE`].
pub const VALUE: i32 = 64;
pub fn values(width: i32, n: usize) -> Rect {
let (x, w) = pane(width);
Rect::new(x, TOP, w, VALUE * n.max(1) as i32)
}
/// The button to act on the device (add as contact), and the one to
/// disconnect, side by side at the bottom.
pub fn action(width: i32, height: i32) -> Rect {
let (x, w) = pane(width);
Rect::new(x, height - BUTTON - 32, (w - GAP) / 2, BUTTON)
}
pub fn action_center(width: i32, height: i32) -> (i32, i32) {
center(action(width, height))
}
pub fn disconnect(width: i32, height: i32) -> Rect {
let (x, w) = pane(width);
Rect::new(x + (w + GAP) / 2, height - BUTTON - 32, (w - GAP) / 2, BUTTON)
}
pub fn disconnect_center(width: i32, height: i32) -> (i32, i32) {
center(disconnect(width, height))
}
/// The button to pair or forget, across the column above the two.
pub fn pair(width: i32, height: i32) -> Rect {
let (x, w) = pane(width);
Rect::new(x, height - 2 * BUTTON - 32 - GAP, w, BUTTON)
}
pub fn pair_center(width: i32, height: i32) -> (i32, i32) {
center(pair(width, height))
}
/// Pairing's question, a card in the middle of the window: who, the
/// number to compare, and No and Yes side by side at its foot.
pub fn ask(width: i32, height: i32) -> Rect {
let (x, w) = pane(width);
let h = 320;
Rect::new(x, ((height - h) / 2).max(TOP - 80), w, h)
}
pub fn ask_no(width: i32, height: i32) -> Rect {
let card = ask(width, height);
Rect::new(
card.x + 24,
card.bottom() - BUTTON - 24,
(card.width - 48 - GAP) / 2,
BUTTON,
)
}
pub fn ask_yes(width: i32, height: i32) -> Rect {
let no = ask_no(width, height);
Rect::new(no.right() + GAP, no.y, no.width, BUTTON)
}
pub fn ask_no_center(width: i32, height: i32) -> (i32, i32) {
center(ask_no(width, height))
}
pub fn ask_yes_center(width: i32, height: i32) -> (i32, i32) {
center(ask_yes(width, height))
}