From f6770f01839cfc67c26ec075d286800ca125324a Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 31 Mar 2021 23:12:42 +0200 Subject: [PATCH] Various spelling fixes, docs improvements and code cleanup --- check.sh | 2 +- docs/index.html | 4 +++- egui/src/data/input.rs | 4 ++-- egui/src/experimental/easy_mark_viewer.rs | 2 +- egui/src/input_state.rs | 8 +++----- egui/src/response.rs | 1 + egui/src/ui.rs | 4 ++-- egui/src/widgets/label.rs | 6 +++--- egui/src/widgets/mod.rs | 2 -- egui/src/widgets/separator.rs | 13 ++++++++++--- egui_demo_lib/src/apps/demo/dancing_strings.rs | 7 +------ egui_demo_lib/src/apps/demo/demo_windows.rs | 8 ++++---- egui_demo_lib/src/apps/demo/tests.rs | 9 +++++---- 13 files changed, 36 insertions(+), 34 deletions(-) diff --git a/check.sh b/check.sh index 1fa28203..4444a9e6 100755 --- a/check.sh +++ b/check.sh @@ -13,7 +13,7 @@ CARGO_INCREMENTAL=0 cargo clippy --workspace --all-targets --all-features -- -D cargo test --workspace --all-targets --all-features cargo fmt --all -- --check -# TODO: doesn't error, but at least prints a warning. +# TODO: make cargo doc produce a proper error (it only prints a warning at the moment). cargo doc -p emath -p epaint -p egui -p eframe -p epi -p egui_web -p egui_glium --lib --no-deps cargo doc -p egui_web --target wasm32-unknown-unknown --lib --no-deps diff --git a/docs/index.html b/docs/index.html index f7659c40..3288e5e4 100644 --- a/docs/index.html +++ b/docs/index.html @@ -65,10 +65,12 @@ // Here we tell bindgen the path to the wasm file so it can start // initialization and return to us a promise when it's done. wasm_bindgen("./egui_demo_app_bg.wasm") - .then(on_wasm_loaded)["catch"](console.error); + .then(on_wasm_loaded) + .catch(console.error); function on_wasm_loaded() { // This call installs a bunch of callbacks and then returns. + console.log("loaded wasm, starting egui app"); wasm_bindgen.start("the_canvas_id"); } diff --git a/egui/src/data/input.rs b/egui/src/data/input.rs index 6523c244..c524fcf6 100644 --- a/egui/src/data/input.rs +++ b/egui/src/data/input.rs @@ -25,8 +25,8 @@ pub struct RawInput { /// `None` will be treated as "same as last frame", with the default being a very big area. pub screen_rect: Option, - /// Also known as device pixel ratio, > 1 for HDPI screens. - /// If text looks blurry on high resolution screens, you probably forgot to set this. + /// Also known as device pixel ratio, > 1 for high resolution screens. + /// If text looks blurry you probably forgot to set this. /// Set this the first frame, whenever it changes, or just on every frame. pub pixels_per_point: Option, diff --git a/egui/src/experimental/easy_mark_viewer.rs b/egui/src/experimental/easy_mark_viewer.rs index d1a5e6fc..58e6aaf2 100644 --- a/egui/src/experimental/easy_mark_viewer.rs +++ b/egui/src/experimental/easy_mark_viewer.rs @@ -38,7 +38,7 @@ pub fn item_ui(ui: &mut Ui, item: easy_mark::Item<'_>) { } easy_mark::Item::Separator => { - ui.add(Separator::new().horizontal()); + ui.add(Separator::default().horizontal()); } easy_mark::Item::Indentation(indent) => { let indent = indent as f32 * one_indent; diff --git a/egui/src/input_state.rs b/egui/src/input_state.rs index 3480139a..94020fa7 100644 --- a/egui/src/input_state.rs +++ b/egui/src/input_state.rs @@ -24,7 +24,7 @@ pub struct InputState { /// Position and size of the egui area. pub screen_rect: Rect, - /// Also known as device pixel ratio, > 1 for HDPI screens. + /// Also known as device pixel ratio, > 1 for high resolution screens. pub pixels_per_point: f32, /// Time in seconds. Relative to whatever. Used for animation. @@ -79,7 +79,7 @@ impl InputState { let unstable_dt = (time - self.time) as f32; let screen_rect = new.screen_rect.unwrap_or_else(|| { if new.screen_size != Default::default() { - Rect::from_min_size(Default::default(), new.screen_size) // backwards compatability + Rect::from_min_size(Default::default(), new.screen_size) // backwards compatibility } else { self.screen_rect } @@ -159,7 +159,7 @@ impl InputState { }) } - /// Also known as device pixel ratio, > 1 for HDPI screens. + /// Also known as device pixel ratio, > 1 for high resolution screens. pub fn pixels_per_point(&self) -> f32 { self.pixels_per_point } @@ -257,8 +257,6 @@ pub struct PointerState { /// Used to check for double-clicks. last_click_time: f64, - // /// All clicks that occurred this frame - // clicks: Vec, /// All button events that occurred this frame pub(crate) pointer_events: Vec, } diff --git a/egui/src/response.rs b/egui/src/response.rs index 7fba5135..438dbad5 100644 --- a/egui/src/response.rs +++ b/egui/src/response.rs @@ -43,6 +43,7 @@ pub struct Response { /// The pointer clicked this thing this frame. pub(crate) clicked: [bool; NUM_POINTER_BUTTONS], + // TODO: `released` for sliders /// The thing was double-clicked. pub(crate) double_clicked: [bool; NUM_POINTER_BUTTONS], diff --git a/egui/src/ui.rs b/egui/src/ui.rs index 097f46d4..1db73f4f 100644 --- a/egui/src/ui.rs +++ b/egui/src/ui.rs @@ -1000,9 +1000,9 @@ impl Ui { response } - /// Shortcut for `add(Separator::new())` (see [`Separator`]). + /// Shortcut for `add(Separator::default())` (see [`Separator`]). pub fn separator(&mut self) -> Response { - self.add(Separator::new()) + self.add(Separator::default()) } /// Modify an angle. The given angle should be in radians, but is shown to the user in degrees. diff --git a/egui/src/widgets/label.rs b/egui/src/widgets/label.rs index bc7dab49..7dedc0b0 100644 --- a/egui/src/widgets/label.rs +++ b/egui/src/widgets/label.rs @@ -268,11 +268,11 @@ impl Label { let dy = if self.raised { -2.0 } else { - let normal_text_heigth = ui.fonts()[TextStyle::Body].row_height(); + let normal_text_height = ui.fonts()[TextStyle::Body].row_height(); let font_height = ui.fonts().row_height(text_style); - (normal_text_heigth - font_height) / 2.0 - 1.0 // center + (normal_text_height - font_height) / 2.0 - 1.0 // center - // normal_text_heigth - font_height // align bottom + // normal_text_height - font_height // align bottom }; if dy != 0.0 { diff --git a/egui/src/widgets/mod.rs b/egui/src/widgets/mod.rs index 67c164b1..1594f01b 100644 --- a/egui/src/widgets/mod.rs +++ b/egui/src/widgets/mod.rs @@ -4,8 +4,6 @@ //! * `ui.add(Label::new("Text").text_color(color::red));` //! * `if ui.add(Button::new("Click me")).clicked() { ... }` -#![allow(clippy::new_without_default)] - use crate::*; mod button; diff --git a/egui/src/widgets/separator.rs b/egui/src/widgets/separator.rs index eaacc1c6..7c79b456 100644 --- a/egui/src/widgets/separator.rs +++ b/egui/src/widgets/separator.rs @@ -8,7 +8,7 @@ use crate::*; /// # let ui = &mut egui::Ui::__test(); /// // These are equivalent: /// ui.separator(); -/// ui.add(egui::Separator::new()); +/// ui.add(egui::Separator::default()); /// ``` #[must_use = "You should put this widget in an ui with `ui.add(widget);`"] pub struct Separator { @@ -16,13 +16,20 @@ pub struct Separator { is_horizontal_line: Option, } -impl Separator { - pub fn new() -> Self { +impl Default for Separator { + fn default() -> Self { Self { spacing: 6.0, is_horizontal_line: None, } } +} + +impl Separator { + #[deprecated = "Use Separator::default() instead"] + pub fn new() -> Self { + Self::default() + } /// How much space we take up. The line is painted in the middle of this. pub fn spacing(mut self, spacing: f32) -> Self { diff --git a/egui_demo_lib/src/apps/demo/dancing_strings.rs b/egui_demo_lib/src/apps/demo/dancing_strings.rs index 296cea83..d96ecb1e 100644 --- a/egui_demo_lib/src/apps/demo/dancing_strings.rs +++ b/egui_demo_lib/src/apps/demo/dancing_strings.rs @@ -1,15 +1,10 @@ use egui::{containers::*, *}; +#[derive(Default)] #[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "persistence", serde(default))] pub struct DancingStrings {} -impl Default for DancingStrings { - fn default() -> Self { - Self {} - } -} - impl super::Demo for DancingStrings { fn name(&self) -> &'static str { "♫ Dancing Strings" diff --git a/egui_demo_lib/src/apps/demo/demo_windows.rs b/egui_demo_lib/src/apps/demo/demo_windows.rs index 119a0294..dd20b9d3 100644 --- a/egui_demo_lib/src/apps/demo/demo_windows.rs +++ b/egui_demo_lib/src/apps/demo/demo_windows.rs @@ -83,8 +83,6 @@ fn set_open(open: &mut BTreeSet, key: &'static str, is_open: bool) { #[cfg_attr(feature = "persistence", serde(default))] pub struct DemoWindows { open_windows: OpenWindows, - - /// open, title, view demos: Demos, } @@ -115,6 +113,10 @@ impl DemoWindows { ui.heading("Windows:"); self.demos.checkboxes(ui); + + ui.separator(); + + ui.label("egui:"); self.open_windows.checkboxes(ui); ui.separator(); @@ -209,8 +211,6 @@ impl OpenWindows { memory, } = self; - ui.separator(); - ui.label("egui:"); ui.checkbox(settings, "🔧 Settings"); ui.checkbox(inspection, "🔍 Inspection"); ui.checkbox(memory, "📝 Memory"); diff --git a/egui_demo_lib/src/apps/demo/tests.rs b/egui_demo_lib/src/apps/demo/tests.rs index d7da92a3..dbebc633 100644 --- a/egui_demo_lib/src/apps/demo/tests.rs +++ b/egui_demo_lib/src/apps/demo/tests.rs @@ -16,13 +16,14 @@ impl super::Demo for CursorTest { impl super::View for CursorTest { fn ui(&mut self, ui: &mut egui::Ui) { - ui.heading("Hover to switch cursor icon:"); ui.vertical_centered_justified(|ui| { + ui.heading("Hover to switch cursor icon:"); for &cursor_icon in &egui::CursorIcon::ALL { let _ = ui .button(format!("{:?}", cursor_icon)) .on_hover_cursor(cursor_icon); } + ui.add(crate::__egui_github_link_file!()); }); } } @@ -295,14 +296,14 @@ impl super::View for InputTest { egui::PointerButton::Middle, ] { if response.clicked_by(button) { - new_info += &format!("Clicked by {:?}\n", button); + new_info += &format!("Clicked by {:?} button\n", button); } if response.double_clicked_by(button) { - new_info += &format!("Double-clicked by {:?}\n", button); + new_info += &format!("Double-clicked by {:?} button\n", button); } if response.dragged_by(button) { new_info += &format!( - "Dragged by {:?}, delta: {:?}\n", + "Dragged by {:?} button, delta: {:?}\n", button, response.drag_delta() );