1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 13:50:04 -04:00

Merge branch 'master' of https://github.com/emilk/egui into multiples_viewports

This commit is contained in:
Konkitoman
2023-09-05 16:19:41 +03:00
17 changed files with 168 additions and 36 deletions

View File

@@ -96,6 +96,8 @@ egui = { version = "0.22.0", path = "../egui", default-features = false, feature
"log",
] }
log = { version = "0.4", features = ["std"] }
parking_lot = "0.12"
static_assertions = "1.1.0"
thiserror.workspace = true
#! ### Optional dependencies
@@ -106,7 +108,6 @@ egui_glow = { version = "0.22.0", path = "../egui_glow", optional = true, defaul
glow = { version = "0.12", optional = true }
ron = { version = "0.8", optional = true, features = ["integer128"] }
serde = { version = "1", optional = true, features = ["derive"] }
static_assertions = "1.1.0"
# -------------------------------------------
# native:

View File

@@ -1771,6 +1771,7 @@ mod wgpu_integration {
use egui::ViewportRender;
use egui_winit::create_winit_window_builder;
use parking_lot::Mutex;
use super::*;
@@ -1830,7 +1831,7 @@ mod wgpu_integration {
}
struct WgpuWinitApp {
repaint_proxy: Arc<std::sync::Mutex<EventLoopProxy<UserEvent>>>,
repaint_proxy: Arc<Mutex<EventLoopProxy<UserEvent>>>,
app_name: String,
native_options: epi::NativeOptions,
app_creator: Option<epi::AppCreator>,
@@ -1855,7 +1856,7 @@ mod wgpu_integration {
);
Self {
repaint_proxy: Arc::new(std::sync::Mutex::new(event_loop.create_proxy())),
repaint_proxy: Arc::new(Mutex::new(event_loop.create_proxy())),
app_name: app_name.to_owned(),
native_options,
running: None,
@@ -1983,11 +1984,7 @@ mod wgpu_integration {
let mut state = egui_winit::State::new(event_loop);
#[cfg(feature = "accesskit")]
{
integration.init_accesskit(
&mut state,
&window,
self.repaint_proxy.lock().unwrap().clone(),
);
integration.init_accesskit(&mut state, &window, self.repaint_proxy.lock().clone());
}
let theme = system_theme.unwrap_or(self.native_options.default_theme);
integration.egui_ctx.set_visuals(theme.egui_visuals());
@@ -2006,7 +2003,6 @@ mod wgpu_integration {
event_loop_proxy
.lock()
.unwrap()
.send_event(UserEvent::RequestRepaint {
when,
frame_nr,

View File

@@ -61,7 +61,7 @@ egui = { version = "0.22.0", path = "../egui", default-features = false, feature
] }
log = { version = "0.4", features = ["std"] }
raw-window-handle = "0.5.0"
web-time = { version = "0.1" } # We use web-time so we can (maybe) compile for web
web-time = { version = "0.2" } # We use web-time so we can (maybe) compile for web
winit = { version = "0.28", default-features = false }
#! ### Optional dependencies

View File

@@ -1,4 +1,5 @@
// #![warn(missing_docs)]
#![warn(missing_docs)] // Let's keep `Context` well-documented.
use std::sync::Arc;
use crate::{
@@ -1889,6 +1890,7 @@ impl Context {
}
impl Context {
/// Show a ui for settings (style and tessellation options).
pub fn settings_ui(&self, ui: &mut Ui) {
use crate::containers::*;
@@ -1911,6 +1913,7 @@ impl Context {
});
}
/// Show the state of egui, including its input and output.
pub fn inspection_ui(&self, ui: &mut Ui) {
use crate::containers::*;
crate::trace!(ui);
@@ -2040,6 +2043,7 @@ impl Context {
});
}
/// Shows the contents of [`Self::memory`].
pub fn memory_ui(&self, ui: &mut crate::Ui) {
if ui
.button("Reset all")
@@ -2140,6 +2144,7 @@ impl Context {
}
impl Context {
/// Edit the active [`Style`].
pub fn style_ui(&self, ui: &mut Ui) {
let mut style: Style = (*self.style()).clone();
style.ui(ui);
@@ -2155,6 +2160,8 @@ impl Context {
/// the function is still called, but with no other effect.
///
/// No locks are held while the given closure is called.
#[allow(clippy::unused_self)]
#[inline]
pub fn with_accessibility_parent(&self, _id: Id, f: impl FnOnce()) {
// TODO(emilk): this isn't thread-safe - another thread can call this function between the push/pop calls
#[cfg(feature = "accesskit")]

View File

@@ -1,3 +1,5 @@
/// An `enum` of common operating systems.
#[allow(clippy::upper_case_acronyms)] // `Ios` looks too ugly
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum OperatingSystem {
/// Unknown OS - could be wasm
@@ -26,6 +28,7 @@ impl Default for OperatingSystem {
}
impl OperatingSystem {
/// Uses the compile-time `target_arch` to identify the OS.
pub const fn from_target_os() -> Self {
if cfg!(target_arch = "wasm32") {
Self::Unknown

View File

@@ -1,4 +1,4 @@
// #![warn(missing_docs)]
#![warn(missing_docs)] // Let's keep `Ui` well-documented.
use std::hash::Hash;
use std::sync::Arc;
@@ -249,11 +249,6 @@ impl Ui {
self.painter.is_visible()
}
#[deprecated = "Renamed is_visible"]
pub fn visible(&self) -> bool {
self.painter.is_visible()
}
/// Calling `set_visible(false)` will cause all further widgets to be invisible,
/// yet still allocate space.
///
@@ -281,6 +276,7 @@ impl Ui {
}
}
/// Read the [`Layout`].
#[inline]
pub fn layout(&self) -> &Layout {
self.placer.layout()
@@ -611,6 +607,7 @@ impl Ui {
Id::new(self.next_auto_id_source)
}
/// Same as `ui.next_auto_id().with(id_source)`
pub fn auto_id_with<IdSource>(&self, id_source: IdSource) -> Id
where
IdSource: Hash,
@@ -618,6 +615,7 @@ impl Ui {
Id::new(self.next_auto_id_source).with(id_source)
}
/// Pretend like `count` widgets have been allocated.
pub fn skip_ahead_auto_ids(&mut self, count: usize) {
self.next_auto_id_source = self.next_auto_id_source.wrapping_add(count as u64);
}
@@ -2038,11 +2036,6 @@ impl Ui {
InnerResponse::new(inner, self.interact(rect, child_ui.id, Sense::hover()))
}
#[deprecated = "Use ui.vertical_centered or ui.centered_and_justified"]
pub fn centered<R>(&mut self, add_contents: impl FnOnce(&mut Self) -> R) -> InnerResponse<R> {
self.vertical_centered(add_contents)
}
/// This will make the next added widget centered and justified in the available space.
///
/// Only one widget may be added to the inner `Ui`!

View File

@@ -451,10 +451,13 @@ impl EguiWindows {
#[cfg(not(target_arch = "wasm32"))]
fn call_after_delay(delay: std::time::Duration, f: impl FnOnce() + Send + 'static) {
std::thread::spawn(move || {
std::thread::sleep(delay);
f();
});
std::thread::Builder::new()
.name("call_after_delay".to_owned())
.spawn(move || {
std::thread::sleep(delay);
f();
})
.unwrap();
}
#[cfg(target_arch = "wasm32")]

View File

@@ -29,12 +29,17 @@ default = []
## Enable [`DatePickerButton`] widget.
datepicker = ["chrono"]
## Support loading svg images.
svg = ["resvg", "tiny-skia", "usvg"]
## Log warnings using [`log`](https://docs.rs/log) crate.
log = ["dep:log", "egui/log"]
## Enable profiling with the [`puffin`](https://docs.rs/puffin) crate.
##
## Only enabled on native, because of the low resolution (1ms) of clocks in browsers.
puffin = ["dep:puffin", "egui/puffin"]
## Support loading svg images.
svg = ["resvg", "tiny-skia", "usvg"]
[dependencies]
egui = { version = "0.22.0", path = "../egui", default-features = false }
@@ -65,6 +70,8 @@ image = { version = "0.24", optional = true, default-features = false }
# feature "log"
log = { version = "0.4", optional = true, features = ["std"] }
puffin = { version = "0.16", optional = true }
# svg feature
resvg = { version = "0.28", optional = true, default-features = false }
tiny-skia = { version = "0.8", optional = true, default-features = false } # must be updated in lock-step with resvg

View File

@@ -203,6 +203,7 @@ use egui::ColorImage;
/// On invalid image or unsupported image format.
#[cfg(feature = "image")]
pub fn load_image_bytes(image_bytes: &[u8]) -> Result<egui::ColorImage, String> {
crate::profile_function!();
let image = image::load_from_memory(image_bytes).map_err(|err| err.to_string())?;
let size = [image.width() as _, image.height() as _];
let image_buffer = image.to_rgba8();
@@ -235,6 +236,7 @@ pub fn load_svg_bytes_with_size(
svg_bytes: &[u8],
fit_to: FitTo,
) -> Result<egui::ColorImage, String> {
crate::profile_function!();
let opt = usvg::Options::default();
let rtree = usvg::Tree::from_data(svg_bytes, &opt).map_err(|err| err.to_string())?;

View File

@@ -28,6 +28,38 @@ pub use crate::sizing::Size;
pub use crate::strip::*;
pub use crate::table::*;
// ---------------------------------------------------------------------------
mod profiling_scopes {
#![allow(unused_macros)]
#![allow(unused_imports)]
/// Profiling macro for feature "puffin"
macro_rules! profile_function {
($($arg: tt)*) => {
#[cfg(not(target_arch = "wasm32"))] // Disabled on web because of the coarse 1ms clock resolution there.
#[cfg(feature = "puffin")]
puffin::profile_function!($($arg)*);
};
}
pub(crate) use profile_function;
/// Profiling macro for feature "puffin"
macro_rules! profile_scope {
($($arg: tt)*) => {
#[cfg(not(target_arch = "wasm32"))] // Disabled on web because of the coarse 1ms clock resolution there.
#[cfg(feature = "puffin")]
puffin::profile_scope!($($arg)*);
};
}
pub(crate) use profile_scope;
}
#[allow(unused_imports)]
pub(crate) use profiling_scopes::*;
// ---------------------------------------------------------------------------
/// Log an error with either `log` or `eprintln`
macro_rules! log_err {
($fmt: literal, $($arg: tt)*) => {{

View File

@@ -1,4 +1,6 @@
#![allow(clippy::many_single_char_names)]
#![allow(clippy::wrong_self_convention)] // False positives
use std::ops::Range;
use crate::{shape::Shape, Color32, PathShape, Stroke};

View File

@@ -374,6 +374,8 @@ where
#[cfg(test)]
mod tests {
#![allow(clippy::disallowed_methods)] // Ok for tests
use crate::mutex::Mutex;
use std::time::Duration;
@@ -414,6 +416,8 @@ mod tests {
#[cfg(feature = "deadlock_detection")]
#[cfg(test)]
mod tests_rwlock {
#![allow(clippy::disallowed_methods)] // Ok for tests
use crate::mutex::RwLock;
use std::time::Duration;

View File

@@ -1,4 +1,5 @@
#![allow(clippy::derive_hash_xor_eq)] // We need to impl Hash for f32, but we don't implement Eq, which is fine
#![allow(clippy::wrong_self_convention)] // We use `from_` to indicate conversion direction. It's non-diomatic, but makes sense in this context.
use std::ops::Range;
use std::sync::Arc;