Skip to main content

Module viewer

Module viewer 

Source
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 html feature 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 the video feature, a local video file plays here (see video); with the webview feature, on Linux, a YouTube link plays here in a web view (see embed); other remote video stays outside. docs: pages come from the Docs the application ships (include_str!), on native and on the web build alike; remote pages and images come through a Fetch the 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 (#install scrolls to the heading), links in a page opened through the links service (a link to another docs: 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 host are not loaded” with a button loading them; the host is remembered in the viewer.image_hosts setting (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: its file: images show their alt text and are named on the page and in viewer.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.state and the viewer collector (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 .md or .html (docs:guide/start), a folder its index.md or index.html (docs:guide/, and docs: alone the root’s).
EmbedRequest
What a backend is asked to open.
ImageRef
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.
ViewerPlugin
The viewer as a plugin (opt-in): the panel, the service, the links service’s way inside, the commands, the setting and the viewer collector.

Enums§

Content
What a page shows.
Failure
Why a page is not shown.
Status
Where the viewer is.

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_REFERRERDeprecated
The Referer the 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 the videos collector.
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§

EmbedBackend
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 fetch on the web build). done may 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 physical pixels meets YouTube’s minimum (MIN_PLAYER each way). native_pixels_per_point is 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 Referer naming the application of id app_id (org.example.App), as YouTube asks of an application: an https URL 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: a docs: page gives a docs: 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.