1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 14:50:03 -04:00

Improve clippy, and add more docs (#3306)

* Silence a few clippy warnings

* Use named threads

* Remove some deprecated functions

* Document Context and Ui fully

* Use `parking_lot::Mutex` in `eframe`

* Expand clippy.toml files

* build fix
This commit is contained in:
Emil Ernerfeldt
2023-09-05 14:11:22 +02:00
committed by GitHub
parent 436996b79e
commit 67168be069
12 changed files with 119 additions and 23 deletions

View File

@@ -1,4 +1,5 @@
// #![warn(missing_docs)]
#![warn(missing_docs)] // Let's keep `Context` well-documented.
use std::sync::Arc;
use crate::{
@@ -1552,6 +1553,7 @@ impl Context {
}
impl Context {
/// Show a ui for settings (style and tessellation options).
pub fn settings_ui(&self, ui: &mut Ui) {
use crate::containers::*;
@@ -1574,6 +1576,7 @@ impl Context {
});
}
/// Show the state of egui, including its input and output.
pub fn inspection_ui(&self, ui: &mut Ui) {
use crate::containers::*;
crate::trace!(ui);
@@ -1703,6 +1706,7 @@ impl Context {
});
}
/// Shows the contents of [`Self::memory`].
pub fn memory_ui(&self, ui: &mut crate::Ui) {
if ui
.button("Reset all")
@@ -1803,6 +1807,7 @@ impl Context {
}
impl Context {
/// Edit the active [`Style`].
pub fn style_ui(&self, ui: &mut Ui) {
let mut style: Style = (*self.style()).clone();
style.ui(ui);
@@ -1818,6 +1823,8 @@ impl Context {
/// the function is still called, but with no other effect.
///
/// No locks are held while the given closure is called.
#[allow(clippy::unused_self)]
#[inline]
pub fn with_accessibility_parent(&self, _id: Id, f: impl FnOnce()) {
// TODO(emilk): this isn't thread-safe - another thread can call this function between the push/pop calls
#[cfg(feature = "accesskit")]

View File

@@ -1,3 +1,5 @@
/// An `enum` of common operating systems.
#[allow(clippy::upper_case_acronyms)] // `Ios` looks too ugly
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum OperatingSystem {
/// Unknown OS - could be wasm
@@ -26,6 +28,7 @@ impl Default for OperatingSystem {
}
impl OperatingSystem {
/// Uses the compile-time `target_arch` to identify the OS.
pub const fn from_target_os() -> Self {
if cfg!(target_arch = "wasm32") {
Self::Unknown

View File

@@ -1,4 +1,4 @@
// #![warn(missing_docs)]
#![warn(missing_docs)] // Let's keep `Ui` well-documented.
use std::hash::Hash;
use std::sync::Arc;
@@ -249,11 +249,6 @@ impl Ui {
self.painter.is_visible()
}
#[deprecated = "Renamed is_visible"]
pub fn visible(&self) -> bool {
self.painter.is_visible()
}
/// Calling `set_visible(false)` will cause all further widgets to be invisible,
/// yet still allocate space.
///
@@ -281,6 +276,7 @@ impl Ui {
}
}
/// Read the [`Layout`].
#[inline]
pub fn layout(&self) -> &Layout {
self.placer.layout()
@@ -611,6 +607,7 @@ impl Ui {
Id::new(self.next_auto_id_source)
}
/// Same as `ui.next_auto_id().with(id_source)`
pub fn auto_id_with<IdSource>(&self, id_source: IdSource) -> Id
where
IdSource: Hash,
@@ -618,6 +615,7 @@ impl Ui {
Id::new(self.next_auto_id_source).with(id_source)
}
/// Pretend like `count` widgets have been allocated.
pub fn skip_ahead_auto_ids(&mut self, count: usize) {
self.next_auto_id_source = self.next_auto_id_source.wrapping_add(count as u64);
}
@@ -2038,11 +2036,6 @@ impl Ui {
InnerResponse::new(inner, self.interact(rect, child_ui.id, Sense::hover()))
}
#[deprecated = "Use ui.vertical_centered or ui.centered_and_justified"]
pub fn centered<R>(&mut self, add_contents: impl FnOnce(&mut Self) -> R) -> InnerResponse<R> {
self.vertical_centered(add_contents)
}
/// This will make the next added widget centered and justified in the available space.
///
/// Only one widget may be added to the inner `Ui`!