forked from emilk/egui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split out new crate egui-winit from egui_glium (emilk#735)
- Loading branch information
1 parent
408d1bc
commit b9b415a
Showing
27 changed files
with
1,003 additions
and
616 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ members = [ | |
"egui_demo_lib", | ||
"egui_glium", | ||
"egui_web", | ||
"egui-winit", | ||
"egui", | ||
"emath", | ||
"epaint", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
Oops, something went wrong.