mirror of
https://github.com/tauri-apps/tauri-egui.git
synced 2026-02-04 02:41:19 +01:00
110 lines
4.8 KiB
Markdown
110 lines
4.8 KiB
Markdown
# tauri-egui
|
|
|
|
[](https://github.com/tauri-apps/tauri-egui/tree/dev)
|
|
[](https://opencollective.com/tauri)
|
|
[](https://github.com/tauri-apps/tauri/actions?query=workflow%3A%22test+library%22)
|
|
[](https://discord.com/invite/tauri)
|
|
[](https://tauri.app)
|
|
[](https://good-labs.github.io/greater-good-affirmation)
|
|
[](https://opencollective.com/tauri)
|
|
|
|
## This project is currently unmaintained!
|
|
|
|
For the time being, an unvetted community-hosted implementation is hosted [here](https://github.com/clearlysid/tauri-plugin-egui).
|
|
|
|
## About tauri-egui
|
|
|
|
`tauri-egui` is a Tauri plugin for using the [`egui library`](https://github.com/emilk/egui) in a Tauri application via [`glutin`](https://github.com/tauri-apps/glutin). `egui` is a pure Rust GUI library that runs natively, recommended by the Tauri team for secure contexts such as password and secret interfaces.
|
|
|
|
## Dependency
|
|
|
|
| Component | Description | Version |
|
|
| -------------------------------------------------------------------------------------------- | ----------------------------------------- | -------------------------------------------------------------------------------------------------------- |
|
|
| [**tauri**](https://github.com/tauri-apps/tauri/tree/dev/core/tauri) | runtime core | [](https://crates.io/crates/tauri) |
|
|
| [**egui**](https://github.com/tauri-apps/egui) | immediate mode GUI library for Rust | [](https://crates.io/crates/egui) |
|
|
| [**tao**](https://github.com/tauri-apps/tao) | cross-platform application window creation library in Rust | [](https://crates.io/crates/tao) |
|
|
| [**glutin**](https://github.com/tauri-apps/glutin) | low-level library for OpenGL context creation, written in pure Rust. | [](https://crates.io/crates/glutin) |
|
|
|
|
## Example
|
|
|
|
```rust
|
|
use tauri::Manager;
|
|
use tauri_egui::{eframe, egui, EguiPluginBuilder, EguiPluginHandle};
|
|
|
|
struct LoginApp {
|
|
password: String,
|
|
on_submit: Box<dyn Fn(&str) -> bool + Send>,
|
|
}
|
|
|
|
impl LoginApp {
|
|
fn new<F: Fn(&str) -> bool + Send + 'static>(
|
|
ctx: &eframe::CreationContext,
|
|
on_submit: F,
|
|
) -> Self {
|
|
Self {
|
|
password: "".into(),
|
|
on_submit: Box::new(on_submit),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl eframe::App for LoginApp {
|
|
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
|
let LoginApp {
|
|
password,
|
|
on_submit,
|
|
} = self;
|
|
egui::CentralPanel::default().show(ctx, |ui| {
|
|
ui.label("Enter your password");
|
|
let textfield = ui.add_sized(
|
|
[ui.available_width(), 24.],
|
|
egui::TextEdit::singleline(password).password(true),
|
|
);
|
|
let button = ui.button("Submit");
|
|
if (textfield.lost_focus() && ui.input().key_pressed(egui::Key::Enter)) || button.clicked() {
|
|
if on_submit(password) {
|
|
frame.close();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
tauri::Builder::default()
|
|
.setup(|app| {
|
|
app.wry_plugin(EguiPluginBuilder::new(app.handle()));
|
|
let egui_handle = app.state::<EguiPluginHandle>();
|
|
|
|
let native_options = eframe::NativeOptions {
|
|
drag_and_drop_support: true,
|
|
initial_window_size: Some([1280.0, 1024.0].into()),
|
|
..Default::default()
|
|
};
|
|
|
|
let _window = egui_handle
|
|
.create_window(
|
|
"native-window".to_string(),
|
|
Box::new(|cc| Box::new(LoginApp::new(cc, |pwd| pwd == "tauriisawesome"))),
|
|
"Login".into(),
|
|
native_options,
|
|
)
|
|
.unwrap();
|
|
|
|
Ok(())
|
|
})
|
|
.run(tauri::generate_context!("examples/demo/tauri.conf.json"))
|
|
.expect("error while building tauri application");
|
|
}
|
|
```
|
|
|
|
## Semver
|
|
|
|
**tauri-egui** is following [Semantic Versioning 2.0](https://semver.org/).
|
|
|
|
## Licenses
|
|
|
|
Code: (c) 2019 - 2022 - The Tauri Programme within The Commons Conservancy.
|
|
|
|
MIT or MIT/Apache 2.0 where applicable.
|