Skip to content

Commit a74dff7

Browse files
committed
cargo fmt & clippy
1 parent ffbf96f commit a74dff7

File tree

5 files changed

+33
-40
lines changed

5 files changed

+33
-40
lines changed

egui/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use std::sync::{
77

88
use crate::{
99
animation_manager::AnimationManager,
10-
menu::ContextMenuSystem,
1110
data::output::Output,
1211
frame_state::FrameState,
1312
input_state::*,
1413
layers::GraphicLayers,
14+
menu::ContextMenuSystem,
1515
mutex::{Mutex, MutexGuard},
1616
*,
1717
};

egui/src/context_menu.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

egui/src/menu.rs

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use super::{
2121
Ui, Vec2,
2222
};
2323
use crate::{widgets::*, *};
24-
use epaint::{Stroke, mutex::RwLock};
24+
use epaint::{mutex::RwLock, Stroke};
2525
use std::sync::Arc;
2626

2727
/// What is saved between frames.
@@ -43,7 +43,11 @@ impl BarState {
4343
}
4444
/// Show a menu at pointer if right-clicked response.
4545
/// Should be called from [`Context`] on a [`Response`]
46-
pub fn bar_menu<R>(&mut self, response: &Response, add_contents: impl FnOnce(&mut Ui) -> R) -> Option<InnerResponse<R>> {
46+
pub fn bar_menu<R>(
47+
&mut self,
48+
response: &Response,
49+
add_contents: impl FnOnce(&mut Ui) -> R,
50+
) -> Option<InnerResponse<R>> {
4751
MenuRoot::stationary_click_interaction(response, &mut self.open_menu, response.id);
4852
self.open_menu.show(response, add_contents)
4953
}
@@ -137,11 +141,8 @@ pub(crate) fn menu_ui<'c, R>(
137141
ui.set_max_width(DEFAULT_MENU_WIDTH);
138142
ui.set_style(style);
139143
ui.set_menu_state(Some(menu_state_arc.clone()));
140-
ui.with_layout(
141-
Layout::top_down_justified(Align::LEFT),
142-
add_contents,
143-
)
144-
.inner
144+
ui.with_layout(Layout::top_down_justified(Align::LEFT), add_contents)
145+
.inner
145146
})
146147
.inner
147148
});
@@ -184,7 +185,11 @@ pub(crate) struct ContextMenuSystem {
184185
impl ContextMenuSystem {
185186
/// Show a menu at pointer if right-clicked response.
186187
/// Should be called from [`Context`] on a [`Response`]
187-
pub fn context_menu(&mut self, response: &Response, add_contents: impl FnOnce(&mut Ui)) -> Option<InnerResponse<()>> {
188+
pub fn context_menu(
189+
&mut self,
190+
response: &Response,
191+
add_contents: impl FnOnce(&mut Ui),
192+
) -> Option<InnerResponse<()>> {
188193
MenuRoot::context_click_interaction(response, &mut self.root, response.id);
189194
self.root.show(response, add_contents)
190195
}
@@ -209,7 +214,11 @@ pub(crate) struct MenuRootManager {
209214
impl MenuRootManager {
210215
/// Show a menu at pointer if right-clicked response.
211216
/// Should be called from [`Context`] on a [`Response`]
212-
pub fn show<R>(&mut self, response: &Response, add_contents: impl FnOnce(&mut Ui) -> R) -> Option<InnerResponse<R>> {
217+
pub fn show<R>(
218+
&mut self,
219+
response: &Response,
220+
add_contents: impl FnOnce(&mut Ui) -> R,
221+
) -> Option<InnerResponse<R>> {
213222
if let Some(root) = self.inner.as_mut() {
214223
let (menu_response, inner_response) = root.show(response, add_contents);
215224
if let MenuResponse::Close = menu_response {
@@ -256,7 +265,8 @@ impl MenuRoot {
256265
add_contents: impl FnOnce(&mut Ui) -> R,
257266
) -> (MenuResponse, Option<InnerResponse<R>>) {
258267
if self.id == response.id {
259-
let inner_response = MenuState::show(&response.ctx, &self.menu_state, self.id, add_contents);
268+
let inner_response =
269+
MenuState::show(&response.ctx, &self.menu_state, self.id, add_contents);
260270
let mut menu_state = self.menu_state.write();
261271
menu_state.rect = inner_response.response.rect;
262272

@@ -330,10 +340,7 @@ impl MenuRoot {
330340
}
331341
MenuResponse::Stay
332342
}
333-
fn handle_menu_response(
334-
root: &mut MenuRootManager,
335-
menu_response: MenuResponse,
336-
) {
343+
fn handle_menu_response(root: &mut MenuRootManager, menu_response: MenuResponse) {
337344
match menu_response {
338345
MenuResponse::Create(pos, id) => {
339346
root.inner = Some(MenuRoot::new(pos, id));
@@ -394,15 +401,8 @@ impl SubMenuButton {
394401
self.icon = icon.to_string();
395402
self
396403
}
397-
pub(crate) fn show(
398-
self,
399-
ui: &mut Ui,
400-
menu_state: &MenuState,
401-
sub_id: Id,
402-
) -> Response {
403-
let SubMenuButton {
404-
text, icon, ..
405-
} = self;
404+
pub(crate) fn show(self, ui: &mut Ui, menu_state: &MenuState, sub_id: Id) -> Response {
405+
let SubMenuButton { text, icon, .. } = self;
406406

407407
let text_style = TextStyle::Button;
408408
let sense = Sense::click();
@@ -445,8 +445,10 @@ impl SubMenuButton {
445445
);
446446

447447
let text_color = visuals.text_color();
448-
ui.painter().galley_with_color(text_pos, text_galley, text_color);
449-
ui.painter().galley_with_color(icon_pos, icon_galley, text_color);
448+
ui.painter()
449+
.galley_with_color(text_pos, text_galley, text_color);
450+
ui.painter()
451+
.galley_with_color(icon_pos, icon_galley, text_color);
450452
}
451453
response
452454
}
@@ -470,11 +472,7 @@ impl SubMenu {
470472
add_contents: impl FnOnce(&mut Ui) -> R,
471473
) -> InnerResponse<Option<R>> {
472474
let sub_id = ui.id().with(self.button.index);
473-
let button = self.button.show(
474-
ui,
475-
&*self.parent_state.read(),
476-
sub_id,
477-
);
475+
let button = self.button.show(ui, &*self.parent_state.read(), sub_id);
478476
self.parent_state
479477
.write()
480478
.submenu_button_interaction(ui, sub_id, &button);
@@ -579,11 +577,7 @@ impl MenuState {
579577
}
580578
if let Some(sub_menu) = self.get_current_submenu() {
581579
if let Some(pos) = pointer.hover_pos() {
582-
return Self::points_at_left_of_rect(
583-
pos,
584-
pointer.velocity(),
585-
sub_menu.read().rect,
586-
);
580+
return Self::points_at_left_of_rect(pos, pointer.velocity(), sub_menu.read().rect);
587581
}
588582
}
589583
false

egui/src/ui.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// #![warn(missing_docs)]
22

3+
use epaint::mutex::RwLock;
34
use std::hash::Hash;
45
use std::sync::Arc;
5-
use epaint::mutex::RwLock;
66

77
use crate::{
88
color::*, containers::*, epaint::text::Fonts, layout::*, menu::MenuState, mutex::MutexGuard,

egui_demo_lib/src/apps/demo/context_menu.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,7 @@ impl super::Demo for ContextMenus {
123123

124124
impl super::View for ContextMenus {
125125
fn ui(&mut self, ui: &mut egui::Ui) {
126-
ui.horizontal(|ui| {
127-
ui.text_edit_singleline(&mut self.title)
128-
});
126+
ui.horizontal(|ui| ui.text_edit_singleline(&mut self.title));
129127
ui.horizontal(|ui| {
130128
ui.add(self.example_plot())
131129
.on_hover_text("Right click for options")

0 commit comments

Comments
 (0)