1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-03 15:20:05 -04:00

Merge remote-tracking branch 'egui/master' into dynamic-grid

This commit is contained in:
René Rössler
2022-03-15 09:35:33 +01:00
69 changed files with 1257 additions and 2450 deletions

View File

@@ -43,28 +43,29 @@ syntax_highlighting = ["syntect"]
egui = { version = "0.17.0", path = "../egui", default-features = false }
epi = { version = "0.17.0", path = "../epi" }
chrono = { version = "0.4", features = ["js-sys", "wasmbind"], optional = true }
chrono = { version = "0.4", optional = true, features = ["js-sys", "wasmbind"] }
enum-map = { version = "2", features = ["serde"] }
unicode_names2 = { version = "0.5.0", default-features = false }
# feature "http":
egui_extras = { version = "0.17.0", path = "../egui_extras", features = [
egui_extras = { version = "0.17.0", path = "../egui_extras", optional = true, features = [
"image",
"datepicker",
], optional = true }
] }
ehttp = { version = "0.2.0", optional = true }
image = { version = "0.24", default-features = false, features = [
image = { version = "0.24", optional = true, default-features = false, features = [
"jpeg",
"png",
], optional = true }
poll-promise = { version = "0.1", default-features = false, optional = true }
] }
poll-promise = { version = "0.1", optional = true, default-features = false }
# feature "syntax_highlighting":
syntect = { version = "4", default-features = false, features = [
syntect = { version = "4", optional = true, default-features = false, features = [
"default-fancy",
], optional = true }
] }
# feature "persistence":
serde = { version = "1", features = ["derive"], optional = true }
serde = { version = "1", optional = true, features = ["derive"] }
[dev-dependencies]
criterion = { version = "0.3", default-features = false }

View File

@@ -38,7 +38,7 @@ impl epi::App for ColorTest {
egui::CentralPanel::default().show(ctx, |ui| {
if frame.is_web() {
ui.label(
"NOTE: The WebGL1 backend without sRGB support does NOT pass the color test.",
"NOTE: Some old browsers stuck on WebGL1 without sRGB support will not pass the color test.",
);
ui.separator();
}

View File

@@ -19,6 +19,7 @@ impl epi::App for DemoApp {
_ctx: &egui::Context,
_frame: &epi::Frame,
_storage: Option<&dyn epi::Storage>,
_gl: &std::rc::Rc<epi::glow::Context>,
) {
#[cfg(feature = "persistence")]
if let Some(storage) = _storage {

View File

@@ -22,7 +22,13 @@ impl super::Demo for DancingStrings {
impl super::View for DancingStrings {
fn ui(&mut self, ui: &mut Ui) {
Frame::dark_canvas(ui.style()).show(ui, |ui| {
let color = if ui.visuals().dark_mode {
Color32::from_additive_luminance(196)
} else {
Color32::from_black_alpha(240)
};
Frame::canvas(ui.style()).show(ui, |ui| {
ui.ctx().request_repaint();
let time = ui.input().time;
@@ -49,10 +55,7 @@ impl super::View for DancingStrings {
.collect();
let thickness = 10.0 / mode as f32;
shapes.push(epaint::Shape::line(
points,
Stroke::new(thickness, Color32::from_additive_luminance(196)),
));
shapes.push(epaint::Shape::line(points, Stroke::new(thickness, color)));
}
ui.painter().extend(shapes);

View File

@@ -52,7 +52,13 @@ impl super::View for MultiTouch {
let num_touches = ui.input().multi_touch().map_or(0, |mt| mt.num_touches);
ui.label(format!("Current touches: {}", num_touches));
Frame::dark_canvas(ui.style()).show(ui, |ui| {
let color = if ui.visuals().dark_mode {
Color32::WHITE
} else {
Color32::BLACK
};
Frame::canvas(ui.style()).show(ui, |ui| {
// Note that we use `Sense::drag()` although we do not use any pointer events. With
// the current implementation, the fact that a touch event of two or more fingers is
// recognized, does not mean that the pointer events are suppressed, which are always
@@ -76,7 +82,6 @@ impl super::View for MultiTouch {
// check for touch input (or the lack thereof) and update zoom and scale factors, plus
// color and width:
let mut stroke_width = 1.;
let color = Color32::GRAY;
if let Some(multi_touch) = ui.ctx().multi_touch() {
// This adjusts the current zoom factor and rotation angle according to the dynamic
// change (for the current frame) of the touch gesture:

View File

@@ -31,7 +31,7 @@ impl Default for PaintBezier {
pos2(200.0, 200.0),
pos2(250.0, 50.0),
],
stroke: Stroke::new(1.0, Color32::LIGHT_BLUE),
stroke: Stroke::new(1.0, Color32::from_rgb(25, 200, 100)),
fill: Color32::from_rgb(50, 100, 150).linear_multiply(0.25),
aux_stroke: Stroke::new(1.0, Color32::RED.linear_multiply(0.25)),
bounding_box_stroke: Stroke::new(0.0, Color32::LIGHT_GREEN.linear_multiply(0.25)),
@@ -164,7 +164,7 @@ impl super::View for PaintBezier {
});
self.ui_control(ui);
Frame::dark_canvas(ui.style()).show(ui, |ui| {
Frame::canvas(ui.style()).show(ui, |ui| {
self.ui_content(ui);
});
}

View File

@@ -12,7 +12,7 @@ impl Default for Painting {
fn default() -> Self {
Self {
lines: Default::default(),
stroke: Stroke::new(1.0, Color32::LIGHT_BLUE),
stroke: Stroke::new(1.0, Color32::from_rgb(25, 200, 100)),
}
}
}
@@ -91,7 +91,7 @@ impl super::View for Painting {
});
self.ui_control(ui);
ui.label("Paint with your mouse/touch!");
Frame::dark_canvas(ui.style()).show(ui, |ui| {
Frame::canvas(ui.style()).show(ui, |ui| {
self.ui_content(ui);
});
}

View File

@@ -274,9 +274,6 @@ fn show_integration_name(ui: &mut egui::Ui, integration_info: &epi::IntegrationI
format!("https://github.com/emilk/egui/tree/master/{}", name),
);
}
name if name.starts_with("egui_web") => {
ui.hyperlink_to(name, "https://github.com/emilk/egui/tree/master/egui_web");
}
name => {
ui.label(name);
}

View File

@@ -148,8 +148,8 @@ fn test_egui_e2e() {
let full_output = ctx.run(raw_input.clone(), |ctx| {
demo_windows.ui(ctx);
});
let clipped_meshes = ctx.tessellate(full_output.shapes);
assert!(!clipped_meshes.is_empty());
let clipped_primitives = ctx.tessellate(full_output.shapes);
assert!(!clipped_primitives.is_empty());
}
}
@@ -167,8 +167,11 @@ fn test_egui_zero_window_size() {
let full_output = ctx.run(raw_input.clone(), |ctx| {
demo_windows.ui(ctx);
});
let clipped_meshes = ctx.tessellate(full_output.shapes);
assert!(clipped_meshes.is_empty(), "There should be nothing to show");
let clipped_primitives = ctx.tessellate(full_output.shapes);
assert!(
clipped_primitives.is_empty(),
"There should be nothing to show"
);
}
}

View File

@@ -1,6 +1,6 @@
use egui::text::LayoutJob;
/// View some code with syntax highlighing and selection.
/// View some code with syntax highlighting and selection.
pub fn code_view_ui(ui: &mut egui::Ui, mut code: &str) {
let language = "rs";
let theme = CodeTheme::from_memory(ui.ctx());
@@ -23,13 +23,13 @@ pub fn code_view_ui(ui: &mut egui::Ui, mut code: &str) {
/// Memoized Code highlighting
pub fn highlight(ctx: &egui::Context, theme: &CodeTheme, code: &str, language: &str) -> LayoutJob {
impl egui::util::cache::ComputerMut<(&CodeTheme, &str, &str), LayoutJob> for Highligher {
impl egui::util::cache::ComputerMut<(&CodeTheme, &str, &str), LayoutJob> for Highlighter {
fn compute(&mut self, (theme, code, lang): (&CodeTheme, &str, &str)) -> LayoutJob {
self.highlight(theme, code, lang)
}
}
type HighlightCache<'a> = egui::util::cache::FrameCache<LayoutJob, Highligher>;
type HighlightCache<'a> = egui::util::cache::FrameCache<LayoutJob, Highlighter>;
let mut memory = ctx.memory();
let highlight_cache = memory.caches.cache::<HighlightCache<'_>>();
@@ -295,13 +295,13 @@ impl CodeTheme {
// ----------------------------------------------------------------------------
#[cfg(feature = "syntect")]
struct Highligher {
struct Highlighter {
ps: syntect::parsing::SyntaxSet,
ts: syntect::highlighting::ThemeSet,
}
#[cfg(feature = "syntect")]
impl Default for Highligher {
impl Default for Highlighter {
fn default() -> Self {
Self {
ps: syntect::parsing::SyntaxSet::load_defaults_newlines(),
@@ -311,7 +311,7 @@ impl Default for Highligher {
}
#[cfg(feature = "syntect")]
impl Highligher {
impl Highlighter {
#[allow(clippy::unused_self, clippy::unnecessary_wraps)]
fn highlight(&self, theme: &CodeTheme, code: &str, lang: &str) -> LayoutJob {
self.highlight_impl(theme, code, lang).unwrap_or_else(|| {
@@ -392,10 +392,10 @@ fn as_byte_range(whole: &str, range: &str) -> std::ops::Range<usize> {
#[cfg(not(feature = "syntect"))]
#[derive(Default)]
struct Highligher {}
struct Highlighter {}
#[cfg(not(feature = "syntect"))]
impl Highligher {
impl Highlighter {
#[allow(clippy::unused_self, clippy::unnecessary_wraps)]
fn highlight(&self, theme: &CodeTheme, mut text: &str, _language: &str) -> LayoutJob {
// Extremely simple syntax highlighter for when we compile without syntect

View File

@@ -47,6 +47,7 @@ impl epi::App for WrapApp {
_ctx: &egui::Context,
_frame: &epi::Frame,
_storage: Option<&dyn epi::Storage>,
_gl: &std::rc::Rc<epi::glow::Context>,
) {
#[cfg(feature = "persistence")]
if let Some(storage) = _storage {