capture typesetting overflow in ComposedType and pass thru to gam.post_textview()

This commit is contained in:
nworbnhoj 2023-08-26 03:42:05 +10:00
parent 77f25bc416
commit 6362ff9e4d
5 changed files with 16 additions and 3 deletions

View file

@ -151,6 +151,7 @@ impl Gam {
api::Return::RenderReturn(tvr) => {
tv.bounds_computed = tvr.bounds_computed;
tv.cursor = tvr.cursor;
tv.overflow = tvr.overflow;
}
api::Return::NotCurrentlyDrawable => {
tv.bounds_computed = None;
@ -172,6 +173,7 @@ impl Gam {
api::Return::RenderReturn(tvr) => {
tv.bounds_computed = tvr.bounds_computed;
tv.cursor = tvr.cursor;
tv.overflow = tvr.overflow;
}
_ => panic!("GAM_API: bounds_compute_textview got a return value from the server that isn't expected or handled")
}

View file

@ -245,6 +245,7 @@ fn wrapped_main() -> ! {
// copy back the fields that we want to be mutable
tv.cursor = tv_clone.cursor;
tv.bounds_computed = tv_clone.bounds_computed;
tv.overflow = tv_clone.overflow;
let ret = api::Return::RenderReturn(tv);
buffer.replace(ret).unwrap();
@ -285,6 +286,7 @@ fn wrapped_main() -> ! {
log::trace!("got computed cursor of {:?}, bounds {:?}", tv_clone.cursor, tv_clone.bounds_computed);
tv.cursor = tv_clone.cursor;
tv.bounds_computed = tv_clone.bounds_computed;
tv.overflow = tv_clone.overflow;
let ret = api::Return::RenderReturn(tv);
buffer.replace(ret).unwrap();

View file

@ -156,6 +156,7 @@ impl Gfx {
let tvr = buf.to_original::<TextView, _>().unwrap();
tv.bounds_computed = tvr.bounds_computed;
tv.cursor = tvr.cursor;
tv.overflow = tvr.overflow;
Ok(())
}

View file

@ -387,6 +387,7 @@ fn wrapped_main(main_thread_token: backend::MainThreadToken) -> ! {
tv.cursor.pt.x = composition.final_cursor().pt.x;
tv.cursor.pt.y = composition.final_cursor().pt.y;
tv.cursor.line_height = composition.final_cursor().line_height;
tv.overflow = Some(composition.final_overflow());
tv.bounds_computed = Some(
clear_rect

View file

@ -93,13 +93,15 @@ pub(crate) struct ComposedType {
words: Vec::<TypesetWord>,
bounding_box: ClipRect,
cursor: Cursor,
overflow: bool,
}
impl ComposedType {
pub fn new(words: Vec::<TypesetWord>, bounds: ClipRect, cursor: Cursor) -> Self {
pub fn new(words: Vec::<TypesetWord>, bounds: ClipRect, cursor: Cursor, overflow: bool) -> Self {
ComposedType {
words,
bounding_box: bounds,
cursor,
overflow,
}
}
pub fn bb_width(&self) -> i16 {
@ -177,6 +179,9 @@ impl ComposedType {
pub fn final_cursor(&self) -> Cursor {
self.cursor
}
pub fn final_overflow(&self) -> bool {
self.overflow
}
}
/// Typesetter takes a string and attempts to lay it out within a region defined by
/// a single point known as the "Extent". This is the maximum extent allowable for
@ -267,7 +272,8 @@ impl Typesetter {
log::error!("Words cannot be typset because the width of the typset region is too narrow.");
return ComposedType::new(composition,
ClipRect::new(self.bb.min.x, self.bb.min.y, self.bb.min.x, self.bb.min.y),
self.cursor
self.cursor,
true,
);
}
// algorithm:
@ -422,7 +428,8 @@ impl Typesetter {
self.bb.min.x, self.bb.min.y,
self.max_width as i16, self.cursor.pt.y + self.last_line_height as i16,
),
self.cursor
self.cursor,
self.overflow,
);
// cleanup any state based on the overflow strategy
match strat {