From dd2ce1406ae0e96f8d8bbe97e2ce7f3d5f0c81e5 Mon Sep 17 00:00:00 2001 From: Linus Behrbohm Date: Wed, 29 Sep 2021 22:48:01 +0200 Subject: [PATCH] cargo fmt & clippy --- egui/src/context.rs | 2 +- egui/src/context_menu.rs | 1 + egui/src/menu.rs | 64 ++++++++++----------- egui/src/ui.rs | 2 +- egui_demo_lib/src/apps/demo/context_menu.rs | 4 +- 5 files changed, 33 insertions(+), 40 deletions(-) diff --git a/egui/src/context.rs b/egui/src/context.rs index a2fc89b2d639..caa44962059f 100644 --- a/egui/src/context.rs +++ b/egui/src/context.rs @@ -7,11 +7,11 @@ use std::sync::{ use crate::{ animation_manager::AnimationManager, - menu::ContextMenuSystem, data::output::Output, frame_state::FrameState, input_state::*, layers::GraphicLayers, + menu::ContextMenuSystem, mutex::{Mutex, MutexGuard}, *, }; diff --git a/egui/src/context_menu.rs b/egui/src/context_menu.rs index e69de29bb2d1..8b137891791f 100644 --- a/egui/src/context_menu.rs +++ b/egui/src/context_menu.rs @@ -0,0 +1 @@ + diff --git a/egui/src/menu.rs b/egui/src/menu.rs index d249d83584e4..f071b1b8548b 100644 --- a/egui/src/menu.rs +++ b/egui/src/menu.rs @@ -21,7 +21,7 @@ use super::{ Ui, Vec2, }; use crate::{widgets::*, *}; -use epaint::{Stroke, mutex::RwLock}; +use epaint::{mutex::RwLock, Stroke}; use std::sync::Arc; /// What is saved between frames. @@ -43,7 +43,11 @@ impl BarState { } /// Show a menu at pointer if right-clicked response. /// Should be called from [`Context`] on a [`Response`] - pub fn bar_menu(&mut self, response: &Response, add_contents: impl FnOnce(&mut Ui) -> R) -> Option> { + pub fn bar_menu( + &mut self, + response: &Response, + add_contents: impl FnOnce(&mut Ui) -> R, + ) -> Option> { MenuRoot::stationary_click_interaction(response, &mut self.open_menu, response.id); self.open_menu.show(response, add_contents) } @@ -137,11 +141,8 @@ pub(crate) fn menu_ui<'c, R>( ui.set_max_width(DEFAULT_MENU_WIDTH); ui.set_style(style); ui.set_menu_state(Some(menu_state_arc.clone())); - ui.with_layout( - Layout::top_down_justified(Align::LEFT), - add_contents, - ) - .inner + ui.with_layout(Layout::top_down_justified(Align::LEFT), add_contents) + .inner }) .inner }); @@ -184,7 +185,11 @@ pub(crate) struct ContextMenuSystem { impl ContextMenuSystem { /// Show a menu at pointer if right-clicked response. /// Should be called from [`Context`] on a [`Response`] - pub fn context_menu(&mut self, response: &Response, add_contents: impl FnOnce(&mut Ui)) -> Option> { + pub fn context_menu( + &mut self, + response: &Response, + add_contents: impl FnOnce(&mut Ui), + ) -> Option> { MenuRoot::context_click_interaction(response, &mut self.root, response.id); self.root.show(response, add_contents) } @@ -209,7 +214,11 @@ pub(crate) struct MenuRootManager { impl MenuRootManager { /// Show a menu at pointer if right-clicked response. /// Should be called from [`Context`] on a [`Response`] - pub fn show(&mut self, response: &Response, add_contents: impl FnOnce(&mut Ui) -> R) -> Option> { + pub fn show( + &mut self, + response: &Response, + add_contents: impl FnOnce(&mut Ui) -> R, + ) -> Option> { if let Some(root) = self.inner.as_mut() { let (menu_response, inner_response) = root.show(response, add_contents); if let MenuResponse::Close = menu_response { @@ -256,7 +265,8 @@ impl MenuRoot { add_contents: impl FnOnce(&mut Ui) -> R, ) -> (MenuResponse, Option>) { if self.id == response.id { - let inner_response = MenuState::show(&response.ctx, &self.menu_state, self.id, add_contents); + let inner_response = + MenuState::show(&response.ctx, &self.menu_state, self.id, add_contents); let mut menu_state = self.menu_state.write(); menu_state.rect = inner_response.response.rect; @@ -330,10 +340,7 @@ impl MenuRoot { } MenuResponse::Stay } - fn handle_menu_response( - root: &mut MenuRootManager, - menu_response: MenuResponse, - ) { + fn handle_menu_response(root: &mut MenuRootManager, menu_response: MenuResponse) { match menu_response { MenuResponse::Create(pos, id) => { root.inner = Some(MenuRoot::new(pos, id)); @@ -394,15 +401,8 @@ impl SubMenuButton { self.icon = icon.to_string(); self } - pub(crate) fn show( - self, - ui: &mut Ui, - menu_state: &MenuState, - sub_id: Id, - ) -> Response { - let SubMenuButton { - text, icon, .. - } = self; + pub(crate) fn show(self, ui: &mut Ui, menu_state: &MenuState, sub_id: Id) -> Response { + let SubMenuButton { text, icon, .. } = self; let text_style = TextStyle::Button; let sense = Sense::click(); @@ -445,8 +445,10 @@ impl SubMenuButton { ); let text_color = visuals.text_color(); - ui.painter().galley_with_color(text_pos, text_galley, text_color); - ui.painter().galley_with_color(icon_pos, icon_galley, text_color); + ui.painter() + .galley_with_color(text_pos, text_galley, text_color); + ui.painter() + .galley_with_color(icon_pos, icon_galley, text_color); } response } @@ -470,11 +472,7 @@ impl SubMenu { add_contents: impl FnOnce(&mut Ui) -> R, ) -> InnerResponse> { let sub_id = ui.id().with(self.button.index); - let button = self.button.show( - ui, - &*self.parent_state.read(), - sub_id, - ); + let button = self.button.show(ui, &*self.parent_state.read(), sub_id); self.parent_state .write() .submenu_button_interaction(ui, sub_id, &button); @@ -579,11 +577,7 @@ impl MenuState { } if let Some(sub_menu) = self.get_current_submenu() { if let Some(pos) = pointer.hover_pos() { - return Self::points_at_left_of_rect( - pos, - pointer.velocity(), - sub_menu.read().rect, - ); + return Self::points_at_left_of_rect(pos, pointer.velocity(), sub_menu.read().rect); } } false diff --git a/egui/src/ui.rs b/egui/src/ui.rs index 78b6859f73db..fb19d0666c4e 100644 --- a/egui/src/ui.rs +++ b/egui/src/ui.rs @@ -1,8 +1,8 @@ // #![warn(missing_docs)] +use epaint::mutex::RwLock; use std::hash::Hash; use std::sync::Arc; -use epaint::mutex::RwLock; use crate::{ color::*, containers::*, epaint::text::Fonts, layout::*, menu::MenuState, mutex::MutexGuard, diff --git a/egui_demo_lib/src/apps/demo/context_menu.rs b/egui_demo_lib/src/apps/demo/context_menu.rs index b9143fbc96f6..d06e6fd3a051 100644 --- a/egui_demo_lib/src/apps/demo/context_menu.rs +++ b/egui_demo_lib/src/apps/demo/context_menu.rs @@ -123,9 +123,7 @@ impl super::Demo for ContextMenus { impl super::View for ContextMenus { fn ui(&mut self, ui: &mut egui::Ui) { - ui.horizontal(|ui| { - ui.text_edit_singleline(&mut self.title) - }); + ui.horizontal(|ui| ui.text_edit_singleline(&mut self.title)); ui.horizontal(|ui| { ui.add(self.example_plot()) .on_hover_text("Right click for options")