pub struct EditorViewport {
pub bounds: Rect,
pub content_rect: Rect,
pub text_rect: Rect,
pub gutter_rect: Option<Rect>,
pub scroll_x: f32,
pub scroll_y: f32,
pub wrap_mode: EditorWrapMode,
}Expand description
Current editor viewport in widget/screen coordinates.
All geometry and scroll values are logical pixels. Soft wrap forces horizontal scroll to zero; vertical scroll is clamped non-negative.
§Examples
use ailloli_ui_core::Rect;
use ailloli_ui_editor::{EditorConfig, EditorViewport};
use ailloli_ui_text::TextEditState;
let viewport = EditorViewport::new(Rect::new(0.0, 0.0, 100.0, 60.0), EditorConfig::default(), &TextEditState::new());
assert_eq!(viewport.content_rect, Rect::new(10.0, 10.0, 80.0, 40.0));
assert!(viewport.gutter_rect.is_none());Fields§
§bounds: RectComplete widget bounds.
content_rect: RectBounds after editor padding, before optional gutter split.
text_rect: RectText clip/layout viewport after optional gutter allocation.
gutter_rect: Option<Rect>Optional left gutter, or None when disabled/non-positive.
scroll_x: f32Non-negative horizontal text offset; always zero under soft wrap.
scroll_y: f32Non-negative vertical content offset.
wrap_mode: EditorWrapModeWrap policy used to derive width and scrolling behavior.
Implementations§
Source§impl EditorViewport
Viewport construction and coordinate conversion operations.
impl EditorViewport
Viewport construction and coordinate conversion operations.
Sourcepub fn new(bounds: Rect, config: EditorConfig, edit: &TextEditState) -> Self
pub fn new(bounds: Rect, config: EditorConfig, edit: &TextEditState) -> Self
Resolves a viewport without a gutter.
§Examples
use ailloli_ui_core::Rect;
use ailloli_ui_editor::{EditorConfig, EditorViewport};
use ailloli_ui_text::TextEditState;
let viewport = EditorViewport::new(Rect::new(0.0, 0.0, 50.0, 50.0), EditorConfig::default(), &TextEditState::new());
assert_eq!(viewport.text_rect, viewport.content_rect);Sourcepub fn with_gutter(
bounds: Rect,
config: EditorConfig,
edit: &TextEditState,
gutter: Option<GutterConfig>,
) -> Self
pub fn with_gutter( bounds: Rect, config: EditorConfig, edit: &TextEditState, gutter: Option<GutterConfig>, ) -> Self
Resolves padding, optional left gutter, and clamped scroll offsets.
An enabled gutter with positive width is clamped to content width; zero,
negative, or disabled gutter values behave as None.
§Examples
use ailloli_ui_core::Rect;
use ailloli_ui_editor::{CodeEditorConfig, EditorConfig, EditorViewport};
use ailloli_ui_text::TextEditState;
let gutter = CodeEditorConfig::default().gutter;
let viewport = EditorViewport::with_gutter(Rect::new(0.0, 0.0, 120.0, 60.0), EditorConfig::default(), &TextEditState::new(), Some(gutter));
assert!(viewport.gutter_rect.is_some());
assert_eq!(viewport.gutter_rect.unwrap().w, gutter.width);Sourcepub fn text_origin_x(self) -> f32
pub fn text_origin_x(self) -> f32
Returns the unscrolled text origin minus horizontal scroll.
§Examples
use ailloli_ui_core::Rect;
use ailloli_ui_editor::{EditorConfig, EditorViewport};
use ailloli_ui_text::TextEditState;
let viewport = EditorViewport::new(Rect::new(0.0, 0.0, 80.0, 40.0), EditorConfig::default(), &TextEditState::new());
assert_eq!(viewport.text_origin_x(), 10.0);Sourcepub fn text_origin_y(self) -> f32
pub fn text_origin_y(self) -> f32
Returns the fixed top of the text viewport in logical pixels.
Vertical scroll is applied per run, not to this origin.
§Examples
use ailloli_ui_core::Rect;
use ailloli_ui_editor::{EditorConfig, EditorViewport};
use ailloli_ui_text::TextEditState;
let viewport = EditorViewport::new(Rect::new(0.0, 0.0, 80.0, 40.0), EditorConfig::default(), &TextEditState::new());
assert_eq!(viewport.text_origin_y(), 10.0);Sourcepub fn text_wrap_mode(self) -> WrapMode
pub fn text_wrap_mode(self) -> WrapMode
Maps editor wrapping to the text engine’s concrete wrap mode.
§Examples
use ailloli_ui_core::Rect;
use ailloli_ui_editor::{EditorConfig, EditorViewport};
use ailloli_ui_text::{TextEditState, WrapMode};
let viewport = EditorViewport::new(Rect::new(0.0, 0.0, 80.0, 40.0), EditorConfig::default(), &TextEditState::new());
assert_eq!(viewport.text_wrap_mode(), WrapMode::WordOrAnywhere);Sourcepub fn max_text_width(self) -> Option<f32>
pub fn max_text_width(self) -> Option<f32>
Returns the text viewport width for soft wrap, or None for no wrap.
§Examples
use ailloli_ui_core::Rect;
use ailloli_ui_editor::{EditorConfig, EditorViewport};
use ailloli_ui_text::TextEditState;
let viewport = EditorViewport::new(Rect::new(0.0, 0.0, 80.0, 40.0), EditorConfig::default(), &TextEditState::new());
assert_eq!(viewport.max_text_width(), Some(60.0));Sourcepub fn local_point(self, pos: Point) -> (f32, f32)
pub fn local_point(self, pos: Point) -> (f32, f32)
Converts a screen point into scrolled text-local coordinates.
The x result is clamped at zero; y may be negative above the text rect.
§Examples
use ailloli_ui_core::{Point, Rect};
use ailloli_ui_editor::{EditorConfig, EditorViewport};
use ailloli_ui_text::TextEditState;
let viewport = EditorViewport::new(Rect::new(0.0, 0.0, 80.0, 40.0), EditorConfig::default(), &TextEditState::new());
assert_eq!(viewport.local_point(Point::new(15.0, 17.0)), (5.0, 7.0));Trait Implementations§
Source§impl Clone for EditorViewport
impl Clone for EditorViewport
Source§fn clone(&self) -> EditorViewport
fn clone(&self) -> EditorViewport
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more