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
impl Editor
Sourcepub fn create_annotation(
&mut self,
kind: AnnotationKind,
page: PageId,
payload: AnnotationPayload,
) -> AnnotationId
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.
Sourcepub fn delete_annotation(&mut self, id: &AnnotationId)
pub fn delete_annotation(&mut self, id: &AnnotationId)
Delete an annotation by id.
Sourcepub fn delete_selected(&mut self)
pub fn delete_selected(&mut self)
Delete all selected annotations.
Sourcepub fn move_annotation(&mut self, id: &AnnotationId, dx: f64, dy: f64)
pub fn move_annotation(&mut self, id: &AnnotationId, dx: f64, dy: f64)
Move an annotation by (dx, dy).
Sourcepub fn resize_annotation(&mut self, id: &AnnotationId, new_rect: Rect)
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).
Sourcepub fn move_annotation_vertex(
&mut self,
id: &AnnotationId,
index: usize,
new_point: (f64, f64),
)
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
impl Editor
Sourcepub fn set_annotation_color(
&mut self,
id: &AnnotationId,
range: Option<(usize, usize)>,
color: Color,
)
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.
Sourcepub fn set_annotation_width(&mut self, id: &AnnotationId, width: f64)
pub fn set_annotation_width(&mut self, id: &AnnotationId, width: f64)
Set the stroke width (Freehand/Shape).
Sourcepub fn set_annotation_font_size_measured<F>(
&mut self,
id: &AnnotationId,
range: Option<(usize, usize)>,
size_mm: f64,
measure: F,
)
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).
Sourcepub fn set_annotation_font_family_measured<F>(
&mut self,
id: &AnnotationId,
range: Option<(usize, usize)>,
family: &str,
measure: F,
)
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.
Sourcepub fn insert_text(&mut self, id: &AnnotationId, offset: usize, chars: &str)
pub fn insert_text(&mut self, id: &AnnotationId, offset: usize, chars: &str)
Insert text into a text annotation (TextBox/Note/Watermark) at char offset.
Sourcepub fn insert_text_measured<F>(
&mut self,
id: &AnnotationId,
offset: usize,
chars: &str,
measure: F,
)
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.
Sourcepub fn replace_text_measured<F>(
&mut self,
id: &AnnotationId,
start: usize,
end: usize,
chars: &str,
measure: F,
)
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.
Sourcepub fn delete_text(&mut self, id: &AnnotationId, offset: usize, len: usize)
pub fn delete_text(&mut self, id: &AnnotationId, offset: usize, len: usize)
Delete len chars from a text annotation at char offset.
Sourcepub fn delete_text_measured<F>(
&mut self,
id: &AnnotationId,
offset: usize,
len: usize,
measure: F,
)
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).
Sourcepub fn set_annotation_text(&mut self, id: &AnnotationId, text: &str)
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).
Sourcepub fn reply_to(&mut self, parent: &AnnotationId, content: &str) -> AnnotationId
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
impl Editor
pub fn new() -> Self
pub fn load_document(&mut self, doc: OfdDocument)
Sourcepub fn revise_document<T>(
&mut self,
revise: impl FnOnce(&mut OfdDocument) -> T,
) -> T
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).
Sourcepub fn invalidate_pages(&mut self)
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.
Sourcepub fn set_clock(&mut self, author: String, ts: i64)
pub fn set_clock(&mut self, author: String, ts: i64)
Caller-supplied author + timestamp. The library never reads a system clock.
pub fn document(&self) -> &OfdDocument
pub fn selection(&self) -> &AnnotationSelection
pub fn text_cursor(&self) -> Option<&TextCursor>
pub fn can_undo(&self) -> bool
pub fn can_redo(&self) -> bool
Sourcepub fn history_len(&self) -> usize
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).
Sourcepub fn select(&mut self, id: AnnotationId)
pub fn select(&mut self, id: AnnotationId)
Select a single annotation by id.
Sourcepub fn set_selection(&mut self, sel: AnnotationSelection)
pub fn set_selection(&mut self, sel: AnnotationSelection)
Replace the current selection wholesale.
Sourcepub fn clear_selection(&mut self)
pub fn clear_selection(&mut self)
Clear the selection.
Sourcepub fn set_cursor(&mut self, annotation: AnnotationId, offset: usize)
pub fn set_cursor(&mut self, annotation: AnnotationId, offset: usize)
Position the text cursor at offset within annotation.
Sourcepub fn set_cursor_with_preferred_x(
&mut self,
annotation: AnnotationId,
offset: usize,
preferred_x: Option<f32>,
)
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.
Sourcepub fn clear_cursor(&mut self)
pub fn clear_cursor(&mut self)
Clear the text cursor.