ellipsis support and fixing prediction redraw bugs

This commit is contained in:
bunnie 2021-03-09 02:24:45 +08:00
parent a4a96c9c56
commit 7d1fb5a31b
4 changed files with 28 additions and 16 deletions

View file

@ -194,8 +194,8 @@ pub fn recompute_canvases(canvases: FnvIndexMap<Gid, Canvas, U32>, screen: Recta
let mut higher_clipregions: BinaryHeap<Canvas, U32, Max> = BinaryHeap::new();
let mut trust_level: u8 = 255;
// sorted_clipregions is a Max heap keyed on trust, so popping the elements off will return them sorted from most to least trusted
info!("CANVAS: received screen argument of {:?}", screen);
info!("CANVAS: now determining which regions are drawable");
if debug{info!("CANVAS: received screen argument of {:?}", screen);}
if debug{info!("CANVAS: now determining which regions are drawable");}
loop {
if let Some(c) = sorted_clipregions.pop() {
if debug { info!(" CANVAS: considering {:?}", c);}

View file

@ -104,7 +104,7 @@ impl ChatLayout {
graphics_server::draw_rectangle(self.gfx_conn, rect).expect("GAM: can't clear canvas");
Ok(())
}
pub fn resize_input(&mut self, new_height: i16, canvases: &mut FnvIndexMap<Gid, Canvas, U32>) -> Result<i16, xous::Error> {
pub fn resize_input(&mut self, new_height: i16, canvases: &mut FnvIndexMap<Gid, Canvas, U32>) -> Result<Point, xous::Error> {
let input_canvas = canvases.get(&self.input).expect("GAM: couldn't find input canvas");
let content_canvas = canvases.get(&self.content).expect("GAM: couldn't find content canvas");
let predictive_canvas = canvases.get(&self.predictive).expect("GAM: couldn't find predictive canvas");
@ -131,10 +131,10 @@ impl ChatLayout {
graphics_server::draw_rectangle(self.gfx_conn, new_content_rect).expect("GAM: can't clear canvas");
}
// we resized to this new height
Ok(height)
Ok(new_content_rect.br)
} else {
// we didn't resize anything, height unchanged
Ok(input_canvas.clip_rect().br.y)
Ok(input_canvas.clip_rect().br)
}
}
}
@ -312,7 +312,7 @@ fn xmain() -> ! {
// very few canvases allow dynamic resizing, so we special case these
if cb.canvas == chatlayout.input {
let newheight = chatlayout.resize_input(cb.requested.y, &mut canvases).expect("GAM: SetCanvasBoundsRequest couldn't recompute input canvas height");
cb.granted = Some(Point::new(0, newheight));
cb.granted = Some(newheight);
canvases = recompute_canvases(canvases, Rectangle::new(Point::new(0, 0), screensize));
} else {
cb.granted = None;

View file

@ -12,8 +12,6 @@ use log::{error, info};
use graphics_server::{Gid, Line, PixelColor, Point, Rectangle, TextBounds, TextView, DrawStyle};
use blitstr_ref as blitstr;
use heapless::Vec;
use heapless::consts::U32;
use core::pin::Pin;
use ime_plugin_api::{PredictionTriggers, PredictionPlugin, PredictionApi};
@ -212,7 +210,7 @@ impl InputTracker {
}
pub fn update(&mut self, newkeys: [char; 4]) -> Result<(), xous::Error> {
let debug1= false;
let debug1= true;
let mut update_predictor = false;
if let Some(ic) = self.input_canvas {
if debug1{info!("IMEF: updating input area");}
@ -375,6 +373,7 @@ impl InputTracker {
self.predictor.unwrap().feedback_picked(self.pred_phrase).expect("IMEF: couldn't send feedback to predictor");
self.pred_phrase.clear();
self.can_unpick = true;
update_predictor = true;
}
self.last_trigger_char = Some(self.insertion);
}
@ -383,6 +382,7 @@ impl InputTracker {
self.predictor.unwrap().feedback_picked(self.pred_phrase).expect("IMEF: couldn't send feedback to predictor");
self.pred_phrase.clear();
self.can_unpick = true;
update_predictor = true;
}
self.last_trigger_char = Some(self.insertion);
}
@ -393,7 +393,6 @@ impl InputTracker {
if !(trigger.punctuation && k.is_ascii_punctuation() ||
trigger.whitespace && k.is_ascii_whitespace() ) {
self.pred_phrase.push(k).expect("IMEF: ran out of space pushing character into prediction phrase");
update_predictor = true;
}
}
self.characters += 1;
@ -442,7 +441,7 @@ impl InputTracker {
}
input_tv.insertion = Some(self.insertion as u32);
info!("IMEF: insertion point is {}, characters in string {}", self.insertion, self.characters);
if debug1{info!("IMEF: insertion point is {}, characters in string {}", self.insertion, self.characters);}
if do_redraw {
write!(input_tv.text, "{}", self.line.as_str().expect("IMEF: couldn't convert str")).expect("IMEF: couldn't update TextView string in input canvas");
gam::post_textview(self.gam_conn, &mut input_tv).expect("IMEF: can't draw input TextView");
@ -467,9 +466,9 @@ impl InputTracker {
match req.granted {
Some(bounds) => {
self.was_grown = true;
if debug1{info!("IMEF: refresh succeeded, now redrawing");}
if debug1{info!("IMEF: refresh succeeded, now redrawing with height of {:?}", bounds);}
// request was approved, redraw with the new bounding box
input_tv.bounds_hint = TextBounds::BoundingBox(Rectangle::new(Point::new(0,1), ic_bounds));
input_tv.bounds_hint = TextBounds::BoundingBox(Rectangle::new(Point::new(0,1), bounds));
input_tv.bounds_computed = None;
gam::post_textview(self.gam_conn, &mut input_tv).expect("IMEF: can't draw input TextView");
},
@ -482,8 +481,7 @@ impl InputTracker {
}
/*
what else do we need:
- relay hints to the prediction engine, and draw prediction results
- extend blitstr to add ellipsis '…" when the clipping rectangle overflows
- debug prediction order
- registration for listening to string results
*/
// prediction area is drawn second because the area could be cleared on behalf of a resize of the text box
@ -549,6 +547,7 @@ impl InputTracker {
p_tv.draw_border = false;
p_tv.border_width = 1;
p_tv.clear_area = false;
p_tv.ellipsis = true;
p_tv.style = blitstr::GlyphStyle::Small;
write!(p_tv.text, "{}", pred_str).expect("IMEF: can't write the prediction string");
gam::post_textview(self.gam_conn, &mut p_tv).expect("IMEF: couldn't post prediction text");

View file

@ -24,10 +24,23 @@ fn xmain() -> ! {
let mut history: Queue<xous::String<64>, U4> = Queue::new(); // this has 2^4 elements = 16??? or does it just have 4 elements.
let history_max = 4;
if true { // loads defaults into the predictor array to test things
use core::fmt::Write as CoreWriter;
let mut test1: xous::String::<64> = xous::String::new();
write!(test1, "This〰should overflow the box").unwrap();
history.enqueue(test1).unwrap();
let mut test2: xous::String::<64> = xous::String::new();
write!(test2, "Another string too long").unwrap();
history.enqueue(test2).unwrap();
let mut test3: xous::String::<64> = xous::String::new();
write!(test3, "Mary had a little lamb").unwrap();
history.enqueue(test3).unwrap();
}
let mytriggers = PredictionTriggers {
newline: true,
punctuation: false,
whitespace: false,
whitespace: true,
};
info!("IME_SH: ready to accept requests");