MCPcopy Create free account
hub / github.com/TheRedDeveloper/ply-engine / ensure_cursor_visible

Method ensure_cursor_visible

src/text_input.rs:367–378  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 2

Calls

no outgoing calls

Tested by 1