Skip to content

Commit

Permalink
Split out new crate egui-winit from egui_glium (emilk#735)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk authored and mankinskin committed Sep 29, 2021
1 parent 408d1bc commit b9b415a
Show file tree
Hide file tree
Showing 27 changed files with 1,003 additions and 616 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ jobs:
toolchain: 1.54.0
override: true
- run: sudo apt-get install libspeechd-dev
- run: cargo doc -p emath -p epaint -p egui -p eframe -p epi -p egui_web -p egui_glium --lib --no-deps --all-features
- run: cargo doc -p emath -p epaint -p egui -p eframe -p epi -p egui_web -p egui-winit -p egui_glium --lib --no-deps --all-features

doc_web:
name: cargo doc web
Expand Down
8 changes: 6 additions & 2 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Also see [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUT


## Crate overview
The crates in this repository are: `egui, emath, epaint, egui, epi, egui_web, egui_glium, egui_demo_lib, egui_demo_app`.
The crates in this repository are: `egui, emath, epaint, egui, epi, egui-winit, egui_web, egui_glium, egui_demo_lib, egui_demo_app`.

### `egui`: The main GUI library.
Example code: `if ui.button("Click me").clicked() { … }`
Expand All @@ -25,6 +25,11 @@ Depends on `emath`, [`ab_glyph`](https://crates.io/crates/ab_glyph), [`atomic_re
Depends only on `egui`.
Adds a thin application level wrapper around `egui` for hosting an `egui` app inside of `eframe`.

### `egui-winit`
This crates provides bindings between [`egui`](https://github.com/emilk/egui) and [winit](https://crates.io/crates/winit).

The library translates winit events to egui, handled copy/paste, updates the cursor, open links clicked in egui, etc.

### `egui_web`
Puts an egui app inside the web browser by compiling to WASM and binding to the web browser with [`js-sys`](https://crates.io/crates/js-sys) and [`wasm-bindgen`](https://crates.io/crates/wasm-bindgen). Paints the triangles that egui outputs using WebGL.

Expand All @@ -40,7 +45,6 @@ The demo that you can see at <https://emilk.github.io/egui/index.html> is using
Depends on `egui` + `epi`.
This contains a bunch of uses of `egui` and looks like the ui code you would write for an `egui` app.


### `egui_demo_app`
Thin wrapper around `egui_demo_lib` so we can compile it to a web site or a native app executable.
Depends on `egui_demo_lib` + `eframe`.
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to the egui crate will be documented in this file.

NOTE: [`eframe`](eframe/CHANGELOG.md), [`egui_web`](egui_web/CHANGELOG.md) and [`egui_glium`](egui_glium/CHANGELOG.md) have their own changelogs!
NOTE: [`eframe`](eframe/CHANGELOG.md), [`egui_web`](egui_web/CHANGELOG.md), [`egui-winit`](egui-winit/CHANGELOG.md) and [`egui_glium`](egui_glium/CHANGELOG.md) have their own changelogs!


## Unreleased
Expand Down
16 changes: 13 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"egui_demo_lib",
"egui_glium",
"egui_web",
"egui-winit",
"egui",
"emath",
"epaint",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ I maintain two official egui integrations made for apps:

* [`egui_web`](https://github.com/emilk/egui/tree/master/egui_web) for making a web app. Compiles to WASM, renders with WebGL. [Click to run the egui demo](https://emilk.github.io/egui/index.html).
* [`egui_glium`](https://github.com/emilk/egui/tree/master/egui_glium) for compiling native apps with [Glium](https://github.com/glium/glium).
* [`egui-winit`](https://github.com/emilk/egui/tree/master/egui-winit) for integrating with [`winit`](https://github.com/rust-windowing/winit). `egui-winit` is used by `egui_glium`.

If you making an app, consider using [`eframe`](https://github.com/emilk/egui/tree/master/eframe), a framework which allows you to write code that works on both the web (`egui_web`) and native (using `egui_glium`).

Expand All @@ -180,7 +181,6 @@ If you making an app, consider using [`eframe`](https://github.com/emilk/egui/tr
* [`egui_sdl2_gl`](https://crates.io/crates/egui_sdl2_gl) for [SDL2](https://crates.io/crates/sdl2).
* [`egui_vulkano`](https://github.com/derivator/egui_vulkano) for [Vulkano](https://github.com/vulkano-rs/vulkano).
* [`egui-winit-ash-integration`](https://github.com/MatchaChoco010/egui-winit-ash-integration) for [winit](https://github.com/rust-windowing/winit) and [ash](https://github.com/MaikKlein/ash).
* [`egui_winit_platform`](https://github.com/hasenbanck/egui_winit_platform) for [winit](https://crates.io/crates/winit) (requires separate painter).
* [`egui_winit_vulkano`](https://github.com/hakolao/egui_winit_vulkano) for [Vulkano](https://github.com/vulkano-rs/vulkano).
* [`fltk-egui`](https://crates.io/crates/fltk-egui) for [fltk-rs](https://github.com/fltk-rs/fltk-rs).
* [`ggez-egui`](https://github.com/NemuiSen/ggez-egui) for the [ggez](https://ggez.rs/) game framework.
Expand Down
12 changes: 9 additions & 3 deletions eframe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ epi = { version = "0.14.0", path = "../epi" }

# For compiling natively:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
egui_glium = { version = "0.14.0", path = "../egui_glium", default-features = false }
egui_glium = { version = "0.14.0", path = "../egui_glium", default-features = false, features = ["clipboard", "links"] }

# For compiling to web:
[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand All @@ -43,6 +43,12 @@ default = ["default_fonts"]
# If set, egui will use `include_bytes!` to bundle some fonts.
# If you plan on specifying your own fonts you may disable this feature.
default_fonts = ["egui/default_fonts"]

# Enable saving app state to disk.
persistence = ["epi/persistence", "egui_glium/persistence", "egui_web/persistence"]
screen_reader = ["egui_glium/screen_reader", "egui_web/screen_reader"] # experimental
time = ["egui_glium/time"] # for seconds_since_midnight

# experimental support for a screen reader
screen_reader = ["egui_glium/screen_reader", "egui_web/screen_reader"]

# for seconds_since_midnight (used in egui_demo_lib)
time = ["egui_glium/time"]
2 changes: 1 addition & 1 deletion eframe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ pub fn start_web(canvas_id: &str, app: Box<dyn epi::App>) -> Result<(), wasm_bin
/// Call from `fn main` like this: `eframe::run_native(Box::new(MyEguiApp::default()))`
#[cfg(not(target_arch = "wasm32"))]
pub fn run_native(app: Box<dyn epi::App>, native_options: epi::NativeOptions) {
egui_glium::run(app, native_options)
egui_glium::run(app, &native_options)
}
7 changes: 7 additions & 0 deletions egui-winit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog for egui-winit

All notable changes to the `egui-winit` integration will be noted in this file.


## Unreleased
First stand-alone release. Previously part of `egui_glium`.
45 changes: 45 additions & 0 deletions egui-winit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[package]
name = "egui-winit"
version = "0.14.0"
authors = ["Emil Ernerfeldt <[email protected]>"]
description = "Bindings for using egui with winit"
edition = "2018"
homepage = "https://github.com/emilk/egui/tree/master/egui-winit"
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/emilk/egui/tree/master/egui-winit"
categories = ["gui", "game-development"]
keywords = ["winit", "egui", "gui", "gamedev"]
include = [
"../LICENSE-APACHE",
"../LICENSE-MIT",
"**/*.rs",
"Cargo.toml",
]

[package.metadata.docs.rs]
all-features = true

[dependencies]
egui = { version = "0.14.0", path = "../egui", default-features = false }
epi = { version = "0.14.0", path = "../epi" }
winit = "0.25"

copypasta = { version = "0.7", optional = true }
webbrowser = { version = "0.5", optional = true }

# feature screen_reader
tts = { version = "0.17", optional = true }

[features]
default = ["clipboard", "links"]

# enable cut/copy/paste to OS clipboard.
# if disabled a clipboard will be simulated so you can still copy/paste within the egui app.
clipboard = ["copypasta"]

# enable opening links in a browser when an egui hyperlink is clicked.
links = ["webbrowser"]

# experimental support for a screen reader
screen_reader = ["tts"]
11 changes: 11 additions & 0 deletions egui-winit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# egui-winit

[![Latest version](https://img.shields.io/crates/v/egui-winit.svg)](https://crates.io/crates/egui-winit)
[![Documentation](https://docs.rs/egui-winit/badge.svg)](https://docs.rs/egui-winit)
[![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/)
![MIT](https://img.shields.io/badge/license-MIT-blue.svg)
![Apache](https://img.shields.io/badge/license-Apache-blue.svg)

This crates provides bindings between [`egui`](https://github.com/emilk/egui) and [winit](https://crates.io/crates/winit).

The library translates winit events to egui, handled copy/paste, updates the cursor, open links clicked in egui, etc.
69 changes: 69 additions & 0 deletions egui-winit/src/clipboard.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/// Handles interfacing either with the OS clipboard.
/// If the "clipboard" feature is off it will instead simulate the clipboard locally.
pub struct Clipboard {
#[cfg(feature = "copypasta")]
copypasta: Option<copypasta::ClipboardContext>,

/// Fallback manual clipboard.
#[cfg(not(feature = "copypasta"))]
clipboard: String,
}

impl Default for Clipboard {
fn default() -> Self {
Self {
#[cfg(feature = "copypasta")]
copypasta: init_copypasta(),

#[cfg(not(feature = "copypasta"))]
clipboard: String::default(),
}
}
}

impl Clipboard {
pub fn get(&mut self) -> Option<String> {
#[cfg(feature = "copypasta")]
if let Some(clipboard) = &mut self.copypasta {
use copypasta::ClipboardProvider as _;
match clipboard.get_contents() {
Ok(contents) => Some(contents),
Err(err) => {
eprintln!("Paste error: {}", err);
None
}
}
} else {
None
}

#[cfg(not(feature = "copypasta"))]
Some(self.clipboard.clone())
}

pub fn set(&mut self, text: String) {
#[cfg(feature = "copypasta")]
if let Some(clipboard) = &mut self.copypasta {
use copypasta::ClipboardProvider as _;
if let Err(err) = clipboard.set_contents(text) {
eprintln!("Copy/Cut error: {}", err);
}
}

#[cfg(not(feature = "copypasta"))]
{
self.clipboard = text;
}
}
}

#[cfg(feature = "copypasta")]
fn init_copypasta() -> Option<copypasta::ClipboardContext> {
match copypasta::ClipboardContext::new() {
Ok(clipboard) => Some(clipboard),
Err(err) => {
eprintln!("Failed to initialize clipboard: {}", err);
None
}
}
}
Loading

0 comments on commit b9b415a

Please sign in to comment.