Various spelling fixes, docs improvements and code cleanup

This commit is contained in:
Emil Ernerfeldt 2021-03-31 23:12:42 +02:00
parent 1f965d16a2
commit f6770f0183
13 changed files with 36 additions and 34 deletions

View file

@ -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

View file

@ -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");
}
</script>

View file

@ -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<Rect>,
/// 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<f32>,

View file

@ -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;

View file

@ -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<Click>,
/// All button events that occurred this frame
pub(crate) pointer_events: Vec<PointerEvent>,
}

View file

@ -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],

View file

@ -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.

View file

@ -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 {

View file

@ -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;

View file

@ -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<bool>,
}
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 {

View file

@ -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"

View file

@ -83,8 +83,6 @@ fn set_open(open: &mut BTreeSet<String>, 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");

View file

@ -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()
);