mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-21 09:14:34 +00:00
refactor layout to take advantage of pre-computed height bubbles
mostly works, so checkpointing it here. need to debug why going down after going up (in terms of selection) is not working.
This commit is contained in:
parent
f479344668
commit
157f0031e6
3 changed files with 243 additions and 157 deletions
|
|
@ -7,7 +7,7 @@ use crate::{now, default_textview};
|
||||||
|
|
||||||
use author::Author;
|
use author::Author;
|
||||||
use gam::Gam;
|
use gam::Gam;
|
||||||
use core::slice::Iter;
|
use core::slice::{Iter, IterMut};
|
||||||
use post::Post;
|
use post::Post;
|
||||||
use rkyv::{Archive, Deserialize, Serialize};
|
use rkyv::{Archive, Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
@ -178,12 +178,27 @@ impl Dialogue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return a slice of posts
|
||||||
|
pub fn posts_as_slice(&self) -> &[Post] {
|
||||||
|
&self.posts
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn posts_as_slice_mut(&mut self) -> &mut [Post] {
|
||||||
|
&mut self.posts
|
||||||
|
}
|
||||||
|
|
||||||
/// Return an iterator over the Dialogue Posts (oldest first)
|
/// Return an iterator over the Dialogue Posts (oldest first)
|
||||||
///
|
///
|
||||||
pub fn posts(&self) -> Iter<Post> {
|
pub fn posts(&self) -> Iter<Post> {
|
||||||
return self.posts.iter();
|
return self.posts.iter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return a mut iterator over the Dialogue Posts (oldest first)
|
||||||
|
///
|
||||||
|
pub fn posts_mut(&mut self) -> IterMut<Post> {
|
||||||
|
return self.posts.iter_mut();
|
||||||
|
}
|
||||||
|
|
||||||
/// Return Some<Author> by id, or None.
|
/// Return Some<Author> by id, or None.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ pub(crate) fn default_textview(
|
||||||
let mut bubble_tv = TextView::new(
|
let mut bubble_tv = TextView::new(
|
||||||
vp.canvas,
|
vp.canvas,
|
||||||
TextBounds::GrowableFromBl(
|
TextBounds::GrowableFromBl(
|
||||||
Point::new(vp.margin.x, vp.screensize.y),
|
Point::new(vp.margin.x, vp.layout_screensize.y),
|
||||||
vp.bubble_width
|
vp.bubble_width
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
@ -40,7 +40,7 @@ pub(crate) fn default_textview(
|
||||||
bubble_tv.clip_rect = Some(
|
bubble_tv.clip_rect = Some(
|
||||||
Rectangle::new(
|
Rectangle::new(
|
||||||
Point::new(0, vp.status_height as i16 + vp.margin.y),
|
Point::new(0, vp.status_height as i16 + vp.margin.y),
|
||||||
vp.screensize
|
vp.layout_screensize
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
bubble_tv.draw_border = true;
|
bubble_tv.draw_border = true;
|
||||||
|
|
@ -54,6 +54,52 @@ pub(crate) fn default_textview(
|
||||||
bubble_tv
|
bubble_tv
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return a TextView bubble representing a Dialogue Post
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `vp` - the visual properties to be applied to the textview
|
||||||
|
/// * `topdown` - direction of the layout
|
||||||
|
/// * `post` - the post to represent in a TextView bubble
|
||||||
|
/// * `dialogue` - containing the Post for context info
|
||||||
|
/// * `hilite` - hilite this Post on the screen (thicker border)
|
||||||
|
/// * `anchor_y` - the vertical position on screen to draw TextView bubble
|
||||||
|
///
|
||||||
|
fn bubble(
|
||||||
|
vp: &VisualProperties,
|
||||||
|
topdown: bool,
|
||||||
|
post: &crate::dialogue::post::Post,
|
||||||
|
dialogue: &crate::dialogue::Dialogue,
|
||||||
|
hilite: bool,
|
||||||
|
anchor_y: i16) -> TextView {
|
||||||
|
// create a textview with all of our default properties
|
||||||
|
let mut bubble_tv = default_textview(post, hilite, vp);
|
||||||
|
|
||||||
|
// set alignment of bubble left/right
|
||||||
|
let mut align_right = false;
|
||||||
|
let mut anchor_x = vp.margin.x; // default to align left
|
||||||
|
if let Some(author) = dialogue.author(post.author_id()) {
|
||||||
|
if author.flag_is(AuthorFlag::Right) {
|
||||||
|
// align right
|
||||||
|
align_right = true;
|
||||||
|
anchor_x = vp.layout_screensize.x - vp.margin.x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// set the text bounds of the bubble and the growth direction
|
||||||
|
let anchor = Point::new(anchor_x, anchor_y);
|
||||||
|
let width = vp.bubble_width;
|
||||||
|
let text_bounds = match (topdown, align_right) {
|
||||||
|
(true, true) => TextBounds::GrowableFromTr(anchor, width),
|
||||||
|
(true, false) => TextBounds::GrowableFromTl(anchor, width),
|
||||||
|
(false, true) => TextBounds::GrowableFromBr(anchor, width),
|
||||||
|
(false, false) => TextBounds::GrowableFromBl(anchor, width),
|
||||||
|
};
|
||||||
|
|
||||||
|
bubble_tv.bounds_hint = text_bounds;
|
||||||
|
bubble_tv
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pub struct Chat {
|
pub struct Chat {
|
||||||
cid: CID,
|
cid: CID,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,11 @@ use xous_names::XousNames;
|
||||||
|
|
||||||
pub const BUSY_ANIMATION_RATE_MS: usize = 200;
|
pub const BUSY_ANIMATION_RATE_MS: usize = 200;
|
||||||
|
|
||||||
|
/// Variables that define the visual properties of the layout
|
||||||
pub struct VisualProperties {
|
pub struct VisualProperties {
|
||||||
pub canvas: Gid,
|
pub canvas: Gid,
|
||||||
// variables that define our graphical attributes
|
pub total_screensize: Point,
|
||||||
pub screensize: Point,
|
pub layout_screensize: Point,
|
||||||
/// height of the status bar. This is subtracted from screensize.
|
/// height of the status bar. This is subtracted from screensize.
|
||||||
pub status_height: u16,
|
pub status_height: u16,
|
||||||
pub bubble_width: u16,
|
pub bubble_width: u16,
|
||||||
|
|
@ -61,13 +62,16 @@ pub(crate) struct Ui {
|
||||||
modals: Modals,
|
modals: Modals,
|
||||||
tt: Ticktimer,
|
tt: Ticktimer,
|
||||||
|
|
||||||
// variables regarding the posts currently onscreen
|
/// These variables are managed exclusively by the layout routine.
|
||||||
// the selected post is hilighted onscreen and the focus of the msg menu F4
|
/// the selected post is highlighted onscreen and the focus of the msg menu
|
||||||
post_selected: Option<usize>,
|
layout_selected: Option<usize>,
|
||||||
// the anchor post is drawn first, at the top or bottom of the screen
|
/// the range of posts that are currently drawable. This was originally implemented as
|
||||||
post_anchor: Option<usize>,
|
/// an Option<Range>, but we need to be able to do RangeInclusive and Reversed ranges.
|
||||||
// layout post bubbles on the screen from top-down or bottom-up
|
/// The RangeBounds trait isn't object-safe, so we can't Box/dyn it either...
|
||||||
post_topdown: bool,
|
/// So, instead, we turn the ranges into a Vec and operate from there...
|
||||||
|
layout_range: Vec<usize>,
|
||||||
|
/// layout post bubbles on the screen from top-down or bottom-up
|
||||||
|
layout_topdown: bool,
|
||||||
|
|
||||||
/// TextView for the status bar. This encapsulates the state of the busy animation, and the text within.
|
/// TextView for the status bar. This encapsulates the state of the busy animation, and the text within.
|
||||||
status_tv: TextView,
|
status_tv: TextView,
|
||||||
|
|
@ -154,7 +158,8 @@ impl Ui {
|
||||||
let status_last_update_ms = tt.elapsed_ms();
|
let status_last_update_ms = tt.elapsed_ms();
|
||||||
let bubble_properties = VisualProperties {
|
let bubble_properties = VisualProperties {
|
||||||
canvas,
|
canvas,
|
||||||
screensize,
|
total_screensize: screensize,
|
||||||
|
layout_screensize: Point::new(screensize.x, screensize.y - status_height as i16),
|
||||||
status_height,
|
status_height,
|
||||||
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),
|
||||||
|
|
@ -177,9 +182,9 @@ impl Ui {
|
||||||
tt,
|
tt,
|
||||||
status_tv,
|
status_tv,
|
||||||
status_last_update_ms,
|
status_last_update_ms,
|
||||||
post_selected: None,
|
layout_selected: None,
|
||||||
post_anchor: None,
|
layout_range: Vec::new(),
|
||||||
post_topdown: false,
|
layout_topdown: false,
|
||||||
vp: bubble_properties,
|
vp: bubble_properties,
|
||||||
menu_mode: true,
|
menu_mode: true,
|
||||||
app_menu: app_menu.to_owned(),
|
app_menu: app_menu.to_owned(),
|
||||||
|
|
@ -212,9 +217,9 @@ impl Ui {
|
||||||
{
|
{
|
||||||
Ok(dialogue) => {
|
Ok(dialogue) => {
|
||||||
// show most recent posts onscreen
|
// show most recent posts onscreen
|
||||||
self.post_selected = dialogue.post_last();
|
self.layout_selected = dialogue.post_last();
|
||||||
self.post_anchor = self.post_selected;
|
self.layout_range.clear();
|
||||||
self.post_topdown = false;
|
self.layout_topdown = false;
|
||||||
Some(dialogue)
|
Some(dialogue)
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
@ -464,11 +469,11 @@ impl Ui {
|
||||||
///
|
///
|
||||||
/// * `index` - POST_SELECT_NEXT or POST_SELECT_PREV or an arbitraty index
|
/// * `index` - POST_SELECT_NEXT or POST_SELECT_PREV or an arbitraty index
|
||||||
pub fn post_select(&mut self, index: usize) {
|
pub fn post_select(&mut self, index: usize) {
|
||||||
self.post_selected = match &self.dialogue {
|
self.layout_selected = match &self.dialogue {
|
||||||
Some(dialogue) => {
|
Some(dialogue) => {
|
||||||
match dialogue.post_last() {
|
match dialogue.post_last() {
|
||||||
Some(last_post) => {
|
Some(last_post) => {
|
||||||
match (index, self.post_selected) {
|
match (index, self.layout_selected) {
|
||||||
(POST_SELECTED_NEXT, Some(selected)) => {
|
(POST_SELECTED_NEXT, Some(selected)) => {
|
||||||
if selected >= last_post {
|
if selected >= last_post {
|
||||||
self.event(Event::Bottom);
|
self.event(Event::Bottom);
|
||||||
|
|
@ -525,52 +530,15 @@ impl Ui {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return a TextView bubble representing a Dialogue Post
|
/// Clear the screen area, not including the status bar
|
||||||
///
|
///
|
||||||
/// # Arguments
|
|
||||||
///
|
|
||||||
/// * `post` - the post to represent in a TextView bubble
|
|
||||||
/// * `dialogue` - containing the Post for context info
|
|
||||||
/// * `hilite` - hilite this Post on the screen (thicker border)
|
|
||||||
/// * `anchor_y` - the vertical position on screen to draw TextView bubble
|
|
||||||
///
|
|
||||||
fn bubble(&self, post: &Post, dialogue: &Dialogue, hilite: bool, anchor_y: i16) -> TextView {
|
|
||||||
// create a textview with all of our default properties
|
|
||||||
let mut bubble_tv = default_textview(post, hilite, &self.vp);
|
|
||||||
|
|
||||||
// set alignment of bubble left/right
|
|
||||||
let mut align_right = false;
|
|
||||||
let mut anchor_x = self.vp.margin.x; // default to align left
|
|
||||||
if let Some(author) = dialogue.author(post.author_id()) {
|
|
||||||
if author.flag_is(AuthorFlag::Right) {
|
|
||||||
// align right
|
|
||||||
align_right = true;
|
|
||||||
anchor_x = self.vp.screensize.x - self.vp.margin.x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// set the text bounds of the bubble and the growth direction
|
|
||||||
let anchor = Point::new(anchor_x, anchor_y);
|
|
||||||
let width = self.vp.bubble_width;
|
|
||||||
let text_bounds = match (self.post_topdown, align_right) {
|
|
||||||
(true, true) => TextBounds::GrowableFromTr(anchor, width),
|
|
||||||
(true, false) => TextBounds::GrowableFromTl(anchor, width),
|
|
||||||
(false, true) => TextBounds::GrowableFromBr(anchor, width),
|
|
||||||
(false, false) => TextBounds::GrowableFromBl(anchor, width),
|
|
||||||
};
|
|
||||||
|
|
||||||
bubble_tv.bounds_hint = text_bounds;
|
|
||||||
bubble_tv
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear the screen area
|
|
||||||
//
|
|
||||||
fn clear_area(&self) {
|
fn clear_area(&self) {
|
||||||
self.gam
|
self.gam
|
||||||
.draw_rectangle(
|
.draw_rectangle(
|
||||||
self.vp.canvas,
|
self.vp.canvas,
|
||||||
Rectangle::new_with_style(
|
Rectangle::new_with_style(
|
||||||
Point::new(0, self.vp.status_height as i16),
|
Point::new(0, self.vp.status_height as i16),
|
||||||
self.vp.screensize,
|
self.vp.total_screensize,
|
||||||
DrawStyle {
|
DrawStyle {
|
||||||
fill_color: Some(PixelColor::Light),
|
fill_color: Some(PixelColor::Light),
|
||||||
stroke_color: None,
|
stroke_color: None,
|
||||||
|
|
@ -604,10 +572,7 @@ impl Ui {
|
||||||
///
|
///
|
||||||
pub(crate) fn redraw(&mut self) -> Result<(), xous::Error> {
|
pub(crate) fn redraw(&mut self) -> Result<(), xous::Error> {
|
||||||
if self.dialogue.is_some() {
|
if self.dialogue.is_some() {
|
||||||
let mut attempt = 0;
|
self.layout().expect("layout failed to execute");
|
||||||
while !self.layout().unwrap_or(true) && attempt < 3 {
|
|
||||||
attempt += 1;
|
|
||||||
}
|
|
||||||
self.status_last_update_ms = self.tt.elapsed_ms();
|
self.status_last_update_ms = self.tt.elapsed_ms();
|
||||||
} else {
|
} else {
|
||||||
self.clear_area(); // no dialogue so clear screen
|
self.clear_area(); // no dialogue so clear screen
|
||||||
|
|
@ -699,110 +664,170 @@ impl Ui {
|
||||||
///
|
///
|
||||||
/// Error if there if Dialogue is None
|
/// Error if there if Dialogue is None
|
||||||
///
|
///
|
||||||
fn layout(&mut self) -> Result<bool, Error> {
|
fn layout(&mut self) -> Result<(), Error> {
|
||||||
self.clear_area();
|
if let Some(dialogue) = self.dialogue.as_mut() {
|
||||||
|
log::info!("redrawing dialogue: {}", dialogue.title);
|
||||||
|
|
||||||
|
// 1. Consistency check the layout range versus selected post.
|
||||||
|
let search_required = if let Some(selected) = self.layout_selected {
|
||||||
|
!self.layout_range.contains(&selected)
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
};
|
||||||
|
|
||||||
|
// 2. Adjust the displayable range.
|
||||||
|
if search_required {
|
||||||
|
let starting_at = if let Some(selected) = self.layout_selected {
|
||||||
|
if self.layout_range.len() > 0 {
|
||||||
|
self.layout_topdown = selected <= *self.layout_range.iter().min().unwrap_or(&0);
|
||||||
|
selected
|
||||||
|
} else {
|
||||||
|
// if no range is available, go from the bottom up, starting with the selected post
|
||||||
|
self.layout_topdown = false;
|
||||||
|
selected
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// no post selected, always layout from bottom up, starting at the most recent post
|
||||||
|
self.layout_topdown = false;
|
||||||
|
dialogue.post_last().unwrap_or(0)
|
||||||
|
};
|
||||||
|
let mut fwd_iter;
|
||||||
|
let mut rev_iter;
|
||||||
|
let search_window: &mut dyn Iterator<Item = _> = if self.layout_topdown {
|
||||||
|
// search from the selected post to all newer posts, top-to-down
|
||||||
|
fwd_iter = dialogue.posts_as_slice_mut()[starting_at..].iter_mut();
|
||||||
|
&mut fwd_iter
|
||||||
|
} else {
|
||||||
|
// search from oldest post to selected post, bottom-to-top
|
||||||
|
rev_iter = dialogue.posts_as_slice_mut()[..=starting_at].iter_mut().rev();
|
||||||
|
&mut rev_iter
|
||||||
|
};
|
||||||
|
let mut total_height = 0;
|
||||||
|
self.layout_range.clear();
|
||||||
|
for (i, post) in search_window.enumerate() {
|
||||||
|
let next_height = if let Some(bb) = post.bounding_box {
|
||||||
|
bb.height() + self.vp.bubble_space as u32 + self.vp.bubble_margin.y as u32
|
||||||
|
} else {
|
||||||
|
// if the "natural height" has not been computed, do so now.
|
||||||
|
let mut layout_bubble = default_textview(post, false, &self.vp);
|
||||||
|
if self.gam.bounds_compute_textview(&mut layout_bubble).is_ok() {
|
||||||
|
post.bounding_box = layout_bubble.bounds_computed;
|
||||||
|
match layout_bubble.bounds_computed {
|
||||||
|
Some(r) => r.height() + self.vp.bubble_space as u32 + self.vp.bubble_margin.y as u32,
|
||||||
|
None => {
|
||||||
|
log::warn!("Unexpected null bounds in computing textview heights, layout will be incorrect.");
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log::warn!("Unexpected error in computing textview heights, layout will be incorrect.");
|
||||||
|
0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if total_height + next_height > self.vp.layout_screensize.y as u32 {
|
||||||
|
if self.layout_topdown {
|
||||||
|
self.layout_range = (starting_at..starting_at + i).collect();
|
||||||
|
} else {
|
||||||
|
self.layout_range = (starting_at - i..=starting_at).rev().collect();
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
total_height += next_height;
|
||||||
|
}
|
||||||
|
if self.layout_range.len() == 0 {
|
||||||
|
// not enough elements to fill the entire screen. Just select everything from selected
|
||||||
|
// to the last possible message.
|
||||||
|
if self.layout_topdown {
|
||||||
|
self.layout_range = (starting_at..).collect();
|
||||||
|
} else {
|
||||||
|
self.layout_range = (0..=starting_at).rev().collect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert!(self.layout_range.len() > 0, "Layout range should be set at this point.");
|
||||||
|
|
||||||
|
// 3. clear the entire area, and re-draw the status bar
|
||||||
|
self.gam
|
||||||
|
.draw_rectangle(
|
||||||
|
self.vp.canvas,
|
||||||
|
Rectangle::new_with_style(
|
||||||
|
Point::new(0, 0),
|
||||||
|
self.vp.total_screensize,
|
||||||
|
DrawStyle {
|
||||||
|
fill_color: Some(PixelColor::Light),
|
||||||
|
stroke_color: None,
|
||||||
|
stroke_width: 0,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.expect("can't clear canvas area");
|
||||||
self.gam.post_textview(&mut self.status_tv)
|
self.gam.post_textview(&mut self.status_tv)
|
||||||
.expect("couldn't render status bar");
|
.expect("couldn't render status bar");
|
||||||
let status_border = Line::new(
|
let status_border = Line::new(
|
||||||
Point::new(0, self.vp.status_height as i16),
|
Point::new(0, self.vp.status_height as i16),
|
||||||
Point::new(self.vp.screensize.x, self.vp.status_height as i16)
|
Point::new(self.vp.total_screensize.x, self.vp.status_height as i16)
|
||||||
);
|
);
|
||||||
self.gam.draw_line(self.vp.canvas,
|
self.gam.draw_line(self.vp.canvas,
|
||||||
status_border
|
status_border
|
||||||
).expect("couldn't draw status lower border");
|
).expect("couldn't draw status lower border");
|
||||||
|
|
||||||
match (&self.dialogue, &self.post_anchor) {
|
// 4. draw the text bubbles, in the order computed in step 2.
|
||||||
(Some(dialogue), Some(post_anchor)) => {
|
let mut y = if self.layout_topdown {
|
||||||
log::info!("redrawing dialogue: {}", dialogue.title);
|
self.vp.status_height as i16 + self.vp.bubble_margin.y
|
||||||
let mut post_selected_visible = false;
|
} else {
|
||||||
let mut bubble_count = 0;
|
self.vp.status_height as i16 + self.vp.layout_screensize.y - self.vp.bubble_margin.y
|
||||||
|
|
||||||
// initialise the first post index AND the vertical position on the screen
|
|
||||||
let mut post_index = *post_anchor;
|
|
||||||
let mut anchor_y = match self.post_topdown {
|
|
||||||
true => self.vp.status_height as i16 + self.vp.margin.y,
|
|
||||||
false => self.vp.screensize.y - self.vp.margin.y,
|
|
||||||
};
|
};
|
||||||
|
for &post_index in &self.layout_range {
|
||||||
// fill the screen with post bubbles from top-down or bottom-up
|
let post = dialogue.post_get(post_index).expect("should be a valid post at this index");
|
||||||
let mut post_is_fully_visible = true;
|
let highlight = if let Some(selected) = self.layout_selected {
|
||||||
let mut is_selected = false;
|
selected == post_index
|
||||||
while post_is_fully_visible {
|
} else {
|
||||||
log::trace!("redrawing post: {post_index}");
|
false
|
||||||
match (dialogue.post_get(post_index), &self.post_selected) {
|
};
|
||||||
(Some(post), Some(post_selected)) => {
|
let mut bubble_tv = bubble(
|
||||||
is_selected = post_index == *post_selected;
|
&self.vp, self.layout_topdown, post, dialogue, highlight, y);
|
||||||
|
|
||||||
// create a bubble and place on canvas
|
|
||||||
let mut bubble_tv = self.bubble(post, dialogue, is_selected, anchor_y);
|
|
||||||
self.gam
|
self.gam
|
||||||
.post_textview(&mut bubble_tv)
|
.post_textview(&mut bubble_tv)
|
||||||
.expect("couldn't render bubble textview");
|
.expect("couldn't render bubble textview");
|
||||||
bubble_count += 1;
|
// double check the actual bounds against expected bounds
|
||||||
post_is_fully_visible = !bubble_tv.overflow.unwrap_or(true);
|
|
||||||
if post_is_fully_visible {
|
|
||||||
// step to the next post AND the next vertical position on the screen
|
|
||||||
match bubble_tv.bounds_computed {
|
match bubble_tv.bounds_computed {
|
||||||
Some(bounds) => match self.post_topdown {
|
Some(actual_r) => {
|
||||||
true => {
|
let expected_r = post.bounding_box.expect("bb should be computed by now");
|
||||||
if post_index
|
if expected_r.height() != actual_r.height() {
|
||||||
>= dialogue.post_last().unwrap_or(usize::MAX)
|
log::warn!(
|
||||||
{
|
"Height mismatch of drawn versus pre-computed text (expected {}, got {}) for {}",
|
||||||
log::info!("trigger a re-layout from bottom-up");
|
expected_r.height(),
|
||||||
self.post_topdown = false;
|
actual_r.height(),
|
||||||
self.post_anchor = dialogue.post_last();
|
bubble_tv.to_str()
|
||||||
return Ok(false);
|
);
|
||||||
}
|
}
|
||||||
post_index += 1;
|
if self.layout_topdown {
|
||||||
anchor_y += (bounds.br.y - bounds.tl.y)
|
y += actual_r.height() as i16;
|
||||||
+ self.vp.bubble_space
|
|
||||||
+ self.vp.bubble_margin.y;
|
|
||||||
}
|
|
||||||
false => {
|
|
||||||
if post_index == 0 {
|
|
||||||
log::info!("trigger a re-layout from top-down");
|
|
||||||
self.post_topdown = true;
|
|
||||||
self.post_anchor = Some(0);
|
|
||||||
return Ok(false);
|
|
||||||
}
|
|
||||||
post_index -= 1;
|
|
||||||
anchor_y -= (bounds.br.y - bounds.tl.y)
|
|
||||||
+ self.vp.bubble_space
|
|
||||||
+ self.vp.bubble_margin.y;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
log::info!("bubble is offscreen so noop");
|
|
||||||
post_is_fully_visible = false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// check if the selected post is fully visible
|
|
||||||
post_selected_visible = post_selected_visible || is_selected;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
(None, _) => {
|
|
||||||
log::trace!("not enough post bubbles to fill the screen");
|
|
||||||
return Ok(true);
|
|
||||||
}
|
|
||||||
(_, _) => return Ok(true), // get me outa-here
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if post_selected_visible || (bubble_count == 1 && is_selected) {
|
|
||||||
Ok(true)
|
|
||||||
} else {
|
} else {
|
||||||
log::info!("trigger a re-layout with selected post visible");
|
y -= actual_r.height() as i16;
|
||||||
self.post_topdown = self.post_selected >= self.post_anchor;
|
}
|
||||||
self.post_anchor = self.post_selected;
|
// sanity check the computations
|
||||||
Ok(false)
|
if y > self.vp.layout_screensize.y + self.vp.status_height as i16
|
||||||
|
|| y < self.vp.status_height as i16 {
|
||||||
|
log::error!("Computed range of elements sent to layout overflows at index {}", post_index);
|
||||||
|
// stop laying out to avoid text artifacts
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// add y-margin before the next iteration
|
||||||
|
if self.layout_topdown {
|
||||||
|
y += self.vp.bubble_space + self.vp.bubble_margin.y;
|
||||||
|
} else {
|
||||||
|
y -= self.vp.bubble_space + self.vp.bubble_margin.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(Some(_dialogue), None) => {
|
_ => {
|
||||||
log::info!("no posts to display");
|
log::error!("No bounds computed for {}, this is a GAM or typesetter bug!", bubble_tv.to_str());
|
||||||
// TODO show dialogue info as a default?
|
}
|
||||||
Ok(true)
|
}
|
||||||
}
|
}
|
||||||
(None, _) => Err(Error::new(ErrorKind::InvalidData, "missing dialogue")),
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(Error::new(ErrorKind::InvalidData, "missing dialogue"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue