Skip to content

Commit

Permalink
Remove msg_area::Line::force_recalculation
Browse files Browse the repository at this point in the history
Invalidate the line layout on every modification, instead of requiring
the caller to do it via `force_recalculation`. Remove
`force_recalculation`.
  • Loading branch information
osa1 committed Sep 23, 2024
1 parent 72f1a5c commit 21423d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
20 changes: 10 additions & 10 deletions crates/libtiny_tui/src/msg_area/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ impl Line {
}
}

fn add_text_inner(&mut self, str: &str) {
/// Add the text to the line. The text can contain IRC formatting characters. The text should
/// not contain other control characters like '\n' or '\r'.
pub(crate) fn add_text(&mut self, str: &str, style: SegStyle) {
self.set_message_style(style);

for format_event in parse_irc_formatting(str) {
match format_event {
IrcFormatEvent::Bold => self.add_attr(termbox_simple::TB_BOLD),
Expand Down Expand Up @@ -157,20 +161,16 @@ impl Line {
}
}
}
}

pub(crate) fn add_text(&mut self, str: &str, style: SegStyle) {
self.set_message_style(style);
self.add_text_inner(str)
self.line_data.set_dirty();
}

/// Add a single character to the line. The character should not be an IRC formatting character
/// or other control characters like '\n' and '\r'.
pub(crate) fn add_char(&mut self, char: char, style: SegStyle) {
self.set_message_style(style);
self.current_seg.string.push(char);
}

pub(crate) fn force_recalculation(&mut self) {
self.line_data.set_dirty()
self.line_data.set_dirty();
}

/// Calculates the number of lines that this line will be.
Expand Down Expand Up @@ -363,7 +363,7 @@ fn align_test() {
67
8
*/
line.add_text_inner("12345678");
line.add_text("12345678", SegStyle::UserMsg);

assert_eq!(line.rendered_height(3), 4);
}
2 changes: 0 additions & 2 deletions crates/libtiny_tui/src/msg_area/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,6 @@ impl MsgArea {
F: Fn(&mut Line),
{
f(&mut self.lines[idx]);
// Line was modified so we need to invalidate its height
self.lines[idx].force_recalculation();
}

pub(crate) fn clear(&mut self) {
Expand Down

0 comments on commit 21423d4

Please sign in to comment.