menus basically working

This commit is contained in:
bunnie 2021-06-19 00:25:18 +08:00
parent aa967a5a17
commit 69a22adee9
12 changed files with 101 additions and 35 deletions

1
Cargo.lock generated
View file

@ -631,6 +631,7 @@ dependencies = [
"num-traits",
"rkyv 0.4.3",
"rtc",
"susres",
"ticktimer-server",
"trng",
"utralib",

View file

@ -57,6 +57,8 @@ impl Com {
ec_acquired: false,
})
}
pub fn conn(&self) -> CID {self.conn}
pub fn getop_backlight(&self) -> u32 {Opcode::SetBackLight.to_u32().unwrap()}
pub fn power_off_soc(&self) -> Result<(), xous::Error> {
send_message(self.conn,

View file

@ -330,7 +330,7 @@ fn xmain() -> ! {
use crate::implementation::Engine512;
log_server::init_wait().unwrap();
log::set_max_level(log::LevelFilter::Trace);
log::set_max_level(log::LevelFilter::Info);
info!("my PID is {}", xous::process::id());
let xns = xous_names::XousNames::new().unwrap();

View file

@ -28,6 +28,8 @@ num-derive = {version = "0.3", default-features = false}
num-traits = {version = "0.2", default-features = false}
rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]}
susres = {path = "../susres"} # used for the sleep now menu item
enum_dispatch = "0.3.7" # used for trait-based dispatch off of multiple layout objects.
[target.'cfg(not(any(windows,unix)))'.dependencies]

View file

@ -131,6 +131,9 @@ pub(crate) enum Opcode {
/// pass-through to get glyph heights to assist with layout planning, without having to create a gfx connection
QueryGlyphProps,
/// request redraw of IME area
RedrawIme,
Quit,
}

View file

@ -30,6 +30,9 @@ impl Gam {
})
}
pub fn conn(&self) -> CID { self.conn }
pub fn getop_revert_focus(&self) -> u32 {
Opcode::RevertFocus.to_u32().unwrap()
}
pub fn redraw(&self) -> Result<(), xous::Error> {
send_message(self.conn,
Message::new_scalar(Opcode::Redraw.to_usize().unwrap(), 0, 0, 0, 0)
@ -247,6 +250,12 @@ impl Gam {
panic!("unexpected return value: {:#?}", response);
}
}
pub fn request_ime_redraw(&self) -> Result<(), xous::Error> {
send_message(self.conn,
Message::new_scalar(Opcode::RedrawIme.to_usize().unwrap(),
0, 0, 0, 0,)
).map(|_| ())
}
}
use core::sync::atomic::{AtomicU32, Ordering};

View file

@ -386,7 +386,8 @@ impl ContextManager {
// now update the IMEF area, since we're initialized
// note: we may need to skip this call if the context does not utilize a predictor...
if context.predictor.is_some() {
self.imef.redraw().unwrap();
log::debug!("calling IMEF redraw");
self.imef.redraw(true).unwrap();
}
// revert the keyboard vibe state
@ -423,6 +424,15 @@ impl ContextManager {
}
Err(xous::Error::ServerNotFound)
}
pub(crate) fn redraw_imef(&self) -> Result<(), xous::Error> {
if let Some(context) = self.focused_context() {
if context.predictor.is_some() {
log::debug!("calling IMEF redraw");
self.imef.redraw(true).unwrap();
}
}
Ok(())
}
pub(crate) fn find_app_token_by_name(&self, name: &str) -> Option<[u32; 4]> {
self.tm.find_token(name)
}
@ -521,7 +531,7 @@ fn imef_cb(s: String::<4000>) {
#[xous::xous_main]
fn xmain() -> ! {
log_server::init_wait().unwrap();
log::set_max_level(log::LevelFilter::Debug);
log::set_max_level(log::LevelFilter::Info);
info!("my PID is {}", xous::process::id());
let xns = xous_names::XousNames::new().unwrap();
@ -588,7 +598,7 @@ fn xmain() -> ! {
Some(c) => {
let mut rect = c.clip_rect();
rect.normalize(); // normalize to 0,0 coordinates
log::debug!("getcanvasbounds: {:?}", rect);
log::trace!("getcanvasbounds: {:?}", rect);
xous::return_scalar2(msg.sender,
rect.tl.into(),
rect.br.into(),
@ -698,7 +708,7 @@ fn xmain() -> ! {
Some(Opcode::SetCanvasBounds) => {
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
let mut cb = buffer.to_original::<SetCanvasBoundsRequest, _>().unwrap();
log::debug!("SetCanvasBoundsRequest {:?}", cb);
log::trace!("SetCanvasBoundsRequest {:?}", cb);
let granted = if cb.token_type == TokenType::Gam {
context_mgr.set_canvas_height(&gfx, cb.token, cb.requested.y, &status_canvas, &mut canvases)
@ -713,13 +723,13 @@ fn xmain() -> ! {
}
cb.granted = granted;
let ret = api::Return::SetCanvasBoundsReturn(cb);
log::debug!("returning {:?}", cb);
log::trace!("returning {:?}", cb);
buffer.replace(ret).unwrap();
}
Some(Opcode::RequestContentCanvas) => {
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
let req = buffer.to_original::<[u32; 4], _>().unwrap();
log::debug!("RequestContentCanvas {:?}", req);
log::trace!("RequestContentCanvas {:?}", req);
let ret = api::Return::ContentCanvasReturn(context_mgr.get_content_canvas(req));
buffer.replace(ret).unwrap();
@ -727,7 +737,7 @@ fn xmain() -> ! {
Some(Opcode::RenderObject) => {
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let obj = buffer.to_original::<GamObject, _>().unwrap();
log::debug!("renderobject {:?}", obj);
log::trace!("renderobject {:?}", obj);
if let Some(canvas) = canvases.get_mut(&obj.canvas) {
// first, figure out if we should even be drawing to this canvas.
if canvas.is_drawable() {
@ -860,6 +870,9 @@ fn xmain() -> ! {
let height = gfx.glyph_height_hint(GlyphStyle::from(style)).expect("couldn't query glyph height from gfx");
xous::return_scalar(msg.sender, height).expect("could not return QueryGlyphProps request");
}),
Some(Opcode::RedrawIme) => {
context_mgr.redraw_imef().expect("couldn't redraw the IMEF");
},
Some(Opcode::Quit) => break,
None => {log::error!("unhandled message {:?}", msg);}
}

View file

@ -21,6 +21,7 @@ pub struct MenuItem {
action_conn: xous::CID,
action_opcode: u32,
action_payload: MenuPayload,
close_on_select: bool,
}
#[derive(Debug)]
@ -164,7 +165,12 @@ impl Menu {
if self.index != 0 {
self.draw_divider(self.index as i16);
}
self.draw_divider(self.index as i16);
if self.index < self.num_items() - 1 {
self.draw_divider(self.index as i16 + 1);
}
if self.index < self.num_items() - 2 {
self.draw_divider(self.index as i16 + 2);
}
}
}
pub fn next_item(&mut self) {
@ -179,12 +185,17 @@ impl Menu {
self.draw_divider(self.index as i16 - 1);
}
self.draw_divider(self.index as i16);
if self.index < self.num_items() - 1 {
self.draw_divider(self.index as i16 + 1);
}
}
}
pub fn redraw(&mut self) {
// for now, just draw a black rectangle
log::trace!("menu redraw");
let canvas_size = self.gam.get_canvas_bounds(self.canvas).unwrap();
self.canvas_width = Some(canvas_size.x);
// draw the outer border
self.gam.draw_rounded_rectangle(self.canvas,
RoundedRectangle::new(
@ -242,6 +253,10 @@ impl Menu {
unimplemented!("menu buffer targets are a future feature");
}
}
self.index = 0; // reset the index to 0
if mi.close_on_select {
self.gam.relinquish_focus().unwrap();
}
}
},
'←' => {
@ -268,33 +283,49 @@ impl Menu {
pub fn main_menu_thread() {
let mut menu = Menu::new(crate::MAIN_MENU_NAME);
let thing_item = MenuItem {
name: String::<64>::from_str("Do a thing"),
action_conn: menu.gam.conn(),
action_opcode: crate::Opcode::RevertFocus.to_u32().unwrap(),
action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
};
menu.add_item(thing_item);
let xns = xous_names::XousNames::new().unwrap();
let susres = susres::Susres::new_without_hook(&xns).unwrap();
let com = com::Com::new(&xns).unwrap();
let another_item = MenuItem {
name: String::<64>::from_str("Another thing"),
action_conn: menu.gam.conn(),
action_opcode: crate::Opcode::RevertFocus.to_u32().unwrap(),
action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
let blon_item = MenuItem {
name: String::<64>::from_str("Backlight on"),
action_conn: com.conn(),
action_opcode: com.getop_backlight(),
action_payload: MenuPayload::Scalar([191 >> 3, 191 >> 3, 0, 0]),
close_on_select: true,
};
menu.add_item(another_item);
menu.add_item(blon_item);
let bloff_item = MenuItem {
name: String::<64>::from_str("Backlight off"),
action_conn: com.conn(),
action_opcode: com.getop_backlight(),
action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
close_on_select: true,
};
menu.add_item(bloff_item);
let sleep_item = MenuItem {
name: String::<64>::from_str("Sleep now"),
action_conn: susres.conn(),
action_opcode: susres.getop_suspend(),
action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
close_on_select: true,
};
menu.add_item(sleep_item);
let close_item = MenuItem {
name: String::<64>::from_str("Close Menu"),
action_conn: menu.gam.conn(),
action_opcode: crate::Opcode::RevertFocus.to_u32().unwrap(),
action_opcode: menu.gam.getop_revert_focus(),
action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
close_on_select: false, // don't close because we're already closing
};
menu.add_item(close_item);
loop {
let msg = xous::receive_message(menu.sid).unwrap();
log::trace!("|status: Message: {:?}", msg);
log::trace!("message: {:?}", msg);
match FromPrimitive::from_usize(msg.body.id()) {
Some(MenuOpcode::Redraw) => {
menu.redraw();

View file

@ -224,7 +224,7 @@ impl InputTracker {
}
}
pub fn update(&mut self, newkeys: [char; 4]) -> Result<Option<String::<4000>>, xous::Error> {
pub fn update(&mut self, newkeys: [char; 4], force_redraw: bool) -> Result<Option<String::<4000>>, xous::Error> {
let debug1= false;
let mut update_predictor = false;
let mut retstring: Option<String::<4000>> = None;
@ -465,7 +465,7 @@ impl InputTracker {
input_tv.insertion = Some(self.insertion as _);
if debug1{info!("insertion point is {}, characters in string {}", self.insertion, self.characters);}
if do_redraw {
if do_redraw || force_redraw {
write!(input_tv.text, "{}", self.line.as_str().expect("couldn't convert str")).expect("couldn't update TextView string in input canvas");
self.gam.post_textview(&mut input_tv).expect("can't draw input TextView");
if debug1{info!("got computed cursor of {:?}", input_tv.cursor);}
@ -547,7 +547,7 @@ impl InputTracker {
write!(empty_tv.text, "Ready for input...").expect("couldn't set up empty TextView");
if debug_canvas { info!("pc canvas {:?}", pc) }
self.gam.post_textview(&mut empty_tv).expect("can't draw prediction TextView");
} else if update_predictor {
} else if update_predictor || force_redraw {
// alright, first, let's clear the area
self.gam.draw_rectangle(pc, pc_clip).expect("couldn't clear predictor area");
@ -697,7 +697,7 @@ fn xmain() -> ! {
},
];
log::trace!("tracking keys: {:?}", keys);
if let Some(line) = tracker.update(keys).expect("couldn't update input tracker with latest key presses") {
if let Some(line) = tracker.update(keys, false).expect("couldn't update input tracker with latest key presses") {
if dbglistener{info!("sending listeners {:?}", line);}
for maybe_conn in listeners.iter_mut() {
if let Some(conn) = maybe_conn {
@ -728,15 +728,16 @@ fn xmain() -> ! {
// ignore keyboard events until we've fully initialized
}
}
Some(ImefOpcode::Redraw) => {
Some(ImefOpcode::Redraw) => msg_scalar_unpack!(msg, arg, _, _, _, {
if tracker.is_init() {
let force = if arg != 0 { true } else { false };
tracker.clear_area().expect("can't initially clear areas");
tracker.update(['\u{0000}'; 4]).expect("can't setup initial screen arrangement");
tracker.update(['\u{0000}'; 4], force).expect("can't setup initial screen arrangement");
} else {
log::trace!("got redraw, but we're not initialized");
// ignore keyboard events until we've fully initialized
}
}
}),
Some(ImefOpcode::Quit) => {log::error!("recevied quit, goodbye!"); break;}
None => {log::error!("couldn't convert opcode");}
}

View file

@ -209,7 +209,7 @@ pub struct ImefDescriptor {
pub trait ImeFrontEndApi {
fn connect_backend(&self, descriptor: ImefDescriptor) -> Result<(), xous::Error>;
fn hook_listener_callback(&mut self, cb: fn(String::<4000>)) -> Result<(), xous::Error>;
fn redraw(&self) -> Result<(), xous::Error>;
fn redraw(&self, force_all: bool) -> Result<(), xous::Error>;
fn send_keyevent(&self, keys: [char; 4]) -> Result<(), xous::Error>;
}
@ -286,10 +286,11 @@ impl ImeFrontEndApi for ImeFrontEnd {
Ok(())
}
fn redraw(&self) -> Result<(), xous::Error> {
fn redraw(&self, force_all: bool) -> Result<(), xous::Error> {
let arg = if force_all { 1 } else { 0 };
send_message(self.cid,
Message::new_scalar(ImefOpcode::Redraw.to_usize().unwrap(),
0, 0, 0, 0)
arg, 0, 0, 0)
)?;
Ok(())
}

View file

@ -237,6 +237,7 @@ impl Repl{
break; // we get None on the bounds computed if the text view fell off the top of the screen
}
}
// self.gam.request_ime_redraw().expect("couldn't redraw the IME area");
Ok(())
}
}
@ -262,7 +263,7 @@ pub(crate) const APP_NAME_SHELLCHAT: &str = "shellchat"; // the user-facing name
#[xous::xous_main]
fn xmain() -> ! {
log_server::init_wait().unwrap();
log::set_max_level(log::LevelFilter::Trace);
log::set_max_level(log::LevelFilter::Info);
info!("my PID is {}", xous::process::id());
let xns = xous_names::XousNames::new().unwrap();

View file

@ -54,6 +54,8 @@ impl Susres {
execution_gate_conn: 0,
})
}
pub fn conn(&self) -> CID { self.conn }
pub fn getop_suspend(&self) -> u32 { Opcode::SuspendRequest.to_u32().unwrap() }
pub fn new_without_hook(xns: &xous_names::XousNames) -> Result<Self, xous::Error> {
let conn = xns.request_connection_blocking(api::SERVER_NAME_SUSRES)?;