pub struct PdfView { /* private fields */ }Expand description
Construct with PdfView::new inside cx.new; it loads and measures the file
off-thread. Render the resulting Entity<PdfView> like any child view. Call
release before dropping it (e.g. when its tab closes) to
free the atlas textures gpui won’t free on plain drop.
Implementations§
Source§impl PdfView
impl PdfView
Sourcepub fn new(
path: PathBuf,
style: PdfStyleFn,
quality: PdfQualityFn,
cx: &mut Context<'_, Self>,
) -> Self
pub fn new( path: PathBuf, style: PdfStyleFn, quality: PdfQualityFn, cx: &mut Context<'_, Self>, ) -> Self
Create a viewer for path, kicking off the off-thread read + parse + measure.
style supplies chrome colors and quality the DPI multiplier, both read at
paint time (see PdfStyleFn / PdfQualityFn). Call inside
cx.new(|cx| PdfView::new(path, style, quality, cx)).
Sourcepub fn form_fields(&self) -> &[FormField]
pub fn form_fields(&self) -> &[FormField]
The document’s form fields, as enumerated at load — for a host driving
field-to-field navigation (Tab order is the enumeration order: page,
then document order). (forms feature.)
Sourcepub fn reveal_field(
&mut self,
field: &FormField,
cx: &mut Context<'_, Self>,
) -> Option<Bounds<Pixels>>
pub fn reveal_field( &mut self, field: &FormField, cx: &mut Context<'_, Self>, ) -> Option<Bounds<Pixels>>
Scroll so field’s widget is comfortably on-screen, then return its
fresh window-space bounds — what a host needs to seat an input on a
field reached by Tab rather than by click. None before layout.
(forms feature.)
Sourcepub fn replace_bytes(&mut self, bytes: Vec<u8>, cx: &mut Context<'_, Self>)
pub fn replace_bytes(&mut self, bytes: Vec<u8>, cx: &mut Context<'_, Self>)
Swap in a new version of the document — e.g. after a form-field write rewrote the file — keeping the scroll position, zoom, and view state. Re-parses off-thread; pages re-render as they come back on screen.
Sourcepub fn is_locked(&self) -> bool
pub fn is_locked(&self) -> bool
Whether the PDF is encrypted and awaiting a password — the host should show a
prompt and call PdfView::unlock rather than rendering the viewer.
Sourcepub fn unlock_failed(&self) -> bool
pub fn unlock_failed(&self) -> bool
Whether the most recent PdfView::unlock used a wrong password.
Sourcepub fn unlock(&mut self, password: String, cx: &mut Context<'_, Self>)
pub fn unlock(&mut self, password: String, cx: &mut Context<'_, Self>)
Retry an encrypted PDF (see PdfView::is_locked) with password, reusing
the bytes already read. Success renders the viewer; a wrong password sets
PdfView::unlock_failed and leaves it locked. Emits PdfEvent::LockChanged
either way so a host’s password prompt can react.
Sourcepub fn load_error(&self) -> Option<&SharedString>
pub fn load_error(&self) -> Option<&SharedString>
The terminal read/parse failure shown in place of the viewer, if any.
Sourcepub fn set_on_open_external(&mut self, f: OpenExternalFn)
pub fn set_on_open_external(&mut self, f: OpenExternalFn)
Set the handler behind the failure pane’s “Open in system viewer” button — a graceful hand-off for files hayro can’t parse (unsupported encryption handlers, exotic features). Without one, the pane shows only the error text.
Sourcepub fn set_highlights(
&mut self,
highlights: Vec<Highlight>,
cx: &mut Context<'_, Self>,
)
pub fn set_highlights( &mut self, highlights: Vec<Highlight>, cx: &mut Context<'_, Self>, )
Set the highlights to draw — the host derives these from its own store (e.g.
the markdown blocks that link this PDF). Pages with highlights extract their
text layer lazily as they scroll into view, then each quote is located and
boxed. (markup feature.)
Sourcepub fn set_on_highlight(&mut self, handler: HighlightClickFn)
pub fn set_on_highlight(&mut self, handler: HighlightClickFn)
Set the handler invoked with a highlight’s id when it’s clicked (e.g. to jump
to the source note). (markup feature.)
Sourcepub fn set_on_create_highlight(&mut self, handler: CreateHighlightFn)
pub fn set_on_create_highlight(&mut self, handler: CreateHighlightFn)
Set the handler invoked when a drag-selection finishes. (markup feature.)
Sourcepub fn toggle_select_mode(&mut self, cx: &mut Context<'_, Self>)
pub fn toggle_select_mode(&mut self, cx: &mut Context<'_, Self>)
Toggle “highlight mode”: when on, dragging over text selects it and fires the
create handler instead of doing nothing. (markup feature.)
Sourcepub fn toggle_area_mode(&mut self, cx: &mut Context<'_, Self>)
pub fn toggle_area_mode(&mut self, cx: &mut Context<'_, Self>)
Toggle “area mode”: like highlight mode, but a drag marks a page region
(an image/figure box) instead of selecting text, firing CreateAreaFn
on release. Turning it on turns text-highlight mode’s selection off (they
share the pen state); turning either mode off clears the other.
(markup feature.)
Sourcepub fn set_on_create_area(
&mut self,
f: CreateAreaFn,
_cx: &mut Context<'_, Self>,
)
pub fn set_on_create_area( &mut self, f: CreateAreaFn, _cx: &mut Context<'_, Self>, )
Set the handler invoked when an area (box) drag finishes. (markup feature.)
Sourcepub fn set_highlight_palette(
&mut self,
palette: Vec<(SharedString, Hsla)>,
cx: &mut Context<'_, Self>,
)
pub fn set_highlight_palette( &mut self, palette: Vec<(SharedString, Hsla)>, cx: &mut Context<'_, Self>, )
Set the highlight colors the picker offers, as (label, fill) pairs. The label
is opaque to the viewer — it’s echoed back via CreateHighlightFn so the host
can store it (and map it back to a fill for [set_highlights]). (markup.)
Sourcepub fn reveal_highlight(&mut self, page: usize, cx: &mut Context<'_, Self>)
pub fn reveal_highlight(&mut self, page: usize, cx: &mut Context<'_, Self>)
Jump to a highlight from its note: scroll page into view (bringing its first
highlight near the top when that page’s text is already extracted) and briefly
flash the page’s highlights so the eye finds them. (markup feature.)
Sourcepub fn toggle_search(&mut self, cx: &mut Context<'_, Self>)
pub fn toggle_search(&mut self, cx: &mut Context<'_, Self>)
Toggle the find bar. On open, extract every page’s text (off-thread, cached)
and compute matches; on close, drop them. (search feature.)
Sourcepub fn close_search(&mut self, cx: &mut Context<'_, Self>)
pub fn close_search(&mut self, cx: &mut Context<'_, Self>)
Close the find bar and clear matches. (search feature.)
Sourcepub fn next_match(&mut self, cx: &mut Context<'_, Self>)
pub fn next_match(&mut self, cx: &mut Context<'_, Self>)
Focus the next match (wrapping) and scroll to it. (search feature.)
Sourcepub fn prev_match(&mut self, cx: &mut Context<'_, Self>)
pub fn prev_match(&mut self, cx: &mut Context<'_, Self>)
Focus the previous match (wrapping) and scroll to it. (search feature.)
Sourcepub fn release(&mut self, window: &mut Window, cx: &mut Context<'_, Self>)
pub fn release(&mut self, window: &mut Window, cx: &mut Context<'_, Self>)
Free every rasterized page — CPU pixel buffer (by dropping the Arcs) and
the GPU atlas texture. gpui caches one atlas texture per RenderImage on
paint and only frees it via drop_image; a raw ImageSource::Render is never
auto-evicted, so call this before dropping the view or the textures leak.
Sourcepub fn detach_textures(
&mut self,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn detach_textures( &mut self, window: &mut Window, cx: &mut Context<'_, Self>, )
Free the viewer’s GPU textures but keep its rendered page bitmaps — for a host moving this view to a different window (e.g. a tab drag). The old window’s textures are released now; the kept bitmaps re-upload wherever the view next paints, so its pages appear there immediately, with scroll, zoom, and (for an encrypted file) the unlocked state intact.
Sourcepub fn set_zoom(&mut self, zoom: f32, cx: &mut Context<'_, Self>)
pub fn set_zoom(&mut self, zoom: f32, cx: &mut Context<'_, Self>)
Set the zoom factor (clamped), keeping the current page in view. Visible pages re-render crisp at the new scale; their current bitmaps stay on screen (rescaled) until the fresh ones land, so nothing blanks.
Sourcepub fn fit_width(&mut self, cx: &mut Context<'_, Self>)
pub fn fit_width(&mut self, cx: &mut Context<'_, Self>)
Fit the page column to the viewport width. Sticky: re-fits as the
viewer resizes, until a manual zoom (buttons, ⌘±/⌘0, set_zoom)
takes over. Toggles off if already active.
Sourcepub fn fit_page(&mut self, cx: &mut Context<'_, Self>)
pub fn fit_page(&mut self, cx: &mut Context<'_, Self>)
Fit the whole current page inside the viewport (both axes). Sticky
like fit_width; toggles off if already active.
Sourcepub fn reset_zoom(&mut self, cx: &mut Context<'_, Self>)
pub fn reset_zoom(&mut self, cx: &mut Context<'_, Self>)
Reset zoom to 100%.
Sourcepub fn go_to_page(&mut self, index: usize, cx: &mut Context<'_, Self>)
pub fn go_to_page(&mut self, index: usize, cx: &mut Context<'_, Self>)
Scroll so page index (0-based, clamped) is at the top of the viewport.
Sourcepub fn toggle_toc(&mut self, cx: &mut Context<'_, Self>)
pub fn toggle_toc(&mut self, cx: &mut Context<'_, Self>)
Toggle the table-of-contents (outline) panel.
Sourcepub fn has_outline(&self) -> bool
pub fn has_outline(&self) -> bool
Whether the document has an outline (bookmarks) to show.
Trait Implementations§
impl EventEmitter<PdfEvent> for PdfView
Auto Trait Implementations§
impl !RefUnwindSafe for PdfView
impl !Send for PdfView
impl !Sync for PdfView
impl !UnwindSafe for PdfView
impl Freeze for PdfView
impl Unpin for PdfView
impl UnsafeUnpin for PdfView
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more