Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: emilk/egui
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ce8c94dbebcf4853a97265b3458130f2c1d1c6df
Choose a base ref
..
head repository: emilk/egui
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6dd21180dac268d4be6ba328d265ec63a6156045
Choose a head ref
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ NOTE: [`epaint`](crates/epaint/CHANGELOG.md), [`eframe`](crates/eframe/CHANGELOG
* Improved text rendering ([#2071](https://github.com/emilk/egui/pull/2071)).
* Less jitter when calling `Context::set_pixels_per_point` ([#2239](https://github.com/emilk/egui/pull/2239)).
* Fixed popups and color edit going outside the screen.
* Fixed keyboard support in `DragValue`. ([#2342](https://github.com/emilk/egui/pull/2342)).


## 0.19.0 - 2022-08-20
16 changes: 8 additions & 8 deletions Cargo.lock

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

49 changes: 47 additions & 2 deletions crates/eframe/src/web/web_painter_wgpu.rs
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@ pub(crate) struct WebPainterWgpu {
limits: wgpu::Limits,
render_state: Option<RenderState>,
on_surface_error: Arc<dyn Fn(wgpu::SurfaceError) -> SurfaceErrorAction>,
depth_format: Option<wgpu::TextureFormat>,
depth_texture_view: Option<wgpu::TextureView>,
}

impl WebPainterWgpu {
@@ -26,6 +28,32 @@ impl WebPainterWgpu {
self.render_state.clone()
}

pub fn generate_depth_texture_view(
&self,
render_state: &RenderState,
width_in_pixels: u32,
height_in_pixels: u32,
) -> Option<wgpu::TextureView> {
let device = &render_state.device;
self.depth_format.map(|depth_format| {
device
.create_texture(&wgpu::TextureDescriptor {
label: Some("egui_depth_texture"),
size: wgpu::Extent3d {
width: width_in_pixels,
height: height_in_pixels,
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: depth_format,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
})
.create_view(&wgpu::TextureViewDescriptor::default())
})
}

#[allow(unused)] // only used if `wgpu` is the only active feature.
pub async fn new(canvas_id: &str, options: &WebOptions) -> Result<Self, String> {
tracing::debug!("Creating wgpu painter");
@@ -55,7 +83,8 @@ impl WebPainterWgpu {
let target_format =
egui_wgpu::preferred_framebuffer_format(&surface.get_supported_formats(&adapter));

let renderer = egui_wgpu::Renderer::new(&device, target_format, None, 1);
let depth_format = options.wgpu_options.depth_format;
let renderer = egui_wgpu::Renderer::new(&device, target_format, depth_format, 1);
let render_state = RenderState {
device: Arc::new(device),
queue: Arc::new(queue),
@@ -80,6 +109,8 @@ impl WebPainterWgpu {
render_state: Some(render_state),
surface,
surface_configuration,
depth_format,
depth_texture_view: None,
limits: options.wgpu_options.device_descriptor.limits.clone(),
on_surface_error: options.wgpu_options.on_surface_error.clone(),
})
@@ -157,6 +188,11 @@ impl WebPainter for WebPainterWgpu {
self.surface_configuration.height = size_in_pixels[1];
self.surface
.configure(&render_state.device, &self.surface_configuration);
self.depth_texture_view = self.generate_depth_texture_view(
render_state,
size_in_pixels[0],
size_in_pixels[1],
);
}

let frame = match self.surface.get_current_texture() {
@@ -193,7 +229,16 @@ impl WebPainter for WebPainterWgpu {
store: true,
},
})],
depth_stencil_attachment: None,
depth_stencil_attachment: self.depth_texture_view.as_ref().map(|view| {
wgpu::RenderPassDepthStencilAttachment {
view,
depth_ops: Some(wgpu::Operations {
load: wgpu::LoadOp::Clear(1.0),
store: false,
}),
stencil_ops: None,
}
}),
label: Some("egui_render"),
});

3 changes: 3 additions & 0 deletions crates/egui-wgpu/src/lib.rs
Original file line number Diff line number Diff line change
@@ -55,6 +55,8 @@ pub struct WgpuConfiguration {

/// Callback for surface errors.
pub on_surface_error: Arc<dyn Fn(wgpu::SurfaceError) -> SurfaceErrorAction>,

pub depth_format: Option<wgpu::TextureFormat>,
}

impl Default for WgpuConfiguration {
@@ -68,6 +70,7 @@ impl Default for WgpuConfiguration {
backends: wgpu::Backends::PRIMARY | wgpu::Backends::GL,
present_mode: wgpu::PresentMode::AutoVsync,
power_preference: wgpu::PowerPreference::HighPerformance,
depth_format: None,

on_surface_error: Arc::new(|err| {
if err == wgpu::SurfaceError::Outdated {
2 changes: 1 addition & 1 deletion crates/egui-winit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ winit = { version = "0.27.2", default-features = false }
document-features = { version = "0.2", optional = true }

# feature accesskit
accesskit_winit = { version = "0.6.0", optional = true }
accesskit_winit = { version = "0.6.6", optional = true }

puffin = { version = "0.14", optional = true }
serde = { version = "1.0", optional = true, features = ["derive"] }
3 changes: 1 addition & 2 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
@@ -880,9 +880,8 @@ impl Context {
pub fn set_pixels_per_point(&self, pixels_per_point: f32) {
if pixels_per_point != self.pixels_per_point() {
self.request_repaint();
self.memory().new_pixels_per_point = Some(pixels_per_point);
}

self.memory().new_pixels_per_point = Some(pixels_per_point);
}

/// Useful for pixel-perfect rendering
17 changes: 16 additions & 1 deletion crates/egui/src/data/input.rs
Original file line number Diff line number Diff line change
@@ -550,7 +550,7 @@ impl<'a> ModifierNames<'a> {
append_if(modifiers.alt, self.alt);
append_if(modifiers.mac_cmd || modifiers.command, self.mac_cmd);
} else {
append_if(modifiers.ctrl, self.ctrl);
append_if(modifiers.ctrl || modifiers.command, self.ctrl);
append_if(modifiers.alt, self.alt);
append_if(modifiers.shift, self.shift);
}
@@ -793,6 +793,21 @@ impl KeyboardShortcut {
}
}

#[test]
fn format_kb_shortcut() {
let cmd_shift_f = KeyboardShortcut::new(Modifiers::COMMAND | Modifiers::SHIFT, Key::F);
assert_eq!(
cmd_shift_f.format(&ModifierNames::NAMES, false),
"Ctrl+Shift+F"
);
assert_eq!(
cmd_shift_f.format(&ModifierNames::NAMES, true),
"Shift+Cmd+F"
);
assert_eq!(cmd_shift_f.format(&ModifierNames::SYMBOLS, false), "^⇧F");
assert_eq!(cmd_shift_f.format(&ModifierNames::SYMBOLS, true), "⇧⌘F");
}

// ----------------------------------------------------------------------------

impl RawInput {
7 changes: 7 additions & 0 deletions crates/egui/src/id.rs
Original file line number Diff line number Diff line change
@@ -90,6 +90,13 @@ impl From<&'static str> for Id {
}
}

impl From<String> for Id {
#[inline]
fn from(string: String) -> Self {
Self::new(string)
}
}

// ----------------------------------------------------------------------------

// Idea taken from the `nohash_hasher` crate.
15 changes: 10 additions & 5 deletions crates/egui/src/input_state.rs
Original file line number Diff line number Diff line change
@@ -245,9 +245,9 @@ impl InputState {
self.pointer.wants_repaint() || self.scroll_delta != Vec2::ZERO || !self.events.is_empty()
}

/// Check for a key press. If found, `true` is returned and the key pressed is consumed, so that this will only return `true` once.
pub fn consume_key(&mut self, modifiers: Modifiers, key: Key) -> bool {
let mut match_found = false;
/// Count presses of a key. If non-zero, the presses are consumed, so that this will only return non-zero once.
pub fn count_and_consume_key(&mut self, modifiers: Modifiers, key: Key) -> usize {
let mut count = 0usize;

self.events.retain(|event| {
let is_match = matches!(
@@ -259,12 +259,17 @@ impl InputState {
} if *ev_key == key && ev_mods.matches(modifiers)
);

match_found |= is_match;
count += is_match as usize;

!is_match
});

match_found
count
}

/// Check for a key press. If found, `true` is returned and the key pressed is consumed, so that this will only return `true` once.
pub fn consume_key(&mut self, modifiers: Modifiers, key: Key) -> bool {
self.count_and_consume_key(modifiers, key) > 0
}

/// Check if the given shortcut has been pressed.
7 changes: 6 additions & 1 deletion crates/egui/src/memory.rs
Original file line number Diff line number Diff line change
@@ -431,8 +431,13 @@ impl Memory {

/// Register this widget as being interested in getting keyboard focus.
/// This will allow the user to select it with tab and shift-tab.
/// This is normally done automatically when handling interactions,
/// but it is sometimes useful to pre-register interest in focus,
/// e.g. before deciding which type of underlying widget to use,
/// as in the [`crate::DragValue`] widget, so a widget can be focused
/// and rendered correctly in a single frame.
#[inline(always)]
pub(crate) fn interested_in_focus(&mut self, id: Id) {
pub fn interested_in_focus(&mut self, id: Id) {
self.interaction.focus.interested_in_focus(id);
}

4 changes: 2 additions & 2 deletions crates/egui/src/ui.rs
Original file line number Diff line number Diff line change
@@ -1447,7 +1447,7 @@ impl Ui {
text: impl Into<WidgetText>,
) -> Response {
let mut response = self.radio(*current_value == alternative, text);
if response.clicked() {
if response.clicked() && *current_value != alternative {
*current_value = alternative;
response.mark_changed();
}
@@ -1475,7 +1475,7 @@ impl Ui {
text: impl Into<WidgetText>,
) -> Response {
let mut response = self.selectable_label(*current_value == selected_value, text);
if response.clicked() {
if response.clicked() && *current_value != selected_value {
*current_value = selected_value;
response.mark_changed();
}
Loading