Enhance TUI scrolling: add viewport dimension tracking, autoscroll logic, and message line calculation. Refactor related components for dynamic rendering.
This commit is contained in:
@@ -10,7 +10,7 @@ use unicode_width::UnicodeWidthStr;
|
||||
use crate::chat_app::{ChatApp, InputMode};
|
||||
use owlen_core::types::Role;
|
||||
|
||||
pub fn render_chat(frame: &mut Frame<'_>, app: &ChatApp) {
|
||||
pub fn render_chat(frame: &mut Frame<'_>, app: &mut ChatApp) {
|
||||
// Calculate dynamic input height based on textarea content
|
||||
let available_width = frame.area().width;
|
||||
let input_height = if matches!(app.mode(), InputMode::Editing) {
|
||||
@@ -345,12 +345,16 @@ fn render_header(frame: &mut Frame<'_>, area: Rect, app: &ChatApp) {
|
||||
frame.render_widget(paragraph, inner_area);
|
||||
}
|
||||
|
||||
fn render_messages(frame: &mut Frame<'_>, area: Rect, app: &ChatApp) {
|
||||
fn render_messages(frame: &mut Frame<'_>, area: Rect, app: &mut ChatApp) {
|
||||
// Calculate viewport dimensions for autoscroll calculations
|
||||
let viewport_height = area.height.saturating_sub(2) as usize; // subtract borders
|
||||
let content_width = area.width.saturating_sub(4).max(20);
|
||||
app.set_viewport_dimensions(viewport_height, usize::from(content_width));
|
||||
|
||||
let conversation = app.conversation();
|
||||
let mut formatter = app.formatter().clone();
|
||||
|
||||
// Reserve space for borders and the message indent so text fits within the block
|
||||
let content_width = area.width.saturating_sub(4).max(20);
|
||||
formatter.set_wrap_width(usize::from(content_width));
|
||||
|
||||
let mut lines: Vec<Line> = Vec::new();
|
||||
|
||||
Reference in New Issue
Block a user