mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
adjust image modal size to match the target size for image centering
This commit is contained in:
parent
d829839c28
commit
1e266b3389
4 changed files with 11 additions and 11 deletions
|
|
@ -17,7 +17,7 @@ pub use consoleinput::*;
|
||||||
#[cfg(feature="ditherpunk")]
|
#[cfg(feature="ditherpunk")]
|
||||||
mod image;
|
mod image;
|
||||||
#[cfg(feature="ditherpunk")]
|
#[cfg(feature="ditherpunk")]
|
||||||
pub use self::image::*;
|
pub use image::*;
|
||||||
|
|
||||||
use enum_dispatch::enum_dispatch;
|
use enum_dispatch::enum_dispatch;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
|
pub const IMG_MODAL_HEIGHT: u32 = 300;
|
||||||
|
pub const IMG_MODAL_WIDTH: u32 = 296;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Image {
|
pub struct Image {
|
||||||
pub action_conn: xous::CID,
|
pub action_conn: xous::CID,
|
||||||
|
|
@ -31,7 +33,10 @@ impl ActionApi for Image {
|
||||||
};
|
};
|
||||||
|
|
||||||
log::info!("bitmap height {:?} : margin {}", bm_height, margin);
|
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) {
|
fn redraw(&self, _at_height: i16, modal: &Modal) {
|
||||||
if self.bitmap.is_some() {
|
if self.bitmap.is_some() {
|
||||||
|
|
|
||||||
|
|
@ -194,17 +194,12 @@ impl Modals {
|
||||||
Ok(())
|
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.
|
/// this blocks until the image has been dismissed.
|
||||||
#[cfg(feature = "ditherpunk")]
|
#[cfg(feature = "ditherpunk")]
|
||||||
pub fn show_image(&self, img: &Img) -> Result<(), xous::Error> {
|
pub fn show_image(&self, img: &Img) -> Result<(), xous::Error> {
|
||||||
self.lock();
|
self.lock();
|
||||||
// resize and/or rotate
|
// 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 (w, h, _) = img.size();
|
||||||
let (img_width, img_height) = (w as f32, h as f32);
|
let (img_width, img_height) = (w as f32, h as f32);
|
||||||
|
|
||||||
|
|
@ -227,8 +222,8 @@ impl Modals {
|
||||||
|
|
||||||
// center image in modal
|
// center image in modal
|
||||||
let center = Point::new(
|
let center = Point::new(
|
||||||
((Modals::MODAL_WIDTH - bm_width) / 2).try_into().unwrap(),
|
((gam::IMG_MODAL_WIDTH - bm_width) / 2).try_into().unwrap(),
|
||||||
((Modals::MODAL_HEIGHT - bm_height) / 2).try_into().unwrap(),
|
((gam::IMG_MODAL_HEIGHT - bm_height) / 2).try_into().unwrap(),
|
||||||
);
|
);
|
||||||
bm.translate(center);
|
bm.translate(center);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,7 @@ pub fn spawn_test() {
|
||||||
// https://sequelaencollection.home.blog/2d-chaotic-attractors/
|
// https://sequelaencollection.home.blog/2d-chaotic-attractors/
|
||||||
#[cfg(feature = "ditherpunk")]
|
#[cfg(feature = "ditherpunk")]
|
||||||
fn clifford() -> Img {
|
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 CENTER: f32 = (SIZE / 2) as f32;
|
||||||
const SCALE: f32 = 60.0;
|
const SCALE: f32 = 60.0;
|
||||||
let mut buf = vec![255u8; (SIZE * SIZE).try_into().unwrap()];
|
let mut buf = vec![255u8; (SIZE * SIZE).try_into().unwrap()];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue