mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
commit some API changes before making even more API changes
yo dawg i herd u liek API changes so I made API changes to ur API changes
This commit is contained in:
parent
0db9ad9e6f
commit
7e141aba91
1 changed files with 62 additions and 28 deletions
|
|
@ -24,6 +24,14 @@ use xous_ipc::{Buffer, String};
|
||||||
use api::Opcode;
|
use api::Opcode;
|
||||||
use xous::{msg_scalar_unpack, msg_blocking_scalar_unpack};
|
use xous::{msg_scalar_unpack, msg_blocking_scalar_unpack};
|
||||||
|
|
||||||
|
pub trait LayoutApi {
|
||||||
|
type Layout;
|
||||||
|
|
||||||
|
fn init(xns: &xous_names::XousNames, trng: &trng::Trng, canvases: &mut FnvIndexMap<Gid, Canvas, 32>) -> Result<Self::Layout, xous::Error>;
|
||||||
|
fn clear(&self, canvases: &mut FnvIndexMap<Gid, Canvas, 32>) -> Result<(), xous::Error>;
|
||||||
|
fn resize(&mut self, new_height: i16, canvases: &mut FnvIndexMap<Gid, Canvas, 32>) -> Result<Point, xous::Error>;
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
// GIDs of canvases that are used the "Chat" layout.
|
// GIDs of canvases that are used the "Chat" layout.
|
||||||
struct ChatLayout {
|
struct ChatLayout {
|
||||||
|
|
@ -38,8 +46,9 @@ struct ChatLayout {
|
||||||
min_input_height: i16,
|
min_input_height: i16,
|
||||||
gfx: graphics_server::Gfx,
|
gfx: graphics_server::Gfx,
|
||||||
}
|
}
|
||||||
impl ChatLayout {
|
impl LayoutApi for ChatLayout {
|
||||||
pub fn init(xns: &xous_names::XousNames, trng: &trng::Trng, canvases: &mut FnvIndexMap<Gid, Canvas, 32>) -> Result<ChatLayout, xous::Error> {
|
type Layout = ChatLayout;
|
||||||
|
fn init(xns: &xous_names::XousNames, trng: &trng::Trng, canvases: &mut FnvIndexMap<Gid, Canvas, 32>) -> Result<ChatLayout, xous::Error> {
|
||||||
let gfx = graphics_server::Gfx::new(&xns).unwrap();
|
let gfx = graphics_server::Gfx::new(&xns).unwrap();
|
||||||
let screensize = gfx.screen_size().expect("Couldn't get screen size");
|
let screensize = gfx.screen_size().expect("Couldn't get screen size");
|
||||||
// get the height of various text regions to compute the layout
|
// get the height of various text regions to compute the layout
|
||||||
|
|
@ -84,7 +93,7 @@ impl ChatLayout {
|
||||||
gfx,
|
gfx,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pub fn clear(&self, canvases: &mut FnvIndexMap<Gid, Canvas, 32>) -> Result<(), xous::Error> {
|
fn clear(&self, canvases: &mut FnvIndexMap<Gid, Canvas, 32>) -> Result<(), xous::Error> {
|
||||||
let input_canvas = canvases.get(&self.input).expect("couldn't find input canvas");
|
let input_canvas = canvases.get(&self.input).expect("couldn't find input canvas");
|
||||||
let content_canvas = canvases.get(&self.content).expect("couldn't find content canvas");
|
let content_canvas = canvases.get(&self.content).expect("couldn't find content canvas");
|
||||||
let predictive_canvas = canvases.get(&self.predictive).expect("couldn't find predictive canvas");
|
let predictive_canvas = canvases.get(&self.predictive).expect("couldn't find predictive canvas");
|
||||||
|
|
@ -107,7 +116,7 @@ impl ChatLayout {
|
||||||
self.gfx.draw_rectangle(rect).expect("can't clear canvas");
|
self.gfx.draw_rectangle(rect).expect("can't clear canvas");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn resize_input(&mut self, new_height: i16, canvases: &mut FnvIndexMap<Gid, Canvas, 32>) -> Result<Point, xous::Error> {
|
fn resize(&mut self, new_height: i16, canvases: &mut FnvIndexMap<Gid, Canvas, 32>) -> Result<Point, xous::Error> {
|
||||||
let input_canvas = canvases.get(&self.input).expect("couldn't find input canvas");
|
let input_canvas = canvases.get(&self.input).expect("couldn't find input canvas");
|
||||||
let predictive_canvas = canvases.get(&self.predictive).expect("couldn't find predictive canvas");
|
let predictive_canvas = canvases.get(&self.predictive).expect("couldn't find predictive canvas");
|
||||||
let status_canvas = canvases.get(&self.status).expect("couldn't find status canvas");
|
let status_canvas = canvases.get(&self.status).expect("couldn't find status canvas");
|
||||||
|
|
@ -141,40 +150,65 @@ impl ChatLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// remember GIDs of the canvases for modal pop-up boxes
|
// remember GIDs of the canvases for menus
|
||||||
struct ModalCanvases {
|
struct MenuLayout {
|
||||||
pub password: Gid,
|
|
||||||
pub menu: Gid,
|
pub menu: Gid,
|
||||||
pub alert: Gid,
|
gfx: graphics_server::Gfx,
|
||||||
|
menu_y_pad: i16,
|
||||||
|
menu_x_pad: i16,
|
||||||
|
menu_min_height: i16,
|
||||||
}
|
}
|
||||||
impl ModalCanvases {
|
impl LayoutApi for MenuLayout {
|
||||||
fn init(trng: &trng::Trng, canvases: &mut FnvIndexMap<Gid, Canvas, 32>) -> Result<ModalCanvases, xous::Error> {
|
type Layout = MenuLayout;
|
||||||
let password_canvas = Canvas::new(
|
fn init(xns: &xous_names::XousNames, trng: &trng::Trng, canvases: &mut FnvIndexMap<Gid, Canvas, 32>) -> Result<MenuLayout, xous::Error> {
|
||||||
Rectangle::new_coords(-1, -1, -1, -1),
|
let gfx = graphics_server::Gfx::new(&xns).unwrap();
|
||||||
255, &trng, None
|
let screensize = gfx.screen_size().expect("Couldn't get screen size");
|
||||||
).expect("couldn't create password canvas");
|
// get the height of various text regions to compute the layout
|
||||||
canvases.insert(password_canvas.gid(), password_canvas).expect("can't store password canvas");
|
let small_height: i16 = gfx.glyph_height_hint(GlyphStyle::Small).expect("couldn't get glyph height") as i16;
|
||||||
|
|
||||||
|
const MENU_Y_PAD: i16 = 100;
|
||||||
|
const MENU_X_PAD: i16 = 35;
|
||||||
|
// build for an initial size of 1 entry
|
||||||
let menu_canvas = Canvas::new(
|
let menu_canvas = Canvas::new(
|
||||||
Rectangle::new_coords(-1, -1, -1, -1),
|
Rectangle::new_coords(MENU_X_PAD, MENU_Y_PAD, screensize.x - MENU_X_PAD, MENU_Y_PAD + small_height),
|
||||||
255, &trng, None
|
255, &trng, None
|
||||||
).expect("couldn't create menu canvas");
|
).expect("couldn't create menu canvas");
|
||||||
canvases.insert(menu_canvas.gid(), menu_canvas).expect("can't store menu canvas");
|
canvases.insert(menu_canvas.gid(), menu_canvas).expect("can't store menu canvas");
|
||||||
|
|
||||||
let alert_canvas = Canvas::new(
|
Ok(MenuLayout {
|
||||||
Rectangle::new_coords(-1, -1, -1, -1),
|
|
||||||
255, &trng, None
|
|
||||||
).expect("couldn't create alert canvas");
|
|
||||||
canvases.insert(alert_canvas.gid(), alert_canvas).expect("can't store alert canvas");
|
|
||||||
|
|
||||||
Ok(ModalCanvases {
|
|
||||||
password: password_canvas.gid(),
|
|
||||||
menu: menu_canvas.gid(),
|
menu: menu_canvas.gid(),
|
||||||
alert: alert_canvas.gid(),
|
gfx,
|
||||||
|
menu_y_pad: MENU_Y_PAD,
|
||||||
|
menu_x_pad: MENU_X_PAD,
|
||||||
|
menu_min_height: small_height,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
fn clear(&self, canvases: &mut FnvIndexMap<Gid, Canvas, 32>) -> Result<(), xous::Error> {
|
||||||
|
let menu_canvas = canvases.get(&self.menu).expect("couldn't find menu canvas");
|
||||||
|
|
||||||
|
let mut rect = menu_canvas.clip_rect();
|
||||||
|
rect.style = DrawStyle {fill_color: Some(PixelColor::Dark), stroke_color: None, stroke_width: 0,};
|
||||||
|
self.gfx.draw_rectangle(rect)
|
||||||
|
}
|
||||||
|
fn resize(&mut self, new_height: i16, canvases: &mut FnvIndexMap<Gid, Canvas, 32>) -> Result<Point, xous::Error> {
|
||||||
|
let mut menu_canvas = canvases.get_mut(&self.menu).expect("couldn't find menu canvas");
|
||||||
|
let screensize = self.gfx.screen_size().expect("Couldn't get screen size");
|
||||||
|
|
||||||
|
let mut height: i16 = if new_height < self.menu_min_height {
|
||||||
|
self.menu_min_height
|
||||||
|
} else {
|
||||||
|
new_height
|
||||||
|
};
|
||||||
|
if new_height > screensize.y - self.menu_y_pad {
|
||||||
|
height = screensize.y - self.menu_y_pad;
|
||||||
|
}
|
||||||
|
let mut menu_clip_rect = Rectangle::new_coords(self.menu_x_pad, self.menu_y_pad, screensize.x - self.menu_x_pad, height);
|
||||||
|
menu_clip_rect.style = DrawStyle {fill_color: Some(PixelColor::Dark), stroke_color: None, stroke_width: 0,};
|
||||||
|
menu_canvas.set_clip(menu_clip_rect);
|
||||||
|
self.gfx.draw_rectangle(menu_clip_rect).expect("can't clear menu");
|
||||||
|
Ok(menu_clip_rect.br)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Authentication tokens to the GAM are created on a first-come, first-serve basis,
|
Authentication tokens to the GAM are created on a first-come, first-serve basis,
|
||||||
|
|
@ -288,7 +322,7 @@ fn xmain() -> ! {
|
||||||
|
|
||||||
// a map of canvases accessable by Gid
|
// a map of canvases accessable by Gid
|
||||||
let mut canvases: FnvIndexMap<Gid, Canvas, 32> = FnvIndexMap::new();
|
let mut canvases: FnvIndexMap<Gid, Canvas, 32> = FnvIndexMap::new();
|
||||||
// let modallayout = ModalCanvases::init(trng, &mut canvases).expect("can't add modal layouts");
|
let mut menulayout = MenuLayout::init(&xns, &trng, &mut canvases).expect("couldn't create menu layout");
|
||||||
let mut chatlayout = ChatLayout::init(&xns, &trng, &mut canvases).expect("couldn't create chat layout");
|
let mut chatlayout = ChatLayout::init(&xns, &trng, &mut canvases).expect("couldn't create chat layout");
|
||||||
chatlayout.clear(&mut canvases).expect("couldn't clear initial chatlayout");
|
chatlayout.clear(&mut canvases).expect("couldn't clear initial chatlayout");
|
||||||
|
|
||||||
|
|
@ -452,7 +486,7 @@ fn xmain() -> ! {
|
||||||
// ASSUME:
|
// ASSUME:
|
||||||
// very few canvases allow dynamic resizing, so we special case these
|
// very few canvases allow dynamic resizing, so we special case these
|
||||||
if cb.canvas == chatlayout.input {
|
if cb.canvas == chatlayout.input {
|
||||||
let newheight = chatlayout.resize_input(cb.requested.y, &mut canvases).expect("SetCanvasBoundsRequest couldn't recompute input canvas height");
|
let newheight = chatlayout.resize(cb.requested.y, &mut canvases).expect("SetCanvasBoundsRequest couldn't recompute input canvas height");
|
||||||
cb.granted = Some(newheight);
|
cb.granted = Some(newheight);
|
||||||
canvases = recompute_canvases(canvases, Rectangle::new(Point::new(0, 0), screensize));
|
canvases = recompute_canvases(canvases, Rectangle::new(Point::new(0, 0), screensize));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue