ui_manager: Calculate max_height in a purer fashion
This commit is contained in:
@ -10,6 +10,7 @@
|
|||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
|
|
||||||
use ::logging;
|
use ::logging;
|
||||||
|
use ::outputs::OutputState;
|
||||||
use ::outputs::c::OutputHandle;
|
use ::outputs::c::OutputHandle;
|
||||||
|
|
||||||
mod c {
|
mod c {
|
||||||
@ -65,12 +66,10 @@ impl Manager {
|
|||||||
/// distance from display, and motor skills of the user.
|
/// distance from display, and motor skills of the user.
|
||||||
// FIXME: Start by making this aware of display's dpi,
|
// FIXME: Start by making this aware of display's dpi,
|
||||||
// then layout number of rows.
|
// then layout number of rows.
|
||||||
fn get_max_target_height(&self) -> u32 {
|
fn get_max_target_height(output: &OutputState) -> u32 {
|
||||||
let layout_rows = 4; // FIXME: use number from layout.
|
let layout_rows = 4; // FIXME: use number from layout.
|
||||||
let (scale, px_size, phys_size) = (&self.output).as_ref()
|
let px_size = output.get_pixel_size();
|
||||||
.and_then(|o| o.get_state())
|
let phys_size = output.get_phys_size();
|
||||||
.map(|os| (os.scale as u32, os.get_pixel_size(), os.get_phys_size()))
|
|
||||||
.unwrap_or((1, None, None));
|
|
||||||
|
|
||||||
let finger_height_px = match (px_size, phys_size) {
|
let finger_height_px = match (px_size, phys_size) {
|
||||||
(Some(px_size), Some(phys_size)) => {
|
(Some(px_size), Some(phys_size)) => {
|
||||||
@ -84,13 +83,13 @@ impl Manager {
|
|||||||
// TODO: Take into account target shape/area, not just height.
|
// TODO: Take into account target shape/area, not just height.
|
||||||
finger_height_mm * px_size.height as f64 / phys_size.height as f64
|
finger_height_mm * px_size.height as f64 / phys_size.height as f64
|
||||||
},
|
},
|
||||||
(_, None) => scale as f64 * 52.5, // match total 420px at scale 2 from original design
|
(_, None) => output.scale as f64 * 52.5, // match total 420px at scale 2 from original design
|
||||||
(None, Some(_)) => {
|
(None, Some(_)) => {
|
||||||
log_print!(
|
log_print!(
|
||||||
logging::Level::Surprise,
|
logging::Level::Surprise,
|
||||||
"Output has physical size data but no pixel info",
|
"Output has physical size data but no pixel info",
|
||||||
);
|
);
|
||||||
scale as f64 * 52.5
|
output.scale as f64 * 52.5
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
(layout_rows as f64 * finger_height_px) as u32
|
(layout_rows as f64 * finger_height_px) as u32
|
||||||
@ -99,9 +98,13 @@ impl Manager {
|
|||||||
fn get_perceptual_height(&self) -> Option<u32> {
|
fn get_perceptual_height(&self) -> Option<u32> {
|
||||||
let output_info = (&self.output).as_ref()
|
let output_info = (&self.output).as_ref()
|
||||||
.and_then(|o| o.get_state())
|
.and_then(|o| o.get_state())
|
||||||
.map(|os| (os.scale as u32, os.get_pixel_size()));
|
.map(|os| (
|
||||||
|
os.scale as u32,
|
||||||
|
os.get_pixel_size(),
|
||||||
|
Manager::get_max_target_height(&os),
|
||||||
|
));
|
||||||
match output_info {
|
match output_info {
|
||||||
Some((scale, Some(px_size))) => Some({
|
Some((scale, Some(px_size), target_height)) => Some({
|
||||||
let height = if (px_size.width < 720) & (px_size.width > 0) {
|
let height = if (px_size.width < 720) & (px_size.width > 0) {
|
||||||
px_size.width * 7 / 12 // to match 360×210
|
px_size.width * 7 / 12 // to match 360×210
|
||||||
} else if px_size.width < 1080 {
|
} else if px_size.width < 1080 {
|
||||||
@ -113,10 +116,10 @@ impl Manager {
|
|||||||
// Don't exceed half the display size.
|
// Don't exceed half the display size.
|
||||||
let height = min(height, px_size.height / 2);
|
let height = min(height, px_size.height / 2);
|
||||||
// Don't waste screen space by exceeding best target height.
|
// Don't waste screen space by exceeding best target height.
|
||||||
let height = min(height, self.get_max_target_height());
|
let height = min(height, target_height);
|
||||||
height / scale
|
height / scale
|
||||||
}),
|
}),
|
||||||
Some((scale, None)) => Some(360 / scale),
|
Some((scale, None, _)) => Some(360 / scale),
|
||||||
None => None,
|
None => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user