Skip to content

Commit

Permalink
Merge branch 'emilk:master' into patch22
Browse files Browse the repository at this point in the history
  • Loading branch information
rustbasic authored Jun 19, 2024
2 parents 8926a2c + 52a8e11 commit e771a2a
Show file tree
Hide file tree
Showing 41 changed files with 413 additions and 98 deletions.
50 changes: 40 additions & 10 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,12 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecdffb913a326b6c642290a0d0ec8e8d6597291acdc07cc4c9cb4b3635d44cf9"

[[package]]
name = "color_quant"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"

[[package]]
name = "com"
version = "0.6.0"
Expand Down Expand Up @@ -1107,24 +1113,24 @@ dependencies = [
]

[[package]]
name = "directories-next"
version = "2.0.0"
name = "directories"
version = "5.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "339ee130d97a610ea5a5872d2bbb130fdf68884ff09d3028b81bec8a1ac23bbc"
checksum = "9a49173b84e034382284f27f1af4dcbbd231ffa358c0fe316541a7337f376a35"
dependencies = [
"cfg-if",
"dirs-sys-next",
"dirs-sys",
]

[[package]]
name = "dirs-sys-next"
version = "0.1.2"
name = "dirs-sys"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c"
dependencies = [
"libc",
"option-ext",
"redox_users",
"winapi",
"windows-sys 0.48.0",
]

[[package]]
Expand Down Expand Up @@ -1175,7 +1181,7 @@ version = "0.27.2"
dependencies = [
"ahash",
"bytemuck",
"directories-next",
"directories",
"document-features",
"egui",
"egui-wgpu",
Expand Down Expand Up @@ -1734,6 +1740,16 @@ dependencies = [
"wasi",
]

[[package]]
name = "gif"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fb2d69b19215e18bb912fa30f7ce15846e301408695e44e0ef719f1da9e19f2"
dependencies = [
"color_quant",
"weezl",
]

[[package]]
name = "gimli"
version = "0.28.0"
Expand Down Expand Up @@ -2079,6 +2095,8 @@ checksum = "a9b4f005360d32e9325029b38ba47ebd7a56f3316df09249368939562d518645"
dependencies = [
"bytemuck",
"byteorder",
"color_quant",
"gif",
"num-traits",
"png",
"zune-core",
Expand Down Expand Up @@ -2669,6 +2687,12 @@ version = "11.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575"

[[package]]
name = "option-ext"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"

[[package]]
name = "orbclient"
version = "0.3.46"
Expand Down Expand Up @@ -4234,6 +4258,12 @@ version = "0.25.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14247bb57be4f377dfb94c72830b8ce8fc6beac03cf4bf7b9732eadd414123fc"

[[package]]
name = "weezl"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082"

[[package]]
name = "wgpu"
version = "0.20.1"
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ manual_string_new = "warn"
map_err_ignore = "warn"
map_flatten = "warn"
map_unwrap_or = "warn"
match_bool = "warn"
match_on_vec_items = "warn"
match_same_arms = "warn"
match_wild_err_arm = "warn"
Expand Down
4 changes: 2 additions & 2 deletions crates/eframe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ glow = [

## Enable saving app state to disk.
persistence = [
"directories-next",
"directories",
"egui-winit/serde",
"egui/persistence",
"ron",
Expand Down Expand Up @@ -159,7 +159,7 @@ image = { workspace = true, features = ["png"] } # Needed for app icon
winit = { workspace = true, default-features = false, features = ["rwh_06"] }

# optional native:
directories-next = { version = "2", optional = true }
directories = { version = "5", optional = true }
egui-wgpu = { workspace = true, optional = true, features = [
"winit",
] } # if wgpu is used, use it with winit
Expand Down
2 changes: 1 addition & 1 deletion crates/eframe/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ pub struct NativeOptions {
pub persist_window: bool,

/// The folder where `eframe` will store the app state. If not set, eframe will get the paths
/// from [directories_next].
/// from [directories].
pub persistence_path: Option<std::path::PathBuf>,
}

Expand Down
4 changes: 2 additions & 2 deletions crates/eframe/src/native/file_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use std::{
/// [`egui::ViewportBuilder::app_id`] of [`crate::NativeOptions::viewport`]
/// or the title argument to [`crate::run_native`].
///
/// On native the path is picked using [`directories_next::ProjectDirs::data_dir`](https://docs.rs/directories-next/2.0.0/directories_next/struct.ProjectDirs.html#method.data_dir) which is:
/// On native the path is picked using [`directories::ProjectDirs::data_dir`](https://docs.rs/directories/5.0.1/directories/struct.ProjectDirs.html#method.data_dir) which is:
/// * Linux: `/home/UserName/.local/share/APP_ID`
/// * macOS: `/Users/UserName/Library/Application Support/APP_ID`
/// * Windows: `C:\Users\UserName\AppData\Roaming\APP_ID`
pub fn storage_dir(app_id: &str) -> Option<PathBuf> {
directories_next::ProjectDirs::from("", "", app_id)
directories::ProjectDirs::from("", "", app_id)
.map(|proj_dirs| proj_dirs.data_dir().to_path_buf())
}

Expand Down
4 changes: 3 additions & 1 deletion crates/eframe/src/web/app_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ impl AppRunner {
/// The result can be painted later with a call to [`Self::run_and_paint`] or [`Self::paint`].
pub fn logic(&mut self) {
let canvas_size = super::canvas_size_in_points(self.canvas(), self.egui_ctx());
let raw_input = self.input.new_frame(canvas_size);
let mut raw_input = self.input.new_frame(canvas_size);

self.app.raw_input_hook(&self.egui_ctx, &mut raw_input);

let full_output = self.egui_ctx.run(raw_input, |egui_ctx| {
self.app.update(egui_ctx, &mut self.frame);
Expand Down
2 changes: 1 addition & 1 deletion crates/egui-wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub struct RenderState {
}

impl RenderState {
/// Creates a new `RenderState`, containing everything needed for drawing egui with wgpu.
/// Creates a new [`RenderState`], containing everything needed for drawing egui with wgpu.
///
/// # Errors
/// Wgpu initialization may fail due to incompatible hardware or driver for a given config.
Expand Down
34 changes: 16 additions & 18 deletions crates/egui-wgpu/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use wgpu::util::DeviceExt as _;
/// You can use this for storage when implementing [`CallbackTrait`].
pub type CallbackResources = type_map::concurrent::TypeMap;

/// You can use this to do custom `wgpu` rendering in an egui app.
/// You can use this to do custom [`wgpu`] rendering in an egui app.
///
/// Implement [`CallbackTrait`] and call [`Callback::new_paint_callback`].
///
Expand Down Expand Up @@ -50,15 +50,15 @@ impl Callback {
///
/// ## Command Encoder
///
/// The passed-in `CommandEncoder` is egui's and can be used directly to register
/// The passed-in [`wgpu::CommandEncoder`] is egui's and can be used directly to register
/// wgpu commands for simple use cases.
/// This allows reusing the same [`wgpu::CommandEncoder`] for all callbacks and egui
/// rendering itself.
///
/// ## Command Buffers
///
/// For more complicated use cases, one can also return a list of arbitrary
/// `CommandBuffer`s and have complete control over how they get created and fed.
/// [`wgpu::CommandBuffer`]s and have complete control over how they get created and fed.
/// In particular, this gives an opportunity to parallelize command registration and
/// prevents a faulty callback from poisoning the main wgpu pipeline.
///
Expand Down Expand Up @@ -498,7 +498,7 @@ impl Renderer {
render_pass.set_scissor_rect(0, 0, size_in_pixels[0], size_in_pixels[1]);
}

/// Should be called before `render()`.
/// Should be called before [`Self::render`].
pub fn update_texture(
&mut self,
device: &wgpu::Device,
Expand Down Expand Up @@ -631,12 +631,11 @@ impl Renderer {
self.textures.get(id)
}

/// Registers a `wgpu::Texture` with a `epaint::TextureId`.
/// Registers a [`wgpu::Texture`] with a [`epaint::TextureId`].
///
/// This enables the application to reference the texture inside an image ui element.
/// This effectively enables off-screen rendering inside the egui UI. Texture must have
/// the texture format `TextureFormat::Rgba8UnormSrgb` and
/// Texture usage `TextureUsage::SAMPLED`.
/// the texture format [`wgpu::TextureFormat::Rgba8UnormSrgb`].
pub fn register_native_texture(
&mut self,
device: &wgpu::Device,
Expand All @@ -655,9 +654,9 @@ impl Renderer {
)
}

/// Registers a `wgpu::Texture` with an existing `epaint::TextureId`.
/// Registers a [`wgpu::Texture`] with an existing [`epaint::TextureId`].
///
/// This enables applications to reuse `TextureId`s.
/// This enables applications to reuse [`epaint::TextureId`]s.
pub fn update_egui_texture_from_wgpu_texture(
&mut self,
device: &wgpu::Device,
Expand All @@ -678,15 +677,14 @@ impl Renderer {
);
}

/// Registers a `wgpu::Texture` with a `epaint::TextureId` while also accepting custom
/// `wgpu::SamplerDescriptor` options.
/// Registers a [`wgpu::Texture`] with a [`epaint::TextureId`] while also accepting custom
/// [`wgpu::SamplerDescriptor`] options.
///
/// This allows applications to specify individual minification/magnification filters as well as
/// custom mipmap and tiling options.
///
/// The `Texture` must have the format `TextureFormat::Rgba8UnormSrgb` and usage
/// `TextureUsage::SAMPLED`. Any compare function supplied in the `SamplerDescriptor` will be
/// ignored.
/// The texture must have the format [`wgpu::TextureFormat::Rgba8UnormSrgb`].
/// Any compare function supplied in the [`wgpu::SamplerDescriptor`] will be ignored.
#[allow(clippy::needless_pass_by_value)] // false positive
pub fn register_native_texture_with_sampler_options(
&mut self,
Expand Down Expand Up @@ -723,10 +721,10 @@ impl Renderer {
id
}

/// Registers a `wgpu::Texture` with an existing `epaint::TextureId` while also accepting custom
/// `wgpu::SamplerDescriptor` options.
/// Registers a [`wgpu::Texture`] with an existing [`epaint::TextureId`] while also accepting custom
/// [`wgpu::SamplerDescriptor`] options.
///
/// This allows applications to reuse `TextureId`s created with custom sampler options.
/// This allows applications to reuse [`epaint::TextureId`]s created with custom sampler options.
#[allow(clippy::needless_pass_by_value)] // false positive
pub fn update_egui_texture_from_wgpu_texture_with_sampler_options(
&mut self,
Expand Down Expand Up @@ -766,7 +764,7 @@ impl Renderer {
}

/// Uploads the uniform, vertex and index data used by the renderer.
/// Should be called before `render()`.
/// Should be called before [`Self::render`].
///
/// Returns all user-defined command buffers gathered from [`CallbackTrait::prepare`] & [`CallbackTrait::finish_prepare`] callbacks.
pub fn update_buffers(
Expand Down
9 changes: 7 additions & 2 deletions crates/egui/src/containers/panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ impl SidePanel {
})),
);
panel_ui.expand_to_include_rect(panel_rect);
panel_ui.set_clip_rect(panel_rect); // If we overflow, don't do so visibly (#4475)

let frame = frame.unwrap_or_else(|| Frame::side_top_panel(ui.style()));
let inner_response = frame.show(&mut panel_ui, |ui| {
ui.set_min_height(ui.max_rect().height()); // Make sure the frame fills the full height
Expand Down Expand Up @@ -335,7 +337,7 @@ impl SidePanel {
// (hence the shrink).
let resize_x = side.opposite().side_x(rect.shrink(1.0));
let resize_x = ui.painter().round_to_pixel(resize_x);
ui.painter().vline(resize_x, rect.y_range(), stroke);
ui.painter().vline(resize_x, panel_rect.y_range(), stroke);
}

inner_response
Expand Down Expand Up @@ -749,6 +751,8 @@ impl TopBottomPanel {
})),
);
panel_ui.expand_to_include_rect(panel_rect);
panel_ui.set_clip_rect(panel_rect); // If we overflow, don't do so visibly (#4475)

let frame = frame.unwrap_or_else(|| Frame::side_top_panel(ui.style()));
let inner_response = frame.show(&mut panel_ui, |ui| {
ui.set_min_width(ui.max_rect().width()); // Make the frame fill full width
Expand Down Expand Up @@ -814,7 +818,7 @@ impl TopBottomPanel {
// (hence the shrink).
let resize_y = side.opposite().side_y(rect.shrink(1.0));
let resize_y = ui.painter().round_to_pixel(resize_y);
ui.painter().hline(rect.x_range(), resize_y, stroke);
ui.painter().hline(panel_rect.x_range(), resize_y, stroke);
}

inner_response
Expand Down Expand Up @@ -1078,6 +1082,7 @@ impl CentralPanel {
Layout::top_down(Align::Min),
Some(UiStackInfo::new(UiKind::CentralPanel)),
);
panel_ui.set_clip_rect(panel_rect); // If we overflow, don't do so visibly (#4475)

let frame = frame.unwrap_or_else(|| Frame::central_panel(ui.style()));
frame.show(&mut panel_ui, |ui| {
Expand Down
8 changes: 8 additions & 0 deletions crates/egui/src/hit_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ pub fn hit_test(
.filter(|layer| layer.order.allow_interaction())
.flat_map(|&layer_id| widgets.get_layer(layer_id))
.filter(|&w| {
if w.interact_rect.is_negative() {
return false;
}

let pos_in_layer = pos_in_layers.get(&w.layer_id).copied().unwrap_or(pos);
let dist_sq = w.interact_rect.distance_sq_to_pos(pos_in_layer);

Expand Down Expand Up @@ -311,6 +315,10 @@ fn find_closest(widgets: impl Iterator<Item = WidgetRect>, pos: Pos2) -> Option<
let mut closest = None;
let mut closest_dist_sq = f32::INFINITY;
for widget in widgets {
if widget.interact_rect.is_negative() {
continue;
}

let dist_sq = widget.interact_rect.distance_sq_to_pos(pos);

// In case of a tie, take the last one = the one on top.
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! Try the live web demo: <https://www.egui.rs/#demo>. Read more about egui at <https://github.com/emilk/egui>.
//!
//! `egui` is in heavy development, with each new version having breaking changes.
//! You need to have rust 1.62.0 or later to use `egui`.
//! You need to have rust 1.76.0 or later to use `egui`.
//!
//! To quickly get started with egui, you can take a look at [`eframe_template`](https://github.com/emilk/eframe_template)
//! which uses [`eframe`](https://docs.rs/eframe).
Expand Down
8 changes: 4 additions & 4 deletions crates/egui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ pub struct ScrollStyle {
/// When the user hovers the scroll bars they expand to [`Self::bar_width`].
pub floating_width: f32,

/// How much space i allocated for a floating scroll bar?
/// How much space is allocated for a floating scroll bar?
///
/// Normally this is zero, but you could set this to something small
/// like 4.0 and set [`Self::dormant_handle_opacity`] and
Expand Down Expand Up @@ -499,7 +499,7 @@ impl ScrollStyle {
active_background_opacity: 1.0,
active_handle_opacity: 1.0,

// Be tranlucent when expanded so we can see the content
// Be translucent when expanded so we can see the content
interact_background_opacity: 0.6,
interact_handle_opacity: 0.6,

Expand Down Expand Up @@ -652,7 +652,7 @@ pub struct Interaction {
/// Radius of the interactive area of the corner of a window during drag-to-resize.
pub resize_grab_radius_corner: f32,

/// If `false`, tooltips will show up anytime you hover anything, even is mouse is still moving
/// If `false`, tooltips will show up anytime you hover anything, even if mouse is still moving
pub show_tooltips_only_when_still: bool,

/// Delay in seconds before showing tooltips after the mouse stops moving
Expand Down Expand Up @@ -2132,7 +2132,7 @@ impl HandleShape {
pub enum NumericColorSpace {
/// RGB is 0-255 in gamma space.
///
/// Alpha is 0-255 in linear space .
/// Alpha is 0-255 in linear space.
GammaByte,

/// 0-1 in linear space.
Expand Down
Loading

0 comments on commit e771a2a

Please sign in to comment.