Render the text input content into the given inner area (no block/border). Sets cursor position on frame. Pass `show_cursor = false` to skip cursor.
(
&mut self,
frame: &mut Frame,
inner: Rect,
style: &TextInputStyle,
show_cursor: bool,
)
| 357 | /// Render the text input content into the given inner area (no block/border). |
| 358 | /// Sets cursor position on frame. Pass `show_cursor = false` to skip cursor. |
| 359 | pub fn render( |
| 360 | &mut self, |
| 361 | frame: &mut Frame, |
| 362 | inner: Rect, |
| 363 | style: &TextInputStyle, |
| 364 | show_cursor: bool, |
| 365 | ) { |
| 366 | let visible_lines = inner.height as usize; |
| 367 | |
| 368 | if self.input.is_empty() { |
| 369 | let line = Line::from(vec![ |
| 370 | Span::raw(style.first_line_prefix.to_string()), |
| 371 | Span::styled(style.placeholder.clone(), style.placeholder_style), |
| 372 | ]); |
| 373 | let paragraph = Paragraph::new(line); |
| 374 | frame.render_widget(paragraph, inner); |
| 375 | if show_cursor { |
| 376 | let prefix_w = style.first_line_prefix.width() as u16; |
| 377 | frame.set_cursor_position((inner.x + prefix_w, inner.y)); |
| 378 | } |
| 379 | return; |
| 380 | } |
| 381 | |
| 382 | let prefix_w = style.prefix_display_width(); |
| 383 | self.ensure_cursor_visible(inner.width, prefix_w, visible_lines); |
| 384 | |
| 385 | let visual_lines = self.build_visual_lines(inner.width, style); |
| 386 | let scroll = self.scroll_offset; |
| 387 | let visible_slice: Vec<Line<'static>> = visual_lines |
| 388 | .into_iter() |
| 389 | .skip(scroll) |
| 390 | .take(visible_lines) |
| 391 | .collect(); |
| 392 | |
| 393 | let paragraph = Paragraph::new(visible_slice); |
| 394 | frame.render_widget(paragraph, inner); |
| 395 | |
| 396 | if show_cursor { |
| 397 | let (cursor_vrow, cursor_vcol) = self.cursor_visual_position(inner.width, prefix_w); |
| 398 | let row_in_view = cursor_vrow.saturating_sub(scroll); |
| 399 | if row_in_view < visible_lines { |
| 400 | frame.set_cursor_position(( |
| 401 | inner.x + cursor_vcol as u16, |
| 402 | inner.y + row_in_view as u16, |
| 403 | )); |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | } |
nothing calls this directly
no test coverage detected