mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
implement chat.dialogue_modal()
allowing the chat UI to list & select an existing dialogue in the current pddb dict
This commit is contained in:
parent
278fb8640a
commit
defac5ed7e
2 changed files with 36 additions and 1 deletions
|
|
@ -10,5 +10,13 @@
|
||||||
"chat.test_cmd": {
|
"chat.test_cmd": {
|
||||||
"en": "test chat library UI",
|
"en": "test chat library UI",
|
||||||
"en-tts": "test chat library UI"
|
"en-tts": "test chat library UI"
|
||||||
|
},
|
||||||
|
"chat.dialogue_title": {
|
||||||
|
"en": "read exiting dialogue",
|
||||||
|
"en-tts": "read exiting dialogue"
|
||||||
|
},
|
||||||
|
"chat.dict_empty": {
|
||||||
|
"en": "no dialogues available to read",
|
||||||
|
"en-tts": "no dialogues available to read"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ pub(crate) struct Ui {
|
||||||
|
|
||||||
canvas: Gid,
|
canvas: Gid,
|
||||||
gam: gam::Gam,
|
gam: gam::Gam,
|
||||||
|
modals: Modals,
|
||||||
|
|
||||||
// variables that define our graphical attributes
|
// variables that define our graphical attributes
|
||||||
screensize: Point,
|
screensize: Point,
|
||||||
|
|
@ -78,7 +79,8 @@ impl Ui {
|
||||||
focuschange_id: Some(ChatOp::GamChangeFocus as u32),
|
focuschange_id: Some(ChatOp::GamChangeFocus as u32),
|
||||||
})
|
})
|
||||||
.expect("couldn't register Ux context for chat");
|
.expect("couldn't register Ux context for chat");
|
||||||
|
let xns = XousNames::new().unwrap();
|
||||||
|
let modals = Modals::new(&xns).unwrap();
|
||||||
let canvas = gam
|
let canvas = gam
|
||||||
.request_content_canvas(token.unwrap())
|
.request_content_canvas(token.unwrap())
|
||||||
.expect("couldn't get content canvas");
|
.expect("couldn't get content canvas");
|
||||||
|
|
@ -98,6 +100,7 @@ impl Ui {
|
||||||
opcode_event,
|
opcode_event,
|
||||||
canvas,
|
canvas,
|
||||||
gam,
|
gam,
|
||||||
|
modals,
|
||||||
screensize,
|
screensize,
|
||||||
bubble_width: ((screensize.x / 5) * 4) as u16, // 80% width for the text bubbles
|
bubble_width: ((screensize.x / 5) * 4) as u16, // 80% width for the text bubbles
|
||||||
margin: Point::new(4, 4),
|
margin: Point::new(4, 4),
|
||||||
|
|
@ -220,6 +223,30 @@ impl Ui {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn dialogue_modal(&mut self) {
|
||||||
|
if let Some(dict) = &self.pddb_dict {
|
||||||
|
match self.pddb.list_keys(&dict, None) {
|
||||||
|
Ok(keys) => {
|
||||||
|
if keys.len() > 0 {
|
||||||
|
self.modals
|
||||||
|
.add_list(keys.iter().map(|s| s.as_str()).collect())
|
||||||
|
.expect("failed modal add_list");
|
||||||
|
self.pddb_key = self
|
||||||
|
.modals
|
||||||
|
.get_radiobutton(t!("chat.dialogue_title", locales::LANG))
|
||||||
|
.ok();
|
||||||
|
log::info!("selected dialogue {}:{:?}", dict, self.pddb_key);
|
||||||
|
} else {
|
||||||
|
self.modals
|
||||||
|
.show_notification(t!("chat.dict_empty", locales::LANG), None)
|
||||||
|
.expect("notification failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => log::warn!("failed to list pddb keys: {e}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// set listener sid and opcodes to receive UI-event msgs & user posts
|
// set listener sid and opcodes to receive UI-event msgs & user posts
|
||||||
// pub fn listen_set(
|
// pub fn listen_set(
|
||||||
// &self,
|
// &self,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue