hframe/
lib.rs

1//! Show HTML content "inside" your [egui](https://github.com/emilk/egui) rendered application. "hframe" stands for "HTML Frame".
2//!
3//! > **💡 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](https://tauri.app/).
4//! >
5//! > [egui-tauri-template](https://github.com/noxware/egui-tauri-template)
6//! > will serve as good foundation if you need to target both platforms.
7//!
8//! > **⚠️ Warning:**: If you experience type mismatches, please ensure hframe is
9//! > using the same egui version you are using by checking your `Cargo.lock` file.
10//! > This errors may happen if you try to upgrade your egui version while hframe
11//! > is still using types from your older version.
12//!
13//! ## Simple example
14//!
15//! ```rust
16//! use hframe::Aware;
17//!
18//! const IFRAME: &str = r#"
19//! <iframe src="https://www.example.com/"></iframe>
20//! "#;
21//!
22//! pub struct App;
23//!
24//! impl App {
25//!     pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
26//!         Self
27//!     }
28//! }
29//!
30//! impl eframe::App for App {
31//!     fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
32//!         egui::Window::new("Egui Rendered Window")
33//!             .show(ctx, |ui| {
34//!                 ui.centered_and_justified(|ui| {
35//!                     ui.label("This window can be shown on top of the iframe thanks to `.aware()`");
36//!                 });
37//!             })
38//!             .aware();
39//!
40//!         hframe::HtmlWindow::new("Iframe Window").content(IFRAME).show(ctx);
41//!
42//!         hframe::sync(ctx);
43//!     }
44//! }
45//! ```
46//!
47//! For a more complete example see [demo's app.rs](https://github.com/noxware/hframe/blob/master/examples/demo/src/app.rs).
48//!
49//! ## How does it work?
50//!
51//! `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
52//! abale to show egui windows on top of the HTML content, `hframe` uses different set
53//! of HTML masking/cliping techniques combined with other smart logic to produce the
54//! illusion of the HTML content being "inside" the egui rendered application.
55//!
56//! This approach has been chosen after many experiments with alternative techniques
57//! which were not able to provide the same level of integration and flexibility.
58//!
59//! Additionally, some tracking is performed to provide an immediate mode like public
60//! API. HTML will only be re-rendered if you change the initially provided content. This
61//! can be useful if you want to change the HTML content in a controlled and reactive
62//! manner without giving up the immediate mode API.
63//!
64//! ## Limitations
65//!
66//! - The current implementation assumes that the canvas takes the whole screen and
67//!   it is not scaled. The default configuration of the [eframe_template](https://github.com/emilk/eframe_template) will work.
68//! - Currently the API only provides a way to create egui windows with HTML "inside"
69//!   but doesn't provide a way to put bare HTML content in other places.
70
71mod aware;
72mod composed_area;
73mod composition_context;
74pub(crate) mod composition_strategies;
75mod composition_strategy;
76mod html_window;
77pub(crate) mod utils;
78
79pub use aware::*;
80pub(crate) use composed_area::*;
81pub use composition_context::*;
82pub(crate) use composition_strategy::*;
83pub use html_window::*;