Struct EditorViewport

Source
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: Rect

Complete widget bounds.

§content_rect: Rect

Bounds after editor padding, before optional gutter split.

§text_rect: Rect

Text clip/layout viewport after optional gutter allocation.

§gutter_rect: Option<Rect>

Optional left gutter, or None when disabled/non-positive.

§scroll_x: f32

Non-negative horizontal text offset; always zero under soft wrap.

§scroll_y: f32

Non-negative vertical content offset.

§wrap_mode: EditorWrapMode

Wrap policy used to derive width and scrolling behavior.

Implementations§

Source§

impl EditorViewport

Viewport construction and coordinate conversion operations.

Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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));
Source

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

Source§

fn clone(&self) -> EditorViewport

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EditorViewport

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for EditorViewport

Source§

fn eq(&self, other: &EditorViewport) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for EditorViewport

Source§

impl StructuralPartialEq for EditorViewport

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> ErasedDestructor for T
where T: 'static,