Update scroll offset to ensure cursor is visible within `visible_width`. `cursor_x` is the pixel x-position of the cursor relative to text start.
(&mut self, cursor_x: f32, visible_width: f32)
| 365 | /// Update scroll offset to ensure cursor is visible within `visible_width`. |
| 366 | /// `cursor_x` is the pixel x-position of the cursor relative to text start. |
| 367 | pub fn ensure_cursor_visible(&mut self, cursor_x: f32, visible_width: f32) { |
| 368 | if cursor_x - self.scroll_offset > visible_width { |
| 369 | self.scroll_offset = cursor_x - visible_width; |
| 370 | } |
| 371 | if cursor_x - self.scroll_offset < 0.0 { |
| 372 | self.scroll_offset = cursor_x; |
| 373 | } |
| 374 | // Clamp scroll_offset to valid range |
| 375 | if self.scroll_offset < 0.0 { |
| 376 | self.scroll_offset = 0.0; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | /// Update vertical scroll offset to keep cursor visible in multiline mode. |
| 381 | /// `cursor_line` is the 0-based line index the cursor is on. |
no outgoing calls