Show HTML content "inside" your egui rendered application

Overview

hframe License CI Crates.io Version

Show HTML content "inside" your egui rendered application. "hframe" stands for "HTML Frame".

Note: hframe only works when the application is compiled to WebAssembly and run in a browser. But you can still make a desktop up by leveraging Tauri.

egui-tauri-template will serve as good foundation if you need to target both platforms.

Simple example

use hframe::Aware;

const IFRAME: &str = r#"
<iframe src="https://www.example.com/"></iframe>
"#;

pub struct App;

impl App {
    pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
        Self
    }
}

impl eframe::App for App {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        egui::Window::new("Egui Rendered Window")
            .show(ctx, |ui| {
                ui.centered_and_justified(|ui| {
                    ui.label("This window can be shown on top of the iframe thanks to `.aware()`");
                });
            })
            .aware();

        hframe::HtmlWindow::new("Iframe Window").content(IFRAME).show(ctx);

        hframe::sync(ctx);
    }
}

For a more complete example see demo's app.rs.

Running the demo

Ensure you have trunk installed with cargo install --locked trunk.

git clone https://github.com/noxware/hframe
cd hframe/examples/demo
trunk serve --open

Screenshot

Screenshot

How does it work?

hframe renders the HTML content on top of the canvas where egui is rendering. Web content is absolute positioned following specifc areas of the canvas. To be abale to show egui windows on top of the HTML content, hframe uses different set of HTML masking/cliping techniques combined with other smart logic to produce the illusion of the HTML content being "inside" the egui rendered application.

This approach has been chosen after many experiments with alternative techniques which were not able to provide the same level of integration and flexibility.

Additionally, some tracking is performed to provide an immediate mode like public API. HTML will only be re-rendered if you change the initially provided content. This can be useful if you want to change the HTML content in a controlled and reactive manner without giving up the immediate mode API.

Limitations

  • The current implementation assumes that the canvas takes the whole screen and it is not scaled. The default configuration of the eframe_template will work.
  • Currently the API only provides a way to create egui windows with HTML "inside" but doesn't provide a way to put bare HTML content in other places.
  • Multiple masking strategies are provided bacause all browsers have problems with one or the other. The Auto strategy tries to guess the best one for the current browser but it may choose a wrong strategy for unknown browsers.
You might also like...
A simple program to show a histogram on the terminal.

A simple program to show a histogram on the terminal.

Show unused code from multi-crate Rust projects

Warnalyzer Remove unused code from multi-crate Rust projects. The dead_code lint family of rustc is limited to one crate only and thus can't tell whet

Show active TCP connections on a TUI world map.
Show active TCP connections on a TUI world map.

Maperick Show active TCP connections on a TUI world map. Still WIP, but it's gonna be good. Setup git clone [email protected]:schlunsen/maperick.git cd m

👑 Show in-organization ranking of GitHub activities such as review count.

gh-ranking Show in-organization ranking of GitHub activities such as review count. Installation gh extension install yukukotani/gh-ranking Usage USAG

 🚩 Show sensitive command summary when open a new terminal
🚩 Show sensitive command summary when open a new terminal

🚩 Show sensitive command summary when open a new terminal 👀 Clear sensitive commands from shell history 🙈 Stash your history command before present

A very basic show-case of rust on the esp32 in 2022

Readme This example code does the following: Set up a WiFi connection on the ESP32-C3 Spawn a thread using std::thread in which we listen for incoming

Here we will show you how to build a simple parser.

A Rustic invitation to parsing: Calculator demo This is the code repository that accompanies the Rustic invitation to parsing blog post. It provides a

A simple CLI tool for converting CSV file content to JSON.

fast-csv-to-json A simple CLI tool for converting CSV file content to JSON. 我花了一個小時搓出來,接著優化了兩天的快速 CSV 轉 JSON CLI 小工具 Installation Install Rust with ru

Ideas = Creations, a multi-language CMS(Content Management System) based on Rust Web stacks, with long-term upgrade and maintenance.

Ideas = Creations 中文 RustHub: Rust ideas yesterday, shining creations today! This repository holds source code used to run https://rusthub.org, it's

Comments
  • Implement the `Hide` masking strategy

    Implement the `Hide` masking strategy

    An strategy that simply hides the HTML content when an egui window should be in front of it. Maybe displaying a message in place of the hidden HTML.

    This is useful to support something better than the Nop strategy on browsers where other complete strategies don't work.

    enhancement 
    opened by noxware 3
  •  Propertly support Safari, GTK WebKit and other WebKit based renderers

    Propertly support Safari, GTK WebKit and other WebKit based renderers

    This is pretty important since Tauri uses WebKit when running in Mac OS and Linux. At least on linux DocumentMask strategy doesn't work and DataMask flickers a lot.

    bug enhancement high priority 
    opened by noxware 0
  • Allow to have an always display-only non-interactable HTML element

    Allow to have an always display-only non-interactable HTML element

    Someone may want to show HTML content in a display-only fashion, without letting that HTML receive events. For example, they may be doing a video player where the controls of that video are in the egui side and a display-only video is rendered that makes little sense to be clickable.

    enhancement low priority 
    opened by noxware 0
Releases(v0.3.0)
  • v0.3.0(Feb 26, 2024)

    • Adds the Hide strategy.
    • Fixes the Nop strategy.
    • Optimizes when masking is triggered.
    • Other minor changes.

    Full Changelog: https://github.com/noxware/hframe/compare/v0.2.0...v0.3.0

    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Feb 26, 2024)

    Functional implementation of the change mask strategy at runtime feature.

    Full Changelog: https://github.com/noxware/hframe/compare/v0.1.1...v0.2.0

    Source code(tar.gz)
    Source code(zip)
  • v0.1.1(Feb 25, 2024)

  • v0.1.0(Feb 25, 2024)

    The first version of hframe that provides a usable public API.

    Works against egui 0.25.0.

    Full Changelog: https://github.com/noxware/hframe/commits/v0.1.0

    Source code(tar.gz)
    Source code(zip)
Owner
Franco Profeti
Franco Profeti
Fast command-line application to show the moon phase

moon-phases Command-line application to show the moon phase for a given date and time, as a text string, emoji, or numeric value. It can also show the

mirrorwitch 3 Oct 7, 2023
belt is a command line app that can show your time from a list of selected time zones

A CLI app to show your time from a list of selected time zones, and a rust lib to parse dates in string formats that are commonly used.

Rollie Ma 23 Nov 4, 2022
🎨✨ Show off your soothing color palette

?? Show off your soothing color palette ✨ Palettes · install · contribute · Gratitute ?? Palettes Rust C Lua Ruby Go sh js ?? install Installing this

BinaryBrainiacs 4 Jan 28, 2023
Generate a vanity address (`juno1wynd...`) to show your support for WYND DAO

WYND Generator When you generate a new mnemonic, it is very random (must be to be secure), and you cannot predict the address you will get. However, i

null 9 Dec 8, 2022
rusty-donut - ASCII raymarching inside a terminal

ASCII raymarching inside a terminal

drip 14 Feb 9, 2022
Works out if this is running from inside a shell, and if so, which one.

pshell pshell answers the question "Is my application running in a shell, and if so, which one". Example: you are installing something and want to mak

Alec Brown 2 Nov 3, 2022
Check if the process is running inside Windows Subsystem for Linux (Bash on Windows)

is-wsl Check if the process is running inside Windows Subsystem for Linux (Bash on Windows) Inspired by sindresorhus/is-wsl and made for Rust lang. Ca

Sean Larkin 6 Jan 31, 2023
Shared execution environment for constructing 3D virtual spaces from the inside.

Hearth Hearth is a shared, always-on execution environment for constructing 3D virtual spaces from the inside. Come join our Discord server! The Histo

null 6 Jan 31, 2023
A tool to format codeblocks inside markdown and org documents.

cbfmt (codeblock format) A tool to format codeblocks inside markdown, org, and restructuredtext documents. It iterates over all codeblocks, and format

Lukas Reineke 126 May 26, 2023
:large_orange_diamond: Build beautiful terminal tables with automatic content wrapping

Comfy-table Comfy-table tries to provide utility for building beautiful tables, while being easy to use. Features: Dynamic arrangement of content to a

Arne Beer 525 Jan 8, 2023