Skip to content

Commit

Permalink
Remove wildcard imports (emilk#5018)
Browse files Browse the repository at this point in the history
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to test and add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review your PR, but my time is limited!
-->

I removed (I hope so) all wildcard imports I found.

For me on my pc this improved the build time:
- for egui -5s
- for eframe -12s

* [x] I have followed the instructions in the PR template
  • Loading branch information
bircni authored and 486c committed Oct 9, 2024
1 parent 6460e45 commit 0a9144f
Show file tree
Hide file tree
Showing 99 changed files with 423 additions and 208 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ unused_qualifications = "allow"
[workspace.lints.rustdoc]
all = "warn"
missing_crate_level_docs = "warn"
broken_intra_doc_links = "warn"

# See also clippy.toml
[workspace.lints.clippy]
Expand Down Expand Up @@ -248,6 +249,7 @@ use_self = "warn"
useless_transmute = "warn"
verbose_file_reads = "warn"
wildcard_dependencies = "warn"
wildcard_imports = "warn"
zero_sized_map_values = "warn"

# TODO(emilk): enable more of these lints:
Expand All @@ -262,4 +264,3 @@ unwrap_used = "allow" # TODO(emilk): We really wanna warn on thi
manual_range_contains = "allow" # this one is just worse imho
self_named_module_files = "allow" # Disabled waiting on https://github.com/rust-lang/rust-clippy/issues/9602
significant_drop_tightening = "allow" # Too many false positives
wildcard_imports = "allow" # we do this a lot in egui
2 changes: 1 addition & 1 deletion crates/ecolor/src/cint_impl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::*;
use super::{linear_f32_from_linear_u8, linear_u8_from_linear_f32, Color32, Hsva, HsvaGamma, Rgba};
use cint::{Alpha, ColorInterop, EncodedSrgb, Hsv, LinearSrgb, PremultipliedAlpha};

// ---- Color32 ----
Expand Down
2 changes: 1 addition & 1 deletion crates/eframe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,4 +474,4 @@ mod profiling_scopes {
}

#[allow(unused_imports)]
pub(crate) use profiling_scopes::*;
pub(crate) use profiling_scopes::{profile_function, profile_scope};
12 changes: 7 additions & 5 deletions crates/eframe/src/native/glow_integration.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Note that this file contains code very similar to [`wgpu_integration`].
//! Note that this file contains code very similar to [`super::wgpu_integration`].
//! When making changes to one you often also want to apply it to the other.
//!
//! This is also very complex code, and not very pretty.
Expand Down Expand Up @@ -36,13 +36,13 @@ use egui::{
use egui_winit::accesskit_winit;

use crate::{
native::{epi_integration::EpiIntegration, winit_integration::create_egui_context},
App, AppCreator, CreationContext, NativeOptions, Result, Storage,
native::epi_integration::EpiIntegration, App, AppCreator, CreationContext, NativeOptions,
Result, Storage,
};

use super::{
winit_integration::{EventResult, UserEvent, WinitApp},
*,
epi_integration, event_loop_context,
winit_integration::{create_egui_context, EventResult, UserEvent, WinitApp},
};

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -462,6 +462,8 @@ impl WinitApp for GlowWinitApp {

#[cfg(feature = "accesskit")]
fn on_accesskit_event(&mut self, event: accesskit_winit::Event) -> crate::Result<EventResult> {
use super::winit_integration;

if let Some(running) = &self.running {
let mut glutin = running.glutin.borrow_mut();
if let Some(viewport_id) = glutin.viewport_from_window.get(&event.window_id).copied() {
Expand Down
4 changes: 2 additions & 2 deletions crates/eframe/src/native/wgpu_integration.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Note that this file contains code very similar to [`glow_integration`].
//! Note that this file contains code very similar to [`super::glow_integration`].
//! When making changes to one you often also want to apply it to the other.
//!
//! This is also very complex code, and not very pretty.
Expand Down Expand Up @@ -29,7 +29,7 @@ use crate::{
App, AppCreator, CreationContext, NativeOptions, Result, Storage,
};

use super::{winit_integration::WinitApp, *};
use super::{epi_integration, event_loop_context, winit_integration, winit_integration::WinitApp};

// ----------------------------------------------------------------------------
// Types:
Expand Down
7 changes: 6 additions & 1 deletion crates/eframe/src/web/events.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use super::*;
use super::{
button_from_mouse_event, location_hash, modifiers_from_kb_event, modifiers_from_mouse_event,
modifiers_from_wheel_event, pos_from_mouse_event, prefers_color_scheme_dark, primary_touch_pos,
push_touches, text_from_keyboard_event, theme_from_dark_mode, translate_key, AppRunner,
Closure, JsCast, JsValue, WebRunner,
};
use web_sys::EventTarget;

// TODO(emilk): there are more calls to `prevent_default` and `stop_propagaton`
Expand Down
6 changes: 5 additions & 1 deletion crates/eframe/src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ pub use backend::*;
use wasm_bindgen::prelude::*;
use web_sys::MediaQueryList;

use input::*;
use input::{
button_from_mouse_event, modifiers_from_kb_event, modifiers_from_mouse_event,
modifiers_from_wheel_event, pos_from_mouse_event, primary_touch_pos, push_touches,
text_from_keyboard_event, translate_key,
};

// ----------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion crates/egui-wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,4 @@ mod profiling_scopes {
}

#[allow(unused_imports)]
pub(crate) use profiling_scopes::*;
pub(crate) use profiling_scopes::{profile_function, profile_scope};
2 changes: 1 addition & 1 deletion crates/egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use ahash::HashSet;
use raw_window_handle::HasDisplayHandle;

#[allow(unused_imports)]
pub(crate) use profiling_scopes::*;
pub(crate) use profiling_scopes::{profile_function, profile_scope};

use winit::{
dpi::{PhysicalPosition, PhysicalSize},
Expand Down
13 changes: 8 additions & 5 deletions crates/egui/src/containers/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
//! It has no frame or own size. It is potentially movable.
//! It is the foundation for windows and popups.
use crate::*;
use crate::{
emath, pos2, Align2, Context, Id, InnerResponse, LayerId, NumExt, Order, Pos2, Rect, Response,
Sense, Ui, UiBuilder, UiKind, UiStackInfo, Vec2, WidgetRect, WidgetWithState,
};

/// State of an [`Area`] that is persisted between frames.
///
Expand All @@ -21,8 +24,8 @@ pub struct AreaState {
///
/// Area size is intentionally NOT persisted between sessions,
/// so that a bad tooltip or menu size won't be remembered forever.
/// A resizable [`Window`] remembers the size the user picked using
/// the state in the [`Resize`] container.
/// A resizable [`crate::Window`] remembers the size the user picked using
/// the state in the [`crate::Resize`] container.
#[cfg_attr(feature = "serde", serde(skip))]
pub size: Option<Vec2>,

Expand Down Expand Up @@ -83,7 +86,7 @@ impl AreaState {

/// An area on the screen that can be moved by dragging.
///
/// This forms the base of the [`Window`] container.
/// This forms the base of the [`crate::Window`] container.
///
/// ```
/// # egui::__run_test_ctx(|ctx| {
Expand Down Expand Up @@ -232,7 +235,7 @@ impl Area {
/// If the contents are smaller than this size, the area will shrink to fit the contents.
/// If the contents overflow, the area will grow.
///
/// If not set, [`style::Spacing::default_area_size`] will be used.
/// If not set, [`crate::style::Spacing::default_area_size`] will be used.
#[inline]
pub fn default_size(mut self, default_size: impl Into<Vec2>) -> Self {
self.default_size = default_size.into();
Expand Down
7 changes: 5 additions & 2 deletions crates/egui/src/containers/collapsing_header.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::hash::Hash;

use crate::*;
use crate::{
emath, epaint, pos2, remap, remap_clamp, vec2, Context, Id, InnerResponse, NumExt, Rect,
Response, Sense, Stroke, TextStyle, TextWrapMode, Ui, Vec2, WidgetInfo, WidgetText, WidgetType,
};
use epaint::Shape;

#[derive(Clone, Copy, Debug)]
Expand All @@ -15,7 +18,7 @@ pub(crate) struct InnerState {

/// This is a a building block for building collapsing regions.
///
/// It is used by [`CollapsingHeader`] and [`Window`], but can also be used on its own.
/// It is used by [`CollapsingHeader`] and [`crate::Window`], but can also be used on its own.
///
/// See [`CollapsingState::show_header`] for how to show a collapsing header with a custom header.
#[derive(Clone, Debug)]
Expand Down
8 changes: 6 additions & 2 deletions crates/egui/src/containers/combo_box.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use epaint::Shape;

use crate::{style::WidgetVisuals, *};
use crate::{
epaint, style::WidgetVisuals, vec2, Align2, Context, Id, InnerResponse, NumExt, Painter,
PopupCloseBehavior, Rect, Response, ScrollArea, Sense, Stroke, TextStyle, TextWrapMode, Ui,
UiBuilder, Vec2, WidgetInfo, WidgetText, WidgetType,
};

#[allow(unused_imports)] // Documentation
use crate::style::Spacing;
Expand Down Expand Up @@ -150,7 +154,7 @@ impl ComboBox {

/// Controls the wrap mode used for the selected text.
///
/// By default, [`Ui::wrap_mode`] will be used, which can be overridden with [`Style::wrap_mode`].
/// By default, [`Ui::wrap_mode`] will be used, which can be overridden with [`crate::Style::wrap_mode`].
///
/// Note that any `\n` in the text will always produce a new line.
#[inline]
Expand Down
7 changes: 5 additions & 2 deletions crates/egui/src/containers/frame.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Frame container
use crate::{layers::ShapeIdx, *};
use epaint::*;
use crate::{
epaint, layers::ShapeIdx, InnerResponse, Response, Sense, Style, Ui, UiBuilder, UiKind,
UiStackInfo,
};
use epaint::{Color32, Margin, Rect, Rounding, Shadow, Shape, Stroke};

/// Add a background, frame and/or margin to a rectangular background of a [`Ui`].
///
Expand Down
25 changes: 14 additions & 11 deletions crates/egui/src/containers/panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! Panels can either be a child of a [`Ui`] (taking up a portion of the parent)
//! or be top-level (taking up a portion of the whole screen).
//!
//! Together with [`Window`] and [`Area`]:s, top-level panels are
//! Together with [`crate::Window`] and [`crate::Area`]:s, top-level panels are
//! the only places where you can put you widgets.
//!
//! The order in which you add panels matter!
Expand All @@ -13,9 +13,12 @@
//!
//! ⚠ Always add any [`CentralPanel`] last.
//!
//! Add your [`Window`]:s after any top-level panels.
//! Add your [`crate::Window`]:s after any top-level panels.
use crate::*;
use crate::{
lerp, vec2, Align, Context, CursorIcon, Frame, Id, InnerResponse, LayerId, Layout, NumExt,
Rangef, Rect, Sense, Stroke, Ui, UiBuilder, UiKind, UiStackInfo, Vec2,
};

fn animate_expansion(ctx: &Context, id: Id, is_expanded: bool) -> f32 {
ctx.animate_bool_responsive(id, is_expanded)
Expand Down Expand Up @@ -135,9 +138,9 @@ impl SidePanel {
/// If you want your panel to be resizable you also need a widget in it that
/// takes up more space as you resize it, such as:
/// * Wrapping text ([`Ui::horizontal_wrapped`]).
/// * A [`ScrollArea`].
/// * A [`Separator`].
/// * A [`TextEdit`].
/// * A [`crate::ScrollArea`].
/// * A [`crate::Separator`].
/// * A [`crate::TextEdit`].
/// * …
#[inline]
pub fn resizable(mut self, resizable: bool) -> Self {
Expand Down Expand Up @@ -613,9 +616,9 @@ impl TopBottomPanel {
/// If you want your panel to be resizable you also need a widget in it that
/// takes up more space as you resize it, such as:
/// * Wrapping text ([`Ui::horizontal_wrapped`]).
/// * A [`ScrollArea`].
/// * A [`Separator`].
/// * A [`TextEdit`].
/// * A [`crate::ScrollArea`].
/// * A [`crate::Separator`].
/// * A [`crate::TextEdit`].
/// * …
#[inline]
pub fn resizable(mut self, resizable: bool) -> Self {
Expand All @@ -633,7 +636,7 @@ impl TopBottomPanel {
}

/// The initial height of the [`TopBottomPanel`], including margins.
/// Defaults to [`style::Spacing::interact_size`].y, plus frame margins.
/// Defaults to [`crate::style::Spacing::interact_size`].y, plus frame margins.
#[inline]
pub fn default_height(mut self, default_height: f32) -> Self {
self.default_height = Some(default_height);
Expand Down Expand Up @@ -1041,7 +1044,7 @@ impl TopBottomPanel {
///
/// ⚠ [`CentralPanel`] must be added after all other panels!
///
/// NOTE: Any [`Window`]s and [`Area`]s will cover the top-level [`CentralPanel`].
/// NOTE: Any [`crate::Window`]s and [`crate::Area`]s will cover the top-level [`CentralPanel`].
///
/// See the [module level docs](crate::containers::panel) for more details.
///
Expand Down
12 changes: 8 additions & 4 deletions crates/egui/src/containers/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
use frame_state::PerWidgetTooltipState;

use crate::*;
use crate::{
frame_state, vec2, AboveOrBelow, Align, Align2, Area, AreaState, Context, Frame, Id,
InnerResponse, Key, LayerId, Layout, Order, Pos2, Rect, Response, Sense, Ui, UiKind, Vec2,
Widget, WidgetText,
};

// ----------------------------------------------------------------------------

Expand Down Expand Up @@ -322,14 +326,14 @@ pub fn was_tooltip_open_last_frame(ctx: &Context, widget_id: Id) -> bool {
pub enum PopupCloseBehavior {
/// Popup will be closed on click anywhere, inside or outside the popup.
///
/// It is used in [`ComboBox`].
/// It is used in [`crate::ComboBox`].
CloseOnClick,

/// Popup will be closed if the click happened somewhere else
/// but in the popup's body
CloseOnClickOutside,

/// Clicks will be ignored. Popup might be closed manually by calling [`Memory::close_popup`]
/// Clicks will be ignored. Popup might be closed manually by calling [`crate::Memory::close_popup`]
/// or by pressing the escape button
IgnoreClicks,
}
Expand Down Expand Up @@ -358,7 +362,7 @@ pub fn popup_below_widget<R>(
///
/// The opened popup will have a minimum width matching its parent.
///
/// You must open the popup with [`Memory::open_popup`] or [`Memory::toggle_popup`].
/// You must open the popup with [`crate::Memory::open_popup`] or [`crate::Memory::toggle_popup`].
///
/// Returns `None` if the popup is not open.
///
Expand Down
7 changes: 5 additions & 2 deletions crates/egui/src/containers/resize.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::*;
use crate::{
pos2, vec2, Align2, Color32, Context, CursorIcon, Id, NumExt, Rect, Response, Sense, Shape, Ui,
UiBuilder, UiKind, UiStackInfo, Vec2, Vec2b,
};

#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
Expand Down Expand Up @@ -88,7 +91,7 @@ impl Resize {
/// Preferred / suggested height. Actual height will depend on contents.
///
/// Examples:
/// * if the contents is a [`ScrollArea`] then this decides the maximum size.
/// * if the contents is a [`crate::ScrollArea`] then this decides the maximum size.
/// * if the contents is a canvas, this decides the height of it,
/// * if the contents is text and buttons, then the `default_height` is ignored
/// and the height is picked automatically..
Expand Down
9 changes: 6 additions & 3 deletions crates/egui/src/containers/scroll_area.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#![allow(clippy::needless_range_loop)]

use crate::*;
use crate::{
emath, epaint, frame_state, lerp, pos2, remap, remap_clamp, vec2, Context, Id, NumExt, Pos2,
Rangef, Rect, Sense, Ui, UiBuilder, UiKind, UiStackInfo, Vec2, Vec2b,
};

#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
Expand Down Expand Up @@ -157,7 +160,7 @@ impl ScrollBarVisibility {
/// # });
/// ```
///
/// You can scroll to an element using [`Response::scroll_to_me`], [`Ui::scroll_to_cursor`] and [`Ui::scroll_to_rect`].
/// You can scroll to an element using [`crate::Response::scroll_to_me`], [`Ui::scroll_to_cursor`] and [`Ui::scroll_to_rect`].
#[derive(Clone, Debug)]
#[must_use = "You should call .show()"]
pub struct ScrollArea {
Expand Down Expand Up @@ -367,7 +370,7 @@ impl ScrollArea {
/// * If `false`, the scroll area will not respond to user scrolling.
///
/// This can be used, for example, to optionally freeze scrolling while the user
/// is typing text in a [`TextEdit`] widget contained within the scroll area.
/// is typing text in a [`crate::TextEdit`] widget contained within the scroll area.
///
/// This controls both scrolling directions.
#[inline]
Expand Down
9 changes: 6 additions & 3 deletions crates/egui/src/containers/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
use std::sync::Arc;

use crate::collapsing_header::CollapsingState;
use crate::*;
use epaint::*;
use crate::{
Align, Align2, Context, CursorIcon, Id, InnerResponse, LayerId, NumExt, Order, Response, Sense,
TextStyle, Ui, UiKind, Vec2b, WidgetRect, WidgetText,
};
use epaint::{emath, pos2, vec2, Galley, Pos2, Rect, RectShape, Rounding, Shape, Stroke, Vec2};

use super::*;
use super::{area, resize, Area, Frame, Resize, ScrollArea};

/// Builder for a floating window which can be dragged, closed, collapsed, resized and scrolled (off by default).
///
Expand Down
Loading

0 comments on commit 0a9144f

Please sign in to comment.