Skip to main content

PdfView

Struct PdfView 

Source
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

Source

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)).

Source

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.)

Source

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.)

Source

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.

Source

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.

Source

pub fn unlock_failed(&self) -> bool

Whether the most recent PdfView::unlock used a wrong password.

Source

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.

Source

pub fn load_error(&self) -> Option<&SharedString>

The terminal read/parse failure shown in place of the viewer, if any.

Source

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.

Source

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.)

Source

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.)

Source

pub fn set_on_create_highlight(&mut self, handler: CreateHighlightFn)

Set the handler invoked when a drag-selection finishes. (markup feature.)

Source

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.)

Source

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.)

Source

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.)

Source

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.)

Source

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.)

Toggle the find bar. On open, extract every page’s text (off-thread, cached) and compute matches; on close, drop them. (search feature.)

Close the find bar and clear matches. (search feature.)

Source

pub fn next_match(&mut self, cx: &mut Context<'_, Self>)

Focus the next match (wrapping) and scroll to it. (search feature.)

Source

pub fn prev_match(&mut self, cx: &mut Context<'_, Self>)

Focus the previous match (wrapping) and scroll to it. (search feature.)

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn zoom_in(&mut self, cx: &mut Context<'_, Self>)

Zoom in one step.

Source

pub fn zoom_out(&mut self, cx: &mut Context<'_, Self>)

Zoom out one step.

Source

pub fn reset_zoom(&mut self, cx: &mut Context<'_, Self>)

Reset zoom to 100%.

Source

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.

Source

pub fn toggle_toc(&mut self, cx: &mut Context<'_, Self>)

Toggle the table-of-contents (outline) panel.

Source

pub fn has_outline(&self) -> bool

Whether the document has an outline (bookmarks) to show.

Source

pub fn next_page(&mut self, cx: &mut Context<'_, Self>)

Go to the next page.

Source

pub fn prev_page(&mut self, cx: &mut Context<'_, Self>)

Go to the previous page.

Trait Implementations§

Source§

impl EventEmitter<PdfEvent> for PdfView

Source§

impl Render for PdfView

Source§

fn render( &mut self, window: &mut Window, cx: &mut Context<'_, Self>, ) -> impl IntoElement

Render this view into an element tree.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more