Skip to content

Commit 011c59c

Browse files
authored
Apply nightly clippy suggestions/fixes (#7794)
* Reduce the diff for #7793
1 parent f1e0b2e commit 011c59c

File tree

10 files changed

+190
-204
lines changed

10 files changed

+190
-204
lines changed

.typos.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
[default.extend-words]
66
ime = "ime" # Input Method Editor
77
nknown = "nknown" # part of @55nknown username
8-
isse = "isse" # part of @IsseW username
9-
tye = "tye" # part of @tye-exe username
8+
isse = "isse" # part of @IsseW username
9+
tye = "tye" # part of @tye-exe username
1010
ro = "ro" # read-only, also part of the username @Phen-Ro
1111
typ = "typ" # Often used because `type` is a keyword in Rust
1212

crates/eframe/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ web-sys = { workspace = true, features = [
251251
] }
252252

253253
# optional web:
254-
egui-wgpu = { workspace = true, optional = true, features = ["capture"] } # if wgpu is used, use it without (!) winit
254+
egui-wgpu = { workspace = true, optional = true, features = [
255+
# if wgpu is used, use it without (!) winit:
256+
"capture",
257+
] }
255258
wgpu = { workspace = true, optional = true }
256259

257260
# Native dev dependencies for testing

crates/eframe/src/web/events.rs

Lines changed: 125 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -137,25 +137,24 @@ fn install_keydown(runner_ref: &WebRunner, target: &EventTarget) -> Result<(), J
137137
&& !modifiers.command
138138
// When text agent is focused, it is responsible for handling input events
139139
&& !runner.text_agent.has_focus()
140+
&& let Some(text) = text_from_keyboard_event(&event)
140141
{
141-
if let Some(text) = text_from_keyboard_event(&event) {
142-
let egui_event = egui::Event::Text(text);
143-
let should_stop_propagation =
144-
(runner.web_options.should_stop_propagation)(&egui_event);
145-
let should_prevent_default =
146-
(runner.web_options.should_prevent_default)(&egui_event);
147-
runner.input.raw.events.push(egui_event);
148-
runner.needs_repaint.repaint_asap();
149-
150-
// If this is indeed text, then prevent any other action.
151-
if should_prevent_default {
152-
event.prevent_default();
153-
}
142+
let egui_event = egui::Event::Text(text);
143+
let should_stop_propagation =
144+
(runner.web_options.should_stop_propagation)(&egui_event);
145+
let should_prevent_default =
146+
(runner.web_options.should_prevent_default)(&egui_event);
147+
runner.input.raw.events.push(egui_event);
148+
runner.needs_repaint.repaint_asap();
154149

155-
// Use web options to tell if the event should be propagated to parent elements.
156-
if should_stop_propagation {
157-
event.stop_propagation();
158-
}
150+
// If this is indeed text, then prevent any other action.
151+
if should_prevent_default {
152+
event.prevent_default();
153+
}
154+
155+
// Use web options to tell if the event should be propagated to parent elements.
156+
if should_stop_propagation {
157+
event.stop_propagation();
159158
}
160159
}
161160

@@ -321,30 +320,28 @@ fn install_copy_cut_paste(runner_ref: &WebRunner, target: &EventTarget) -> Resul
321320
return; // The eframe app is not interested
322321
}
323322

324-
if let Some(data) = event.clipboard_data() {
325-
if let Ok(text) = data.get_data("text") {
326-
let text = text.replace("\r\n", "\n");
327-
328-
let mut should_stop_propagation = true;
329-
let mut should_prevent_default = true;
330-
if !text.is_empty() {
331-
let egui_event = egui::Event::Paste(text);
332-
should_stop_propagation =
333-
(runner.web_options.should_stop_propagation)(&egui_event);
334-
should_prevent_default =
335-
(runner.web_options.should_prevent_default)(&egui_event);
336-
runner.input.raw.events.push(egui_event);
337-
runner.needs_repaint.repaint_asap();
338-
}
323+
if let Some(data) = event.clipboard_data()
324+
&& let Ok(text) = data.get_data("text")
325+
{
326+
let text = text.replace("\r\n", "\n");
339327

340-
// Use web options to tell if the web event should be propagated to parent elements based on the egui event.
341-
if should_stop_propagation {
342-
event.stop_propagation();
343-
}
328+
let mut should_stop_propagation = true;
329+
let mut should_prevent_default = true;
330+
if !text.is_empty() {
331+
let egui_event = egui::Event::Paste(text);
332+
should_stop_propagation = (runner.web_options.should_stop_propagation)(&egui_event);
333+
should_prevent_default = (runner.web_options.should_prevent_default)(&egui_event);
334+
runner.input.raw.events.push(egui_event);
335+
runner.needs_repaint.repaint_asap();
336+
}
344337

345-
if should_prevent_default {
346-
event.prevent_default();
347-
}
338+
// Use web options to tell if the web event should be propagated to parent elements based on the egui event.
339+
if should_stop_propagation {
340+
event.stop_propagation();
341+
}
342+
343+
if should_prevent_default {
344+
event.prevent_default();
348345
}
349346
}
350347
})?;
@@ -562,45 +559,44 @@ fn install_pointerup(runner_ref: &WebRunner, target: &EventTarget) -> Result<(),
562559
if is_interested_in_pointer_event(
563560
runner,
564561
egui::pos2(event.client_x() as f32, event.client_y() as f32),
565-
) {
566-
if let Some(button) = button_from_mouse_event(&event) {
567-
let modifiers = runner.input.raw.modifiers;
568-
let egui_event = egui::Event::PointerButton {
569-
pos,
570-
button,
571-
pressed: false,
572-
modifiers,
573-
};
574-
let should_stop_propagation =
575-
(runner.web_options.should_stop_propagation)(&egui_event);
576-
let should_prevent_default =
577-
(runner.web_options.should_prevent_default)(&egui_event);
578-
runner.input.raw.events.push(egui_event);
579-
580-
// Previously on iOS, the canvas would not receive focus on
581-
// any touch event, which resulted in the on-screen keyboard
582-
// not working when focusing on a text field in an egui app.
583-
// This attempts to fix that by forcing the focus on any
584-
// click on the canvas.
585-
runner.canvas().focus().ok();
586-
587-
// In Safari we are only allowed to do certain things
588-
// (like playing audio, start a download, etc)
589-
// on user action, such as a click.
590-
// So we need to run the app logic here and now:
591-
runner.logic();
592-
593-
// Make sure we paint the output of the above logic call asap:
594-
runner.needs_repaint.repaint_asap();
595-
596-
if should_prevent_default {
597-
event.prevent_default();
598-
}
562+
) && let Some(button) = button_from_mouse_event(&event)
563+
{
564+
let modifiers = runner.input.raw.modifiers;
565+
let egui_event = egui::Event::PointerButton {
566+
pos,
567+
button,
568+
pressed: false,
569+
modifiers,
570+
};
571+
let should_stop_propagation =
572+
(runner.web_options.should_stop_propagation)(&egui_event);
573+
let should_prevent_default =
574+
(runner.web_options.should_prevent_default)(&egui_event);
575+
runner.input.raw.events.push(egui_event);
599576

600-
// Use web options to tell if the web event should be propagated to parent elements based on the egui event.
601-
if should_stop_propagation {
602-
event.stop_propagation();
603-
}
577+
// Previously on iOS, the canvas would not receive focus on
578+
// any touch event, which resulted in the on-screen keyboard
579+
// not working when focusing on a text field in an egui app.
580+
// This attempts to fix that by forcing the focus on any
581+
// click on the canvas.
582+
runner.canvas().focus().ok();
583+
584+
// In Safari we are only allowed to do certain things
585+
// (like playing audio, start a download, etc)
586+
// on user action, such as a click.
587+
// So we need to run the app logic here and now:
588+
runner.logic();
589+
590+
// Make sure we paint the output of the above logic call asap:
591+
runner.needs_repaint.repaint_asap();
592+
593+
if should_prevent_default {
594+
event.prevent_default();
595+
}
596+
597+
// Use web options to tell if the web event should be propagated to parent elements based on the egui event.
598+
if should_stop_propagation {
599+
event.stop_propagation();
604600
}
605601
}
606602
},
@@ -713,80 +709,77 @@ fn install_touchstart(runner_ref: &WebRunner, target: &EventTarget) -> Result<()
713709

714710
fn install_touchmove(runner_ref: &WebRunner, target: &EventTarget) -> Result<(), JsValue> {
715711
runner_ref.add_event_listener(target, "touchmove", |event: web_sys::TouchEvent, runner| {
716-
if let Some((pos, touch)) = primary_touch_pos(runner, &event) {
717-
if is_interested_in_pointer_event(
712+
if let Some((pos, touch)) = primary_touch_pos(runner, &event)
713+
&& is_interested_in_pointer_event(
718714
runner,
719715
egui::pos2(touch.client_x() as f32, touch.client_y() as f32),
720-
) {
721-
let egui_event = egui::Event::PointerMoved(pos);
722-
let should_stop_propagation =
723-
(runner.web_options.should_stop_propagation)(&egui_event);
724-
let should_prevent_default =
725-
(runner.web_options.should_prevent_default)(&egui_event);
726-
runner.input.raw.events.push(egui_event);
716+
)
717+
{
718+
let egui_event = egui::Event::PointerMoved(pos);
719+
let should_stop_propagation = (runner.web_options.should_stop_propagation)(&egui_event);
720+
let should_prevent_default = (runner.web_options.should_prevent_default)(&egui_event);
721+
runner.input.raw.events.push(egui_event);
727722

728-
push_touches(runner, egui::TouchPhase::Move, &event);
729-
runner.needs_repaint.repaint();
723+
push_touches(runner, egui::TouchPhase::Move, &event);
724+
runner.needs_repaint.repaint();
730725

731-
// Use web options to tell if the web event should be propagated to parent elements based on the egui event.
732-
if should_stop_propagation {
733-
event.stop_propagation();
734-
}
726+
// Use web options to tell if the web event should be propagated to parent elements based on the egui event.
727+
if should_stop_propagation {
728+
event.stop_propagation();
729+
}
735730

736-
if should_prevent_default {
737-
event.prevent_default();
738-
}
731+
if should_prevent_default {
732+
event.prevent_default();
739733
}
740734
}
741735
})
742736
}
743737

744738
fn install_touchend(runner_ref: &WebRunner, target: &EventTarget) -> Result<(), JsValue> {
745739
runner_ref.add_event_listener(target, "touchend", |event: web_sys::TouchEvent, runner| {
746-
if let Some((pos, touch)) = primary_touch_pos(runner, &event) {
747-
if is_interested_in_pointer_event(
740+
if let Some((pos, touch)) = primary_touch_pos(runner, &event)
741+
&& is_interested_in_pointer_event(
748742
runner,
749743
egui::pos2(touch.client_x() as f32, touch.client_y() as f32),
750-
) {
751-
// First release mouse to click:
752-
let mut should_stop_propagation = true;
753-
let mut should_prevent_default = true;
754-
let egui_event = egui::Event::PointerButton {
755-
pos,
756-
button: egui::PointerButton::Primary,
757-
pressed: false,
758-
modifiers: runner.input.raw.modifiers,
759-
};
760-
should_stop_propagation &=
761-
(runner.web_options.should_stop_propagation)(&egui_event);
762-
should_prevent_default &= (runner.web_options.should_prevent_default)(&egui_event);
763-
runner.input.raw.events.push(egui_event);
764-
// Then remove hover effect:
765-
should_stop_propagation &=
766-
(runner.web_options.should_stop_propagation)(&egui::Event::PointerGone);
767-
should_prevent_default &=
768-
(runner.web_options.should_prevent_default)(&egui::Event::PointerGone);
769-
runner.input.raw.events.push(egui::Event::PointerGone);
744+
)
745+
{
746+
// First release mouse to click:
747+
let mut should_stop_propagation = true;
748+
let mut should_prevent_default = true;
749+
let egui_event = egui::Event::PointerButton {
750+
pos,
751+
button: egui::PointerButton::Primary,
752+
pressed: false,
753+
modifiers: runner.input.raw.modifiers,
754+
};
755+
should_stop_propagation &= (runner.web_options.should_stop_propagation)(&egui_event);
756+
should_prevent_default &= (runner.web_options.should_prevent_default)(&egui_event);
757+
runner.input.raw.events.push(egui_event);
758+
// Then remove hover effect:
759+
should_stop_propagation &=
760+
(runner.web_options.should_stop_propagation)(&egui::Event::PointerGone);
761+
should_prevent_default &=
762+
(runner.web_options.should_prevent_default)(&egui::Event::PointerGone);
763+
runner.input.raw.events.push(egui::Event::PointerGone);
770764

771-
push_touches(runner, egui::TouchPhase::End, &event);
765+
push_touches(runner, egui::TouchPhase::End, &event);
772766

773-
runner.needs_repaint.repaint_asap();
767+
runner.needs_repaint.repaint_asap();
774768

775-
// Use web options to tell if the web event should be propagated to parent elements based on the egui event.
776-
if should_stop_propagation {
777-
event.stop_propagation();
778-
}
769+
// Use web options to tell if the web event should be propagated to parent elements based on the egui event.
770+
if should_stop_propagation {
771+
event.stop_propagation();
772+
}
779773

780-
if should_prevent_default {
781-
event.prevent_default();
782-
}
774+
if should_prevent_default {
775+
event.prevent_default();
776+
}
783777

784-
// Fix virtual keyboard IOS
785-
// Need call focus at the same time of event
786-
if runner.text_agent.has_focus() {
787-
runner.text_agent.set_focus(false);
788-
runner.text_agent.set_focus(true);
789-
}
778+
// Fix virtual keyboard IOS
779+
// Need call focus at the same time of event
780+
if runner.text_agent.has_focus() {
781+
runner.text_agent.set_focus(false);
782+
runner.text_agent.set_focus(true);
790783
}
791784
}
792785
})

crates/eframe/src/web/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,18 @@ fn canvas_content_rect(canvas: &web_sys::HtmlCanvasElement) -> egui::Rect {
145145
);
146146

147147
// We need to subtract padding and border:
148-
if let Some(window) = web_sys::window() {
149-
if let Ok(Some(style)) = window.get_computed_style(canvas) {
150-
let get_property = |name: &str| -> Option<f32> {
151-
let property = style.get_property_value(name).ok()?;
152-
property.trim_end_matches("px").parse::<f32>().ok()
153-
};
154-
155-
rect.min.x += get_property("padding-left").unwrap_or_default();
156-
rect.min.y += get_property("padding-top").unwrap_or_default();
157-
rect.max.x -= get_property("padding-right").unwrap_or_default();
158-
rect.max.y -= get_property("padding-bottom").unwrap_or_default();
159-
}
148+
if let Some(window) = web_sys::window()
149+
&& let Ok(Some(style)) = window.get_computed_style(canvas)
150+
{
151+
let get_property = |name: &str| -> Option<f32> {
152+
let property = style.get_property_value(name).ok()?;
153+
property.trim_end_matches("px").parse::<f32>().ok()
154+
};
155+
156+
rect.min.x += get_property("padding-left").unwrap_or_default();
157+
rect.min.y += get_property("padding-top").unwrap_or_default();
158+
rect.max.x -= get_property("padding-right").unwrap_or_default();
159+
rect.max.y -= get_property("padding-bottom").unwrap_or_default();
160160
}
161161

162162
rect

crates/eframe/src/web/web_painter_glow.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,17 +192,13 @@ fn is_safari_and_webkit_gtk(gl: &web_sys::WebGlRenderingContext) -> bool {
192192
.get_extension("WEBGL_debug_renderer_info")
193193
.unwrap()
194194
.is_some()
195-
{
196-
if let Ok(renderer) =
195+
&& let Ok(renderer) =
197196
gl.get_parameter(web_sys::WebglDebugRendererInfo::UNMASKED_RENDERER_WEBGL)
198-
{
199-
if let Some(renderer) = renderer.as_string() {
200-
if renderer.contains("Apple") {
201-
return true;
202-
}
203-
}
204-
}
197+
&& let Some(renderer) = renderer.as_string()
198+
&& renderer.contains("Apple")
199+
{
200+
true
201+
} else {
202+
false
205203
}
206-
207-
false
208204
}

0 commit comments

Comments
 (0)