Skip to main content

Editor

Struct Editor 

Source
pub struct Editor { /* private fields */ }
Expand description

Annotation editor. Owns the document; mutates only .annotations via commands. No callbacks - the host/component layer queries state after commands.

Implementations§

Source§

impl Editor

Source

pub fn create_annotation( &mut self, kind: AnnotationKind, page: PageId, payload: AnnotationPayload, ) -> AnnotationId

Create an annotation. Returns the new id. Stamps created/modified from current_ts + author.

Source

pub fn delete_annotation(&mut self, id: &AnnotationId)

Delete an annotation by id.

Source

pub fn delete_selected(&mut self)

Delete all selected annotations.

Source

pub fn move_annotation(&mut self, id: &AnnotationId, dx: f64, dy: f64)

Move an annotation by (dx, dy).

Source

pub fn resize_annotation(&mut self, id: &AnnotationId, new_rect: Rect)

Resize an annotation to new_rect (rect-based payloads; no-op for Markup/Freehand).

Source

pub fn move_annotation_vertex( &mut self, id: &AnnotationId, index: usize, new_point: (f64, f64), )

Move a single vertex of a point-based Shape annotation (Line/Arrow/ Polygon/PolyLine). index is the vertex position in payload.points; new_point is page-local. Rect/Ellipse and non-Shape payloads are a no-op (no history entry). Spec §4.2: vertex drag.

Source§

impl Editor

Source

pub fn set_annotation_color( &mut self, id: &AnnotationId, range: Option<(usize, usize)>, color: Color, )

Set the primary color. For a TextBox, range scopes the change to the selected chars (see spans_apply); other payload kinds ignore it.

Source

pub fn set_annotation_width(&mut self, id: &AnnotationId, width: f64)

Set the stroke width (Freehand/Shape).

Source

pub fn set_annotation_font_size_measured<F>( &mut self, id: &AnnotationId, range: Option<(usize, usize)>, size_mm: f64, measure: F, )

Set the font size (millimetres) of a TextBox in ONE transaction. range scopes the change to the selected chars (see spans_apply). measure follows the Self::insert_text_measured contract and is applied inside the same transaction (grow-only callers pass None when the box does not need to grow).

Source

pub fn set_annotation_font_family_measured<F>( &mut self, id: &AnnotationId, range: Option<(usize, usize)>, family: &str, measure: F, )

Set the font family of a TextBox (font = FontId::new(family)) in ONE transaction. range scopes the change to the selected chars.

Source

pub fn insert_text(&mut self, id: &AnnotationId, offset: usize, chars: &str)

Insert text into a text annotation (TextBox/Note/Watermark) at char offset.

Source

pub fn insert_text_measured<F>( &mut self, id: &AnnotationId, offset: usize, chars: &str, measure: F, )

Insert text and let measure suggest a new annotation height. The closure sees the post-edit payload, so the component can shape the exact text with its font store; a Some(h) is applied in the SAME transaction (one undo restores text + height). measure must return Some only when growth is needed.

Source

pub fn replace_text_measured<F>( &mut self, id: &AnnotationId, start: usize, end: usize, chars: &str, measure: F, )

Replace the char range [start, end) with chars in ONE transaction. Typing / Backspace / Delete / Enter / paste / IME commit over an active text selection all route here, so the edit is a single undo step. measure follows the same contract as Self::insert_text_measured.

Source

pub fn delete_text(&mut self, id: &AnnotationId, offset: usize, len: usize)

Delete len chars from a text annotation at char offset.

Source

pub fn delete_text_measured<F>( &mut self, id: &AnnotationId, offset: usize, len: usize, measure: F, )

Delete text and let measure suggest a new annotation height (same contract as Self::insert_text_measured).

Source

pub fn set_annotation_text(&mut self, id: &AnnotationId, text: &str)

Replace the whole text content. The old span styles do not map onto the new text, so they are dropped (the box falls back to its flat style).

Source

pub fn reply_to(&mut self, parent: &AnnotationId, content: &str) -> AnnotationId

Reply to an annotation (creates a Note with reply_to set).

Source§

impl Editor

Source

pub fn new() -> Self

Source

pub fn load_document(&mut self, doc: OfdDocument)

Source

pub fn revise_document<T>( &mut self, revise: impl FnOnce(&mut OfdDocument) -> T, ) -> T

A change to the document that is neither an annotation command nor another document (spec 2026-11-23 §17.11): a signature appended to the package it carries. revise gets the document, and what it returns is returned. The selection, the text cursor and the history are not touched, and no page is invalidated - call Self::invalidate_pages when the content of the pages changed (a seal is page content).

Source

pub fn invalidate_pages(&mut self)

The content of the pages changed: every cached page is stale. The page scenes and the CPU fallback’s page bitmaps key on the body revision.

Source

pub fn set_clock(&mut self, author: String, ts: i64)

Caller-supplied author + timestamp. The library never reads a system clock.

Source

pub fn document(&self) -> &OfdDocument

Source

pub fn selection(&self) -> &AnnotationSelection

Source

pub fn text_cursor(&self) -> Option<&TextCursor>

Source

pub fn can_undo(&self) -> bool

Source

pub fn can_redo(&self) -> bool

Source

pub fn history_len(&self) -> usize

Number of undoable transactions on the history stack. Mainly for testing (e.g. asserting a drag pushes exactly one Transaction).

Source

pub fn select(&mut self, id: AnnotationId)

Select a single annotation by id.

Source

pub fn set_selection(&mut self, sel: AnnotationSelection)

Replace the current selection wholesale.

Source

pub fn clear_selection(&mut self)

Clear the selection.

Source

pub fn set_cursor(&mut self, annotation: AnnotationId, offset: usize)

Position the text cursor at offset within annotation.

Source

pub fn set_cursor_with_preferred_x( &mut self, annotation: AnnotationId, offset: usize, preferred_x: Option<f32>, )

Position the text cursor and keep a preferred column x (vertical caret movement across visual lines). None clears the preference.

Source

pub fn clear_cursor(&mut self)

Clear the text cursor.

Source

pub fn undo(&mut self) -> bool

Source

pub fn redo(&mut self) -> bool

Trait Implementations§

Source§

impl Default for Editor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Editor

§

impl !Sync for Editor

§

impl !UnwindSafe for Editor

§

impl Forget for Editor

§

impl Freeze for Editor

§

impl Move for Editor

§

impl Send for Editor
where RawVecInner: Send, RawTable<(FontId, FontRef)>: Send, RawTable<(ImageId, Arc<Vec<u8>>)>: Send, RawTable<(FontId, Arc<Vec<u8>>)>: Send, RawTable<(DrawParamId, DrawParam)>: Send, RawTable<(PageId, Vec<Annotation>)>: Send, Arc<Vec<u8>>: Send, NodeRef<Owned, String, SetValZST, LeafOrInternal>: Send, BoxRaw<(String, SetValZST)>: Send, BoxRaw<dyn Step>: Send,

§

impl Unpin for Editor
where *const u8 is !null: Unpin, Arc<Vec<u8>>: Unpin, *const LeafNode<String, SetValZST> is !null: Unpin, Box<(String, SetValZST)>: Unpin, Box<dyn Step>: Unpin,

§

impl UnsafeUnpin for Editor

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.