mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
implement chat app_menu
This commit is contained in:
parent
b095462f29
commit
4f03a27e79
3 changed files with 73 additions and 34 deletions
|
|
@ -16,6 +16,7 @@ pub enum ChatOp {
|
||||||
/// redraw our UI
|
/// redraw our UI
|
||||||
GamRedraw,
|
GamRedraw,
|
||||||
ListenSet,
|
ListenSet,
|
||||||
|
MenuAdd,
|
||||||
PostAdd,
|
PostAdd,
|
||||||
PostDel,
|
PostDel,
|
||||||
PostFind,
|
PostFind,
|
||||||
|
|
@ -66,6 +67,7 @@ pub enum Event {
|
||||||
Bottom, // Bottom of post list reached
|
Bottom, // Bottom of post list reached
|
||||||
Key, // keystroke
|
Key, // keystroke
|
||||||
Post, // new user Post committed
|
Post, // new user Post committed
|
||||||
|
Menu, // menu item clicked
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,13 @@ pub mod dialogue;
|
||||||
pub mod ui;
|
pub mod ui;
|
||||||
|
|
||||||
pub use api::*;
|
pub use api::*;
|
||||||
|
use gam::MenuItem;
|
||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
use xous::{Error, CID, SID};
|
use xous::{Error, MessageEnvelope, CID, SID};
|
||||||
use xous_ipc::Buffer;
|
use xous_ipc::Buffer;
|
||||||
|
|
||||||
pub struct Chat {
|
pub struct Chat {
|
||||||
|
|
@ -18,7 +19,8 @@ pub struct Chat {
|
||||||
|
|
||||||
impl Chat {
|
impl Chat {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
app_name: &str,
|
app_name: &'static str,
|
||||||
|
app_menu: &'static str,
|
||||||
app_cid: Option<CID>,
|
app_cid: Option<CID>,
|
||||||
opcode_post: Option<usize>,
|
opcode_post: Option<usize>,
|
||||||
opcode_event: Option<usize>,
|
opcode_event: Option<usize>,
|
||||||
|
|
@ -26,12 +28,19 @@ impl Chat {
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let chat_sid = xous::create_server().unwrap();
|
let chat_sid = xous::create_server().unwrap();
|
||||||
let chat_cid = xous::connect(chat_sid).unwrap();
|
let chat_cid = xous::connect(chat_sid).unwrap();
|
||||||
let app_name = app_name.to_string();
|
|
||||||
|
|
||||||
log::info!("Starting chat UI server",);
|
log::info!("Starting chat UI server",);
|
||||||
thread::spawn({
|
thread::spawn({
|
||||||
move || {
|
move || {
|
||||||
server(chat_sid, app_cid, opcode_post, opcode_event, opcode_rawkeys);
|
server(
|
||||||
|
chat_sid,
|
||||||
|
app_name,
|
||||||
|
app_menu,
|
||||||
|
app_cid,
|
||||||
|
opcode_post,
|
||||||
|
opcode_event,
|
||||||
|
opcode_rawkeys,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -60,6 +69,13 @@ impl Chat {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn menu_add(&self, item: MenuItem) -> Result<(), Error> {
|
||||||
|
match Buffer::into_buf(item) {
|
||||||
|
Ok(buf) => buf.send(self.cid, ChatOp::MenuAdd as u32).map(|_| ()),
|
||||||
|
Err(_) => Err(xous::Error::InternalError),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// add a new Post to the current Dialogue
|
// add a new Post to the current Dialogue
|
||||||
pub fn post_add(
|
pub fn post_add(
|
||||||
&self,
|
&self,
|
||||||
|
|
@ -145,7 +161,8 @@ impl Chat {
|
||||||
|
|
||||||
pub fn server(
|
pub fn server(
|
||||||
sid: SID,
|
sid: SID,
|
||||||
app_name: &str,
|
app_name: &'static str,
|
||||||
|
app_menu: &'static str,
|
||||||
app_cid: Option<CID>,
|
app_cid: Option<CID>,
|
||||||
opcode_post: Option<usize>,
|
opcode_post: Option<usize>,
|
||||||
opcode_event: Option<usize>,
|
opcode_event: Option<usize>,
|
||||||
|
|
@ -160,7 +177,7 @@ pub fn server(
|
||||||
// let mut opcode_event = opcode_event;
|
// let mut opcode_event = opcode_event;
|
||||||
// let mut opcode_rawkeys = opcode_rawkeys;
|
// let mut opcode_rawkeys = opcode_rawkeys;
|
||||||
|
|
||||||
let mut ui = ui::Ui::new(sid, app_name, app_cid, opcode_event);
|
let mut ui = ui::Ui::new(sid, app_name, app_menu, app_cid, opcode_event);
|
||||||
|
|
||||||
let mut user_post = true;
|
let mut user_post = true;
|
||||||
let mut allow_redraw = false;
|
let mut allow_redraw = false;
|
||||||
|
|
@ -236,14 +253,15 @@ pub fn server(
|
||||||
Some(ChatOp::PostFlag) => {
|
Some(ChatOp::PostFlag) => {
|
||||||
log::warn!("ChatOp::PostFlag not implemented");
|
log::warn!("ChatOp::PostFlag not implemented");
|
||||||
}
|
}
|
||||||
Some(ChatOp::ListenSet) => {
|
Some(ChatOp::MenuAdd) => {
|
||||||
// set listener sid and opcodes to receive UI-event msgs & user posts
|
log::warn!("ChatOp::MenuAdd not implemented");
|
||||||
// pub fn listen_set(&self, cid: xous::CID, opcode_post: Option<u32>, opcode_event: Option<u32>, opcode_rawkeys: Option<u32>) {
|
let buffer =
|
||||||
// self.listener = cid;
|
unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||||
// self.opcode_post = opcode_post;
|
if let Ok(menu_item) = buffer.to_original::<MenuItem, _>() {
|
||||||
// self.opcode_event = opcode_event;
|
ui.menu_add(menu_item);
|
||||||
// self.opcode_rawkeys = opcode_rawkeys;
|
} else {
|
||||||
// }
|
log::warn!("failed to deserialize MenuItem");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Some(ChatOp::UiButton) => {
|
Some(ChatOp::UiButton) => {
|
||||||
log::warn!("ChatOp::UiButton not implemented");
|
log::warn!("ChatOp::UiButton not implemented");
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
//use crate::{ChatOp, Dialogue, Event, Post, CHAT_SERVER_NAME};
|
//use crate::{ChatOp, Dialogue, Event, Post, CHAT_SERVER_NAME};
|
||||||
use dialogue::{author::Author, post::Post, Dialogue};
|
use dialogue::{author::Author, post::Post, Dialogue};
|
||||||
use gam::UxRegistration;
|
use gam::{menu_matic, MenuMatic, MenuPayload, UxRegistration};
|
||||||
use graphics_server::api::GlyphStyle;
|
use graphics_server::api::GlyphStyle;
|
||||||
use graphics_server::{DrawStyle, Gid, PixelColor, Point, Rectangle, TextBounds, TextView};
|
use graphics_server::{DrawStyle, Gid, PixelColor, Point, Rectangle, TextBounds, TextView};
|
||||||
use locales::t;
|
use locales::t;
|
||||||
|
|
@ -49,6 +49,10 @@ pub(crate) struct Ui {
|
||||||
bubble_radius: u16,
|
bubble_radius: u16,
|
||||||
bubble_space: i16, // spacing between text bubbles
|
bubble_space: i16, // spacing between text bubbles
|
||||||
|
|
||||||
|
// variables that define a menu
|
||||||
|
app_menu: String,
|
||||||
|
menu_mgr: MenuMatic,
|
||||||
|
|
||||||
// our security token for making changes to our record on the GAM
|
// our security token for making changes to our record on the GAM
|
||||||
token: [u32; 4],
|
token: [u32; 4],
|
||||||
}
|
}
|
||||||
|
|
@ -57,7 +61,8 @@ pub(crate) struct Ui {
|
||||||
impl Ui {
|
impl Ui {
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
sid: xous::SID,
|
sid: xous::SID,
|
||||||
app_name: &str,
|
app_name: &'static str,
|
||||||
|
app_menu: &'static str,
|
||||||
app_cid: Option<xous::CID>,
|
app_cid: Option<xous::CID>,
|
||||||
opcode_event: Option<usize>,
|
opcode_event: Option<usize>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
|
@ -89,6 +94,12 @@ impl Ui {
|
||||||
.expect("couldn't get dimensions of content canvas");
|
.expect("couldn't get dimensions of content canvas");
|
||||||
let pddb = pddb::Pddb::new();
|
let pddb = pddb::Pddb::new();
|
||||||
pddb.try_mount();
|
pddb.try_mount();
|
||||||
|
let menu_mgr = menu_matic(
|
||||||
|
Vec::<MenuItem>::new(),
|
||||||
|
app_menu,
|
||||||
|
Some(xous::create_server().unwrap()),
|
||||||
|
)
|
||||||
|
.expect("couldn't create MenuMatic manager");
|
||||||
Ui {
|
Ui {
|
||||||
input: None,
|
input: None,
|
||||||
msg: None,
|
msg: None,
|
||||||
|
|
@ -107,7 +118,9 @@ impl Ui {
|
||||||
bubble_margin: Point::new(4, 4),
|
bubble_margin: Point::new(4, 4),
|
||||||
bubble_radius: 4,
|
bubble_radius: 4,
|
||||||
bubble_space: 4,
|
bubble_space: 4,
|
||||||
token: token.unwrap(),
|
app_menu: app_menu.to_owned(),
|
||||||
|
menu_mgr: menu_mgr,
|
||||||
|
token: token,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -257,19 +270,9 @@ impl Ui {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// set listener sid and opcodes to receive UI-event msgs & user posts
|
pub fn menu_add(&self, item: MenuItem) {
|
||||||
// pub fn listen_set(
|
self.menu_mgr.add_item(item);
|
||||||
// &self,
|
}
|
||||||
// cid: xous::CID,
|
|
||||||
// opcode_post: Option<u32>,
|
|
||||||
// opcode_event: Option<u32>,
|
|
||||||
// opcode_rawkeys: Option<u32>,
|
|
||||||
// ) {
|
|
||||||
// self.listener = cid;
|
|
||||||
// self.opcode_post = opcode_post;
|
|
||||||
// self.opcode_event = opcode_event;
|
|
||||||
// self.opcode_rawkeys = opcode_rawkeys;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// add a new Post to the current Dialogue
|
// add a new Post to the current Dialogue
|
||||||
pub fn post_add(
|
pub fn post_add(
|
||||||
|
|
@ -343,9 +346,18 @@ impl Ui {
|
||||||
}
|
}
|
||||||
|
|
||||||
// send a xous scalar message with an Event to the Chat App cid/opcode
|
// send a xous scalar message with an Event to the Chat App cid/opcode
|
||||||
fn event(&self, _event: Event) {
|
pub fn event(&self, event: Event) {
|
||||||
log::warn!("not implemented");
|
log::info!("Event {:?}", event);
|
||||||
// Err(Error::new(ErrorKind::Other, "not implemented"))
|
match (self.app_cid, self.opcode_event) {
|
||||||
|
(Some(cid), Some(opcode)) => match xous::send_message(
|
||||||
|
cid,
|
||||||
|
xous::Message::new_scalar(opcode as usize, event as usize, 0, 0, 0),
|
||||||
|
) {
|
||||||
|
Ok(_) => log::info!("sent event msg"),
|
||||||
|
Err(e) => log::warn!("failed to send event msg: {:?}", e),
|
||||||
|
},
|
||||||
|
_ => log::warn!("missing cid or event opcode"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bubble(&self, post: &Post, author: &Author, baseline: i16) -> TextView {
|
fn bubble(&self, post: &Post, author: &Author, baseline: i16) -> TextView {
|
||||||
|
|
@ -393,12 +405,19 @@ impl Ui {
|
||||||
.expect("can't clear canvas area");
|
.expect("can't clear canvas area");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn raise_menu(&mut self) {
|
||||||
|
// self.title_dirty = true;
|
||||||
|
self.gam
|
||||||
|
.raise_menu(&self.app_menu)
|
||||||
|
.expect("couldn't raise our submenu");
|
||||||
|
log::info!("raised menu");
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn redraw(&mut self) -> Result<(), xous::Error> {
|
pub(crate) fn redraw(&mut self) -> Result<(), xous::Error> {
|
||||||
self.clear_area();
|
self.clear_area();
|
||||||
|
|
||||||
// this defines the bottom border of the text bubbles as they stack up wards
|
// this defines the bottom border of the text bubbles as they stack up wards
|
||||||
let mut bubble_baseline = self.screensize.y - self.margin.y;
|
let mut bubble_baseline = self.screensize.y - self.margin.y;
|
||||||
|
|
||||||
if let Some(dialogue) = &self.dialogue {
|
if let Some(dialogue) = &self.dialogue {
|
||||||
for post in dialogue.posts().rev() {
|
for post in dialogue.posts().rev() {
|
||||||
if let Some(author) = dialogue.author(post.author_id()) {
|
if let Some(author) = dialogue.author(post.author_id()) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue