From 1e266b3389aaafb62cfd09bcc0070d2b2d4171cd Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 17 Jun 2022 22:01:07 +0800 Subject: [PATCH] adjust image modal size to match the target size for image centering --- services/gam/src/modal.rs | 2 +- services/gam/src/modal/image.rs | 7 ++++++- services/modals/src/lib.rs | 11 +++-------- services/modals/src/tests.rs | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/services/gam/src/modal.rs b/services/gam/src/modal.rs index 213491334..a9b63ef10 100644 --- a/services/gam/src/modal.rs +++ b/services/gam/src/modal.rs @@ -17,7 +17,7 @@ pub use consoleinput::*; #[cfg(feature="ditherpunk")] mod image; #[cfg(feature="ditherpunk")] -pub use self::image::*; +pub use image::*; use enum_dispatch::enum_dispatch; diff --git a/services/gam/src/modal/image.rs b/services/gam/src/modal/image.rs index fcbd60dda..5d528193f 100644 --- a/services/gam/src/modal/image.rs +++ b/services/gam/src/modal/image.rs @@ -1,5 +1,7 @@ use crate::*; +pub const IMG_MODAL_HEIGHT: u32 = 300; +pub const IMG_MODAL_WIDTH: u32 = 296; #[derive(Debug)] pub struct Image { pub action_conn: xous::CID, @@ -31,7 +33,10 @@ impl ActionApi for Image { }; log::info!("bitmap height {:?} : margin {}", bm_height, margin); - margin * 2 + bm_height + // the modals routine always tries to center the image within a box of a given height. + // make this height consistent with what the target is + //margin * 2 + bm_height + IMG_MODAL_HEIGHT as i16 } fn redraw(&self, _at_height: i16, modal: &Modal) { if self.bitmap.is_some() { diff --git a/services/modals/src/lib.rs b/services/modals/src/lib.rs index cb0edf1bd..ede9e807f 100644 --- a/services/modals/src/lib.rs +++ b/services/modals/src/lib.rs @@ -194,17 +194,12 @@ impl Modals { Ok(()) } - #[cfg(feature = "ditherpunk")] - const MODAL_WIDTH: u32 = 296; - #[allow(dead_code)] - #[cfg(feature = "ditherpunk")] - const MODAL_HEIGHT: u32 = 300; /// this blocks until the image has been dismissed. #[cfg(feature = "ditherpunk")] pub fn show_image(&self, img: &Img) -> Result<(), xous::Error> { self.lock(); // resize and/or rotate - let (modal_width, modal_height) = (Modals::MODAL_WIDTH as f32, Modals::MODAL_HEIGHT as f32); + let (modal_width, modal_height) = (gam::IMG_MODAL_WIDTH as f32, gam::IMG_MODAL_HEIGHT as f32); let (w, h, _) = img.size(); let (img_width, img_height) = (w as f32, h as f32); @@ -227,8 +222,8 @@ impl Modals { // center image in modal let center = Point::new( - ((Modals::MODAL_WIDTH - bm_width) / 2).try_into().unwrap(), - ((Modals::MODAL_HEIGHT - bm_height) / 2).try_into().unwrap(), + ((gam::IMG_MODAL_WIDTH - bm_width) / 2).try_into().unwrap(), + ((gam::IMG_MODAL_HEIGHT - bm_height) / 2).try_into().unwrap(), ); bm.translate(center); diff --git a/services/modals/src/tests.rs b/services/modals/src/tests.rs index 3bb10811e..cb09bb612 100644 --- a/services/modals/src/tests.rs +++ b/services/modals/src/tests.rs @@ -173,7 +173,7 @@ pub fn spawn_test() { // https://sequelaencollection.home.blog/2d-chaotic-attractors/ #[cfg(feature = "ditherpunk")] fn clifford() -> Img { - const SIZE: u32 = Modals::MODAL_WIDTH - 10; + const SIZE: u32 = gam::IMG_MODAL_WIDTH - 10; const CENTER: f32 = (SIZE / 2) as f32; const SCALE: f32 = 60.0; let mut buf = vec![255u8; (SIZE * SIZE).try_into().unwrap()];