Expand description
The in-app viewer (ADR 0017): a panel showing one page at a time, the
links service’s way inside. Feature markdown.
Experimental: may change in any release
(docs/stability.md).
ViewerPlugin (opt-in) declares a panel in the end side bar
(detachable into its own window, like any panel) and installs itself
as the links service’s Inside: docs: pages, markdown pages on
the application’s documentation hosts and local images then open
here, through the same policy and the same link.open step as every
other link.
- Pages: markdown (rendered by egui_commonmark), images (egui’s
loaders, PNG, JPEG and GIF), plain text, and with the
htmlfeature a safe subset of HTML, mapped to the same blocks as markdown: no scripts, styles, forms, frames or video, which are named on the page and left to Open outside (without the feature, an HTML page gets an error page offering Open outside). With thevideofeature, a local video file plays here (seevideo); with thewebviewfeature, on Linux, a YouTube link plays here in a web view (seeembed); other remote video stays outside.docs:pages come from theDocsthe application ships (include_str!), on native and on the web build alike; remote pages and images come through aFetchthe host gives (none by default: the viewer then opens nothing remote and says so). - Navigation: back and forward (the session’s history, nothing
kept across runs), reload, an address bar (typing a target opens it
through the links service), anchors (
#installscrolls to the heading), links in a page opened through the links service (a link to anotherdocs:page stays inside, a web link goes outside; Ctrl+click or a middle click opens outside). - Find in page (Ctrl+F, F3, Shift+F3, Enter and Shift+Enter in its field): the matches counted in the page’s text, the block holding the current one marked and scrolled to.
- Zoom (Ctrl+plus, Ctrl+minus, Ctrl+0 while the viewer has the focus): the page’s text only, in steps.
- Remote images are never fetched before the user asks: each is
replaced by its alt text, and a bar says “Images from
hostare not loaded” with a button loading them; the host is remembered in theviewer.image_hostssetting (cleared there). Images on the page’s own host (a documentation host the application declares) load at once. A page from the network never loads a local file: itsfile:images show their alt text and are named on the page and inviewer.state. - Failures show an error page in place (not found, no connection, too large, a type it cannot show, an HTML page nested too deep to parse) with Retry, Open outside and Copy link.
- Agents read the viewer through
viewer.stateand theviewercollector (the page, its status or error, the history, the search, the zoom, the images waiting and the hosts allowed) and drive it with its commands; loading a host’s images is the user’s alone.
use egui_pop_api::links::{self, LinksPlugin, Request};
use egui_pop_api::App;
use egui_pop_views::viewer::{Docs, ViewerPlugin, VIEWER};
let docs = Docs::new()
.page("index", "# Help\n\nSee [the guide](guide.md).")
.page("guide", "# Guide\n\n## Install\n\nRun it.");
let app = App::builder()
.plugin(LinksPlugin::default())
.plugin(ViewerPlugin::default().docs(docs))
.build(&egui::Context::default())
.unwrap();
links::open(app.handle(), Request::new("docs:guide#install"));
let viewer = app.handle().service(&VIEWER).unwrap();
assert_eq!(viewer.state()["target"], "docs:guide#install");
assert_eq!(viewer.state()["status"], "shown");Re-exports§
pub use crate::video::SEEK_STEP;pub use crate::video::VOLUME_STEP;pub use crate::video::VideoBackend;pub use crate::video::VideoFrame;pub use crate::video::VideoPlayer;pub use crate::video::VideoRequest;pub use crate::video::VideoState;pub use crate::video::VideoStatus;pub use crate::video::clock;pub use crate::video::rgba_image;
Structs§
- Block
- A top-level block of a page.
- Docs
- The pages and files an application ships for
docs:links, by path (guide/start.md,about.html,img/shot.png). A link names a page with or without its.mdor.html(docs:guide/start), a folder itsindex.mdorindex.html(docs:guide/, anddocs:alone the root’s). - Embed
Request - What a backend is asked to open.
- Image
Ref - An image in a block: where its markdown is, its alt text and its address as written.
- Markdown
- A markdown page.
- Page
- A page shown.
- Placement
- Where a web view goes.
- Viewer
- The viewer: its pages, history, search, zoom and images. Its methods are what its commands and its panel do.
- Viewer
Plugin - The viewer as a plugin (opt-in): the panel, the service, the links
service’s way inside, the commands, the setting and the
viewercollector.
Enums§
Constants§
- CMD_
BACK - CMD_
COPY_ LINK - CMD_
FIND - CMD_
FIND_ NEXT - CMD_
FIND_ PREVIOUS - CMD_
FORWARD - CMD_
LOAD_ IMAGES - CMD_
OPEN_ OUTSIDE - CMD_
RELOAD - CMD_
STATE - CMD_
VIDEO_ AHEAD - CMD_
VIDEO_ BACK - CMD_
VIDEO_ LOUDER - CMD_
VIDEO_ QUIETER - CMD_
VIDEO_ SEEK - CMD_
VIDEO_ TOGGLE - CMD_
VIDEO_ VOLUME - CMD_
ZOOM_ IN - CMD_
ZOOM_ OUT - CMD_
ZOOM_ RESET - DEFAULT_
REFERRER Deprecated - The
Refererthe web view sent before it named the application. - MAX_
BYTES - The largest page or image shown, in bytes.
- MIN_
PLAYER - The smallest side of YouTube’s player, in its own (CSS) pixels: its Required Minimum Functionality asks for a viewport of at least 200 by 200.
- PANEL
- The viewer’s panel.
- PLUGIN
- The plugin’s id.
- PUMP
- How often the web view’s loop is turned while it is open.
- SETTING_
IMAGE_ HOSTS - The hosts whose images the user allowed, separated by commas.
- SURFACE
- The focus surface its keys are bound on (
viewerFocus). - VIDEO_
CONTEXT - The context key saying a video page is shown.
- VIDEO_
ID - The id of the viewer’s video, for the
video.*commands and thevideoscollector. - VIDEO_
SURFACE - The surface the picture’s keys are bound on (
viewerVideoFocus). - VIEWER
- The viewer service.
- WEB_
VIEW_ LISTENER - The viewer’s local listener on
pop.window.close: the web view of that native window is dropped, whoever asked (its page left, its window closing, among others). - WEB_
VIEW_ PREFIX - A web view’s id in the registry:
web-view:<n>. - ZOOM_
STEPS - The page’s zoom steps.
Traits§
- Embed
Backend - What opens web views for the viewer (
ViewerPlugin::web_video). - Embedded
- A web view open. A failure’s text is shown on the error page.
- Fetch
- How the viewer gets a remote page or image, given by the host (an
HTTP client of its choice, a cache, the browser’s
fetchon the web build).donemay be called from any thread, once.
Functions§
- embed_
url - The player’s address for a YouTube video: the privacy-enhanced host, the video starting on its own.
- fits_
player - Whether a player of
physicalpixels meets YouTube’s minimum (MIN_PLAYEReach way).native_pixels_per_pointis the system’s scale: the web view’s pixels are the window’s physical pixels divided by it, so a 2x screen needs 400 physical pixels. Both counts must reach the minimum. - has_
scheme - Whether an address names its scheme (
https:,docs:,mailto:); a Windows drive (C:\\) is not one. - parse_
hosts - The hosts in the setting’s text.
- referrer_
for - The
Referernaming the application of idapp_id(org.example.App), as YouTube asks of an application: anhttpsURL whose domain is the application’s id,https://org.example.app/. None for an empty id or one that cannot be a domain name. - resolve
- A destination resolved against the page it is on: an anchor stays
an anchor (
#x), an address with a scheme is kept, a relative one (guide.md,../img/a.png) joins the page’s folder: adocs:page gives adocs:page, a web or file page joins as the web does. - slug
- A heading’s anchor as hosting sites make it: lower case, letters,
digits,
-and_kept, spaces made-, the rest dropped.
Type Aliases§
- Fetched
- What a fetch gives: the bytes, or why not.