mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 14:49:06 -04:00
Apply nightly clippy suggestions/fixes (#7794)
* Reduce the diff for https://github.com/emilk/egui/pull/7793
This commit is contained in:
@@ -5,8 +5,8 @@
|
||||
[default.extend-words]
|
||||
ime = "ime" # Input Method Editor
|
||||
nknown = "nknown" # part of @55nknown username
|
||||
isse = "isse" # part of @IsseW username
|
||||
tye = "tye" # part of @tye-exe username
|
||||
isse = "isse" # part of @IsseW username
|
||||
tye = "tye" # part of @tye-exe username
|
||||
ro = "ro" # read-only, also part of the username @Phen-Ro
|
||||
typ = "typ" # Often used because `type` is a keyword in Rust
|
||||
|
||||
|
||||
@@ -251,7 +251,10 @@ web-sys = { workspace = true, features = [
|
||||
] }
|
||||
|
||||
# optional web:
|
||||
egui-wgpu = { workspace = true, optional = true, features = ["capture"] } # if wgpu is used, use it without (!) winit
|
||||
egui-wgpu = { workspace = true, optional = true, features = [
|
||||
# if wgpu is used, use it without (!) winit:
|
||||
"capture",
|
||||
] }
|
||||
wgpu = { workspace = true, optional = true }
|
||||
|
||||
# Native dev dependencies for testing
|
||||
|
||||
@@ -137,25 +137,24 @@ fn install_keydown(runner_ref: &WebRunner, target: &EventTarget) -> Result<(), J
|
||||
&& !modifiers.command
|
||||
// When text agent is focused, it is responsible for handling input events
|
||||
&& !runner.text_agent.has_focus()
|
||||
&& let Some(text) = text_from_keyboard_event(&event)
|
||||
{
|
||||
if let Some(text) = text_from_keyboard_event(&event) {
|
||||
let egui_event = egui::Event::Text(text);
|
||||
let should_stop_propagation =
|
||||
(runner.web_options.should_stop_propagation)(&egui_event);
|
||||
let should_prevent_default =
|
||||
(runner.web_options.should_prevent_default)(&egui_event);
|
||||
runner.input.raw.events.push(egui_event);
|
||||
runner.needs_repaint.repaint_asap();
|
||||
let egui_event = egui::Event::Text(text);
|
||||
let should_stop_propagation =
|
||||
(runner.web_options.should_stop_propagation)(&egui_event);
|
||||
let should_prevent_default =
|
||||
(runner.web_options.should_prevent_default)(&egui_event);
|
||||
runner.input.raw.events.push(egui_event);
|
||||
runner.needs_repaint.repaint_asap();
|
||||
|
||||
// If this is indeed text, then prevent any other action.
|
||||
if should_prevent_default {
|
||||
event.prevent_default();
|
||||
}
|
||||
// If this is indeed text, then prevent any other action.
|
||||
if should_prevent_default {
|
||||
event.prevent_default();
|
||||
}
|
||||
|
||||
// Use web options to tell if the event should be propagated to parent elements.
|
||||
if should_stop_propagation {
|
||||
event.stop_propagation();
|
||||
}
|
||||
// Use web options to tell if the event should be propagated to parent elements.
|
||||
if should_stop_propagation {
|
||||
event.stop_propagation();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,30 +320,28 @@ fn install_copy_cut_paste(runner_ref: &WebRunner, target: &EventTarget) -> Resul
|
||||
return; // The eframe app is not interested
|
||||
}
|
||||
|
||||
if let Some(data) = event.clipboard_data() {
|
||||
if let Ok(text) = data.get_data("text") {
|
||||
let text = text.replace("\r\n", "\n");
|
||||
if let Some(data) = event.clipboard_data()
|
||||
&& let Ok(text) = data.get_data("text")
|
||||
{
|
||||
let text = text.replace("\r\n", "\n");
|
||||
|
||||
let mut should_stop_propagation = true;
|
||||
let mut should_prevent_default = true;
|
||||
if !text.is_empty() {
|
||||
let egui_event = egui::Event::Paste(text);
|
||||
should_stop_propagation =
|
||||
(runner.web_options.should_stop_propagation)(&egui_event);
|
||||
should_prevent_default =
|
||||
(runner.web_options.should_prevent_default)(&egui_event);
|
||||
runner.input.raw.events.push(egui_event);
|
||||
runner.needs_repaint.repaint_asap();
|
||||
}
|
||||
let mut should_stop_propagation = true;
|
||||
let mut should_prevent_default = true;
|
||||
if !text.is_empty() {
|
||||
let egui_event = egui::Event::Paste(text);
|
||||
should_stop_propagation = (runner.web_options.should_stop_propagation)(&egui_event);
|
||||
should_prevent_default = (runner.web_options.should_prevent_default)(&egui_event);
|
||||
runner.input.raw.events.push(egui_event);
|
||||
runner.needs_repaint.repaint_asap();
|
||||
}
|
||||
|
||||
// Use web options to tell if the web event should be propagated to parent elements based on the egui event.
|
||||
if should_stop_propagation {
|
||||
event.stop_propagation();
|
||||
}
|
||||
// Use web options to tell if the web event should be propagated to parent elements based on the egui event.
|
||||
if should_stop_propagation {
|
||||
event.stop_propagation();
|
||||
}
|
||||
|
||||
if should_prevent_default {
|
||||
event.prevent_default();
|
||||
}
|
||||
if should_prevent_default {
|
||||
event.prevent_default();
|
||||
}
|
||||
}
|
||||
})?;
|
||||
@@ -562,45 +559,44 @@ fn install_pointerup(runner_ref: &WebRunner, target: &EventTarget) -> Result<(),
|
||||
if is_interested_in_pointer_event(
|
||||
runner,
|
||||
egui::pos2(event.client_x() as f32, event.client_y() as f32),
|
||||
) {
|
||||
if let Some(button) = button_from_mouse_event(&event) {
|
||||
let modifiers = runner.input.raw.modifiers;
|
||||
let egui_event = egui::Event::PointerButton {
|
||||
pos,
|
||||
button,
|
||||
pressed: false,
|
||||
modifiers,
|
||||
};
|
||||
let should_stop_propagation =
|
||||
(runner.web_options.should_stop_propagation)(&egui_event);
|
||||
let should_prevent_default =
|
||||
(runner.web_options.should_prevent_default)(&egui_event);
|
||||
runner.input.raw.events.push(egui_event);
|
||||
) && let Some(button) = button_from_mouse_event(&event)
|
||||
{
|
||||
let modifiers = runner.input.raw.modifiers;
|
||||
let egui_event = egui::Event::PointerButton {
|
||||
pos,
|
||||
button,
|
||||
pressed: false,
|
||||
modifiers,
|
||||
};
|
||||
let should_stop_propagation =
|
||||
(runner.web_options.should_stop_propagation)(&egui_event);
|
||||
let should_prevent_default =
|
||||
(runner.web_options.should_prevent_default)(&egui_event);
|
||||
runner.input.raw.events.push(egui_event);
|
||||
|
||||
// Previously on iOS, the canvas would not receive focus on
|
||||
// any touch event, which resulted in the on-screen keyboard
|
||||
// not working when focusing on a text field in an egui app.
|
||||
// This attempts to fix that by forcing the focus on any
|
||||
// click on the canvas.
|
||||
runner.canvas().focus().ok();
|
||||
// Previously on iOS, the canvas would not receive focus on
|
||||
// any touch event, which resulted in the on-screen keyboard
|
||||
// not working when focusing on a text field in an egui app.
|
||||
// This attempts to fix that by forcing the focus on any
|
||||
// click on the canvas.
|
||||
runner.canvas().focus().ok();
|
||||
|
||||
// In Safari we are only allowed to do certain things
|
||||
// (like playing audio, start a download, etc)
|
||||
// on user action, such as a click.
|
||||
// So we need to run the app logic here and now:
|
||||
runner.logic();
|
||||
// In Safari we are only allowed to do certain things
|
||||
// (like playing audio, start a download, etc)
|
||||
// on user action, such as a click.
|
||||
// So we need to run the app logic here and now:
|
||||
runner.logic();
|
||||
|
||||
// Make sure we paint the output of the above logic call asap:
|
||||
runner.needs_repaint.repaint_asap();
|
||||
// Make sure we paint the output of the above logic call asap:
|
||||
runner.needs_repaint.repaint_asap();
|
||||
|
||||
if should_prevent_default {
|
||||
event.prevent_default();
|
||||
}
|
||||
if should_prevent_default {
|
||||
event.prevent_default();
|
||||
}
|
||||
|
||||
// Use web options to tell if the web event should be propagated to parent elements based on the egui event.
|
||||
if should_stop_propagation {
|
||||
event.stop_propagation();
|
||||
}
|
||||
// Use web options to tell if the web event should be propagated to parent elements based on the egui event.
|
||||
if should_stop_propagation {
|
||||
event.stop_propagation();
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -713,29 +709,27 @@ fn install_touchstart(runner_ref: &WebRunner, target: &EventTarget) -> Result<()
|
||||
|
||||
fn install_touchmove(runner_ref: &WebRunner, target: &EventTarget) -> Result<(), JsValue> {
|
||||
runner_ref.add_event_listener(target, "touchmove", |event: web_sys::TouchEvent, runner| {
|
||||
if let Some((pos, touch)) = primary_touch_pos(runner, &event) {
|
||||
if is_interested_in_pointer_event(
|
||||
if let Some((pos, touch)) = primary_touch_pos(runner, &event)
|
||||
&& is_interested_in_pointer_event(
|
||||
runner,
|
||||
egui::pos2(touch.client_x() as f32, touch.client_y() as f32),
|
||||
) {
|
||||
let egui_event = egui::Event::PointerMoved(pos);
|
||||
let should_stop_propagation =
|
||||
(runner.web_options.should_stop_propagation)(&egui_event);
|
||||
let should_prevent_default =
|
||||
(runner.web_options.should_prevent_default)(&egui_event);
|
||||
runner.input.raw.events.push(egui_event);
|
||||
)
|
||||
{
|
||||
let egui_event = egui::Event::PointerMoved(pos);
|
||||
let should_stop_propagation = (runner.web_options.should_stop_propagation)(&egui_event);
|
||||
let should_prevent_default = (runner.web_options.should_prevent_default)(&egui_event);
|
||||
runner.input.raw.events.push(egui_event);
|
||||
|
||||
push_touches(runner, egui::TouchPhase::Move, &event);
|
||||
runner.needs_repaint.repaint();
|
||||
push_touches(runner, egui::TouchPhase::Move, &event);
|
||||
runner.needs_repaint.repaint();
|
||||
|
||||
// Use web options to tell if the web event should be propagated to parent elements based on the egui event.
|
||||
if should_stop_propagation {
|
||||
event.stop_propagation();
|
||||
}
|
||||
// Use web options to tell if the web event should be propagated to parent elements based on the egui event.
|
||||
if should_stop_propagation {
|
||||
event.stop_propagation();
|
||||
}
|
||||
|
||||
if should_prevent_default {
|
||||
event.prevent_default();
|
||||
}
|
||||
if should_prevent_default {
|
||||
event.prevent_default();
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -743,50 +737,49 @@ fn install_touchmove(runner_ref: &WebRunner, target: &EventTarget) -> Result<(),
|
||||
|
||||
fn install_touchend(runner_ref: &WebRunner, target: &EventTarget) -> Result<(), JsValue> {
|
||||
runner_ref.add_event_listener(target, "touchend", |event: web_sys::TouchEvent, runner| {
|
||||
if let Some((pos, touch)) = primary_touch_pos(runner, &event) {
|
||||
if is_interested_in_pointer_event(
|
||||
if let Some((pos, touch)) = primary_touch_pos(runner, &event)
|
||||
&& is_interested_in_pointer_event(
|
||||
runner,
|
||||
egui::pos2(touch.client_x() as f32, touch.client_y() as f32),
|
||||
) {
|
||||
// First release mouse to click:
|
||||
let mut should_stop_propagation = true;
|
||||
let mut should_prevent_default = true;
|
||||
let egui_event = egui::Event::PointerButton {
|
||||
pos,
|
||||
button: egui::PointerButton::Primary,
|
||||
pressed: false,
|
||||
modifiers: runner.input.raw.modifiers,
|
||||
};
|
||||
should_stop_propagation &=
|
||||
(runner.web_options.should_stop_propagation)(&egui_event);
|
||||
should_prevent_default &= (runner.web_options.should_prevent_default)(&egui_event);
|
||||
runner.input.raw.events.push(egui_event);
|
||||
// Then remove hover effect:
|
||||
should_stop_propagation &=
|
||||
(runner.web_options.should_stop_propagation)(&egui::Event::PointerGone);
|
||||
should_prevent_default &=
|
||||
(runner.web_options.should_prevent_default)(&egui::Event::PointerGone);
|
||||
runner.input.raw.events.push(egui::Event::PointerGone);
|
||||
)
|
||||
{
|
||||
// First release mouse to click:
|
||||
let mut should_stop_propagation = true;
|
||||
let mut should_prevent_default = true;
|
||||
let egui_event = egui::Event::PointerButton {
|
||||
pos,
|
||||
button: egui::PointerButton::Primary,
|
||||
pressed: false,
|
||||
modifiers: runner.input.raw.modifiers,
|
||||
};
|
||||
should_stop_propagation &= (runner.web_options.should_stop_propagation)(&egui_event);
|
||||
should_prevent_default &= (runner.web_options.should_prevent_default)(&egui_event);
|
||||
runner.input.raw.events.push(egui_event);
|
||||
// Then remove hover effect:
|
||||
should_stop_propagation &=
|
||||
(runner.web_options.should_stop_propagation)(&egui::Event::PointerGone);
|
||||
should_prevent_default &=
|
||||
(runner.web_options.should_prevent_default)(&egui::Event::PointerGone);
|
||||
runner.input.raw.events.push(egui::Event::PointerGone);
|
||||
|
||||
push_touches(runner, egui::TouchPhase::End, &event);
|
||||
push_touches(runner, egui::TouchPhase::End, &event);
|
||||
|
||||
runner.needs_repaint.repaint_asap();
|
||||
runner.needs_repaint.repaint_asap();
|
||||
|
||||
// Use web options to tell if the web event should be propagated to parent elements based on the egui event.
|
||||
if should_stop_propagation {
|
||||
event.stop_propagation();
|
||||
}
|
||||
// Use web options to tell if the web event should be propagated to parent elements based on the egui event.
|
||||
if should_stop_propagation {
|
||||
event.stop_propagation();
|
||||
}
|
||||
|
||||
if should_prevent_default {
|
||||
event.prevent_default();
|
||||
}
|
||||
if should_prevent_default {
|
||||
event.prevent_default();
|
||||
}
|
||||
|
||||
// Fix virtual keyboard IOS
|
||||
// Need call focus at the same time of event
|
||||
if runner.text_agent.has_focus() {
|
||||
runner.text_agent.set_focus(false);
|
||||
runner.text_agent.set_focus(true);
|
||||
}
|
||||
// Fix virtual keyboard IOS
|
||||
// Need call focus at the same time of event
|
||||
if runner.text_agent.has_focus() {
|
||||
runner.text_agent.set_focus(false);
|
||||
runner.text_agent.set_focus(true);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -145,18 +145,18 @@ fn canvas_content_rect(canvas: &web_sys::HtmlCanvasElement) -> egui::Rect {
|
||||
);
|
||||
|
||||
// We need to subtract padding and border:
|
||||
if let Some(window) = web_sys::window() {
|
||||
if let Ok(Some(style)) = window.get_computed_style(canvas) {
|
||||
let get_property = |name: &str| -> Option<f32> {
|
||||
let property = style.get_property_value(name).ok()?;
|
||||
property.trim_end_matches("px").parse::<f32>().ok()
|
||||
};
|
||||
if let Some(window) = web_sys::window()
|
||||
&& let Ok(Some(style)) = window.get_computed_style(canvas)
|
||||
{
|
||||
let get_property = |name: &str| -> Option<f32> {
|
||||
let property = style.get_property_value(name).ok()?;
|
||||
property.trim_end_matches("px").parse::<f32>().ok()
|
||||
};
|
||||
|
||||
rect.min.x += get_property("padding-left").unwrap_or_default();
|
||||
rect.min.y += get_property("padding-top").unwrap_or_default();
|
||||
rect.max.x -= get_property("padding-right").unwrap_or_default();
|
||||
rect.max.y -= get_property("padding-bottom").unwrap_or_default();
|
||||
}
|
||||
rect.min.x += get_property("padding-left").unwrap_or_default();
|
||||
rect.min.y += get_property("padding-top").unwrap_or_default();
|
||||
rect.max.x -= get_property("padding-right").unwrap_or_default();
|
||||
rect.max.y -= get_property("padding-bottom").unwrap_or_default();
|
||||
}
|
||||
|
||||
rect
|
||||
|
||||
@@ -192,17 +192,13 @@ fn is_safari_and_webkit_gtk(gl: &web_sys::WebGlRenderingContext) -> bool {
|
||||
.get_extension("WEBGL_debug_renderer_info")
|
||||
.unwrap()
|
||||
.is_some()
|
||||
{
|
||||
if let Ok(renderer) =
|
||||
&& let Ok(renderer) =
|
||||
gl.get_parameter(web_sys::WebglDebugRendererInfo::UNMASKED_RENDERER_WEBGL)
|
||||
{
|
||||
if let Some(renderer) = renderer.as_string() {
|
||||
if renderer.contains("Apple") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
&& let Some(renderer) = renderer.as_string()
|
||||
&& renderer.contains("Apple")
|
||||
{
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
@@ -282,14 +282,12 @@ impl WebPainter for WebPainterWgpu {
|
||||
|
||||
let mut capture_buffer = None;
|
||||
|
||||
if capture {
|
||||
if let Some(capture_state) = &mut self.screen_capture_state {
|
||||
capture_buffer = Some(capture_state.copy_textures(
|
||||
&render_state.device,
|
||||
&output_frame,
|
||||
&mut encoder,
|
||||
));
|
||||
}
|
||||
if capture && let Some(capture_state) = &mut self.screen_capture_state {
|
||||
capture_buffer = Some(capture_state.copy_textures(
|
||||
&render_state.device,
|
||||
&output_frame,
|
||||
&mut encoder,
|
||||
));
|
||||
}
|
||||
|
||||
Some((output_frame, capture_buffer))
|
||||
@@ -301,16 +299,16 @@ impl WebPainter for WebPainterWgpu {
|
||||
.submit(user_cmd_bufs.into_iter().chain([encoder.finish()]));
|
||||
|
||||
if let Some((frame, capture_buffer)) = frame_and_capture_buffer {
|
||||
if let Some(capture_buffer) = capture_buffer {
|
||||
if let Some(capture_state) = &self.screen_capture_state {
|
||||
capture_state.read_screen_rgba(
|
||||
self.ctx.clone(),
|
||||
capture_buffer,
|
||||
capture_data,
|
||||
self.capture_tx.clone(),
|
||||
ViewportId::ROOT,
|
||||
);
|
||||
}
|
||||
if let Some(capture_buffer) = capture_buffer
|
||||
&& let Some(capture_state) = &self.screen_capture_state
|
||||
{
|
||||
capture_state.read_screen_rgba(
|
||||
self.ctx.clone(),
|
||||
capture_buffer,
|
||||
capture_data,
|
||||
self.capture_tx.clone(),
|
||||
ViewportId::ROOT,
|
||||
);
|
||||
}
|
||||
|
||||
frame.present();
|
||||
|
||||
@@ -255,9 +255,7 @@ impl<'a> PanelSizer<'a> {
|
||||
let side = self.panel.side;
|
||||
let size_range = self.panel.size_range;
|
||||
|
||||
if is_resizing && pointer.is_some() {
|
||||
let pointer = pointer.unwrap();
|
||||
|
||||
if is_resizing && let Some(pointer) = pointer {
|
||||
match side {
|
||||
PanelSide::Vertical(side) => {
|
||||
self.size = (pointer.x - side.side_x(self.panel_rect)).abs();
|
||||
@@ -811,9 +809,7 @@ impl Panel {
|
||||
let resize_id = self.id.with("__resize");
|
||||
let resize_response = ui.ctx().read_response(resize_id);
|
||||
|
||||
if resize_response.is_some() {
|
||||
let resize_response = resize_response.unwrap();
|
||||
|
||||
if let Some(resize_response) = resize_response {
|
||||
// NOTE(sharky98): The original code was initializing to
|
||||
// false first, but it doesn't seem necessary.
|
||||
let is_resizing = resize_response.dragged();
|
||||
|
||||
@@ -631,8 +631,10 @@ impl InputState {
|
||||
/// A positive Y-value indicates the content is being moved down, as when swiping down on a touch-screen or track-pad with natural scrolling.
|
||||
#[inline(always)]
|
||||
pub fn translation_delta(&self) -> Vec2 {
|
||||
self.multi_touch()
|
||||
.map_or(self.smooth_scroll_delta(), |touch| touch.translation_delta)
|
||||
self.multi_touch().map_or_else(
|
||||
|| self.smooth_scroll_delta(),
|
||||
|touch| touch.translation_delta,
|
||||
)
|
||||
}
|
||||
|
||||
/// True if there is an active scroll action that might scroll more when using [`Self::smooth_scroll_delta`].
|
||||
|
||||
@@ -1325,7 +1325,7 @@ impl TableRow<'_, '_> {
|
||||
*self.response = Some(
|
||||
self.response
|
||||
.as_ref()
|
||||
.map_or(response.clone(), |r| r.union(response.clone())),
|
||||
.map_or_else(|| response.clone(), |r| r.union(response.clone())),
|
||||
);
|
||||
|
||||
(used_rect, response)
|
||||
|
||||
@@ -12,30 +12,28 @@ Ui testing library for egui, based on [kittest](https://github.com/rerun-io/kitt
|
||||
use egui::accesskit::Toggled;
|
||||
use egui_kittest::{Harness, kittest::{Queryable, NodeT}};
|
||||
|
||||
fn main() {
|
||||
let mut checked = false;
|
||||
let app = |ui: &mut egui::Ui| {
|
||||
ui.checkbox(&mut checked, "Check me!");
|
||||
};
|
||||
let mut checked = false;
|
||||
let app = |ui: &mut egui::Ui| {
|
||||
ui.checkbox(&mut checked, "Check me!");
|
||||
};
|
||||
|
||||
let mut harness = Harness::new_ui(app);
|
||||
let mut harness = Harness::new_ui(app);
|
||||
|
||||
let checkbox = harness.get_by_label("Check me!");
|
||||
assert_eq!(checkbox.accesskit_node().toggled(), Some(Toggled::False));
|
||||
checkbox.click();
|
||||
let checkbox = harness.get_by_label("Check me!");
|
||||
assert_eq!(checkbox.accesskit_node().toggled(), Some(Toggled::False));
|
||||
checkbox.click();
|
||||
|
||||
harness.run();
|
||||
harness.run();
|
||||
|
||||
let checkbox = harness.get_by_label("Check me!");
|
||||
assert_eq!(checkbox.accesskit_node().toggled(), Some(Toggled::True));
|
||||
let checkbox = harness.get_by_label("Check me!");
|
||||
assert_eq!(checkbox.accesskit_node().toggled(), Some(Toggled::True));
|
||||
|
||||
// Shrink the window size to the smallest size possible
|
||||
harness.fit_contents();
|
||||
// Shrink the window size to the smallest size possible
|
||||
harness.fit_contents();
|
||||
|
||||
// You can even render the ui and do image snapshot tests
|
||||
#[cfg(all(feature = "wgpu", feature = "snapshot"))]
|
||||
harness.snapshot("readme_example");
|
||||
}
|
||||
// You can even render the ui and do image snapshot tests
|
||||
#[cfg(all(feature = "wgpu", feature = "snapshot"))]
|
||||
harness.snapshot("readme_example");
|
||||
```
|
||||
|
||||
## Configuration
|
||||
@@ -44,7 +42,7 @@ You can configure test settings via a `kittest.toml` file in your workspace root
|
||||
All possible settings and their defaults:
|
||||
```toml
|
||||
# path to the snapshot directory
|
||||
output_path = "tests/snapshots"
|
||||
output_path = "tests/snapshots"
|
||||
|
||||
# default threshold for image comparison tests
|
||||
threshold = 0.6
|
||||
|
||||
Reference in New Issue
Block a user