mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 23:00:04 -04:00
Use Self everywhere (#3787)
This turns on the clippy lint [`clippy::use_self`](https://rust-lang.github.io/rust-clippy/v0.0.212/index.html#use_self) and fixes it everywhere.
This commit is contained in:
@@ -263,7 +263,7 @@ impl Area {
|
||||
}
|
||||
|
||||
pub(crate) fn begin(self, ctx: &Context) -> Prepared {
|
||||
let Area {
|
||||
let Self {
|
||||
id,
|
||||
movable,
|
||||
order,
|
||||
@@ -458,7 +458,7 @@ impl Prepared {
|
||||
|
||||
#[allow(clippy::needless_pass_by_value)] // intentional to swallow up `content_ui`.
|
||||
pub(crate) fn end(self, ctx: &Context, content_ui: Ui) -> Response {
|
||||
let Prepared {
|
||||
let Self {
|
||||
layer_id,
|
||||
mut state,
|
||||
move_response,
|
||||
|
||||
@@ -45,7 +45,7 @@ impl CollapsingState {
|
||||
}
|
||||
|
||||
pub fn load_with_default_open(ctx: &Context, id: Id, default_open: bool) -> Self {
|
||||
Self::load(ctx, id).unwrap_or(CollapsingState {
|
||||
Self::load(ctx, id).unwrap_or(Self {
|
||||
id,
|
||||
state: InnerState {
|
||||
open: default_open,
|
||||
|
||||
@@ -256,7 +256,7 @@ impl Prepared {
|
||||
pub fn end(self, ui: &mut Ui) -> Response {
|
||||
let paint_rect = self.paint_rect();
|
||||
|
||||
let Prepared {
|
||||
let Self {
|
||||
frame,
|
||||
where_to_put_background,
|
||||
..
|
||||
|
||||
@@ -51,22 +51,22 @@ pub enum Side {
|
||||
impl Side {
|
||||
fn opposite(self) -> Self {
|
||||
match self {
|
||||
Side::Left => Self::Right,
|
||||
Side::Right => Self::Left,
|
||||
Self::Left => Self::Right,
|
||||
Self::Right => Self::Left,
|
||||
}
|
||||
}
|
||||
|
||||
fn set_rect_width(self, rect: &mut Rect, width: f32) {
|
||||
match self {
|
||||
Side::Left => rect.max.x = rect.min.x + width,
|
||||
Side::Right => rect.min.x = rect.max.x - width,
|
||||
Self::Left => rect.max.x = rect.min.x + width,
|
||||
Self::Right => rect.min.x = rect.max.x - width,
|
||||
}
|
||||
}
|
||||
|
||||
fn side_x(self, rect: Rect) -> f32 {
|
||||
match self {
|
||||
Side::Left => rect.left(),
|
||||
Side::Right => rect.right(),
|
||||
Self::Left => rect.left(),
|
||||
Self::Right => rect.right(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -506,22 +506,22 @@ pub enum TopBottomSide {
|
||||
impl TopBottomSide {
|
||||
fn opposite(self) -> Self {
|
||||
match self {
|
||||
TopBottomSide::Top => Self::Bottom,
|
||||
TopBottomSide::Bottom => Self::Top,
|
||||
Self::Top => Self::Bottom,
|
||||
Self::Bottom => Self::Top,
|
||||
}
|
||||
}
|
||||
|
||||
fn set_rect_height(self, rect: &mut Rect, height: f32) {
|
||||
match self {
|
||||
TopBottomSide::Top => rect.max.y = rect.min.y + height,
|
||||
TopBottomSide::Bottom => rect.min.y = rect.max.y - height,
|
||||
Self::Top => rect.max.y = rect.min.y + height,
|
||||
Self::Bottom => rect.min.y = rect.max.y - height,
|
||||
}
|
||||
}
|
||||
|
||||
fn side_y(self, rect: Rect) -> f32 {
|
||||
match self {
|
||||
TopBottomSide::Top => rect.top(),
|
||||
TopBottomSide::Bottom => rect.bottom(),
|
||||
Self::Top => rect.top(),
|
||||
Self::Bottom => rect.bottom(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -692,7 +692,7 @@ impl ScrollArea {
|
||||
impl Prepared {
|
||||
/// Returns content size and state
|
||||
fn end(self, ui: &mut Ui) -> (Vec2, State) {
|
||||
let Prepared {
|
||||
let Self {
|
||||
id,
|
||||
mut state,
|
||||
inner_rect,
|
||||
|
||||
@@ -509,7 +509,7 @@ impl std::fmt::Debug for Context {
|
||||
}
|
||||
|
||||
impl std::cmp::PartialEq for Context {
|
||||
fn eq(&self, other: &Context) -> bool {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
Arc::ptr_eq(&self.0, &other.0)
|
||||
}
|
||||
}
|
||||
@@ -558,7 +558,7 @@ impl Context {
|
||||
/// // handle full_output
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn run(&self, new_input: RawInput, run_ui: impl FnOnce(&Context)) -> FullOutput {
|
||||
pub fn run(&self, new_input: RawInput, run_ui: impl FnOnce(&Self)) -> FullOutput {
|
||||
crate::profile_function!();
|
||||
|
||||
self.begin_frame(new_input);
|
||||
@@ -2675,7 +2675,7 @@ impl Context {
|
||||
/// * Handle the output from [`Context::run`], including rendering
|
||||
#[allow(clippy::unused_self)]
|
||||
pub fn set_immediate_viewport_renderer(
|
||||
callback: impl for<'a> Fn(&Context, ImmediateViewport<'a>) + 'static,
|
||||
callback: impl for<'a> Fn(&Self, ImmediateViewport<'a>) + 'static,
|
||||
) {
|
||||
let callback = Box::new(callback);
|
||||
IMMEDIATE_VIEWPORT_RENDERER.with(|render_sync| {
|
||||
@@ -2752,7 +2752,7 @@ impl Context {
|
||||
&self,
|
||||
new_viewport_id: ViewportId,
|
||||
viewport_builder: ViewportBuilder,
|
||||
viewport_ui_cb: impl Fn(&Context, ViewportClass) + Send + Sync + 'static,
|
||||
viewport_ui_cb: impl Fn(&Self, ViewportClass) + Send + Sync + 'static,
|
||||
) {
|
||||
crate::profile_function!();
|
||||
|
||||
@@ -2804,7 +2804,7 @@ impl Context {
|
||||
&self,
|
||||
new_viewport_id: ViewportId,
|
||||
builder: ViewportBuilder,
|
||||
viewport_ui_cb: impl FnOnce(&Context, ViewportClass) -> T,
|
||||
viewport_ui_cb: impl FnOnce(&Self, ViewportClass) -> T,
|
||||
) -> T {
|
||||
crate::profile_function!();
|
||||
|
||||
|
||||
@@ -104,8 +104,8 @@ impl RawInput {
|
||||
///
|
||||
/// * [`Self::hovered_files`] is cloned.
|
||||
/// * [`Self::dropped_files`] is moved.
|
||||
pub fn take(&mut self) -> RawInput {
|
||||
RawInput {
|
||||
pub fn take(&mut self) -> Self {
|
||||
Self {
|
||||
viewport_id: self.viewport_id,
|
||||
viewports: self.viewports.clone(),
|
||||
screen_rect: self.screen_rect.take(),
|
||||
@@ -692,7 +692,7 @@ impl Modifiers {
|
||||
/// assert!((Modifiers::MAC_CMD | Modifiers::COMMAND).matches_logically(Modifiers::COMMAND));
|
||||
/// assert!(!Modifiers::COMMAND.matches_logically(Modifiers::MAC_CMD));
|
||||
/// ```
|
||||
pub fn matches_logically(&self, pattern: Modifiers) -> bool {
|
||||
pub fn matches_logically(&self, pattern: Self) -> bool {
|
||||
if pattern.alt && !self.alt {
|
||||
return false;
|
||||
}
|
||||
@@ -734,7 +734,7 @@ impl Modifiers {
|
||||
/// assert!((Modifiers::MAC_CMD | Modifiers::COMMAND).matches(Modifiers::COMMAND));
|
||||
/// assert!(!Modifiers::COMMAND.matches(Modifiers::MAC_CMD));
|
||||
/// ```
|
||||
pub fn matches_exact(&self, pattern: Modifiers) -> bool {
|
||||
pub fn matches_exact(&self, pattern: Self) -> bool {
|
||||
// alt and shift must always match the pattern:
|
||||
if pattern.alt != self.alt || pattern.shift != self.shift {
|
||||
return false;
|
||||
@@ -744,7 +744,7 @@ impl Modifiers {
|
||||
}
|
||||
|
||||
#[deprecated = "Renamed `matches_exact`, but maybe you want to use `matches_logically` instead"]
|
||||
pub fn matches(&self, pattern: Modifiers) -> bool {
|
||||
pub fn matches(&self, pattern: Self) -> bool {
|
||||
self.matches_exact(pattern)
|
||||
}
|
||||
|
||||
@@ -755,7 +755,7 @@ impl Modifiers {
|
||||
///
|
||||
/// This takes care to properly handle the difference between
|
||||
/// [`Self::ctrl`], [`Self::command`] and [`Self::mac_cmd`].
|
||||
pub fn cmd_ctrl_matches(&self, pattern: Modifiers) -> bool {
|
||||
pub fn cmd_ctrl_matches(&self, pattern: Self) -> bool {
|
||||
if pattern.mac_cmd {
|
||||
// Mac-specific match:
|
||||
if !self.mac_cmd {
|
||||
@@ -800,12 +800,12 @@ impl Modifiers {
|
||||
/// assert!((Modifiers::CTRL | Modifiers::SHIFT).contains(Modifiers::CTRL));
|
||||
/// assert!(!Modifiers::CTRL.contains(Modifiers::CTRL | Modifiers::SHIFT));
|
||||
/// ```
|
||||
pub fn contains(&self, query: Modifiers) -> bool {
|
||||
if query == Modifiers::default() {
|
||||
pub fn contains(&self, query: Self) -> bool {
|
||||
if query == Self::default() {
|
||||
return true;
|
||||
}
|
||||
|
||||
let Modifiers {
|
||||
let Self {
|
||||
alt,
|
||||
ctrl,
|
||||
shift,
|
||||
@@ -814,27 +814,27 @@ impl Modifiers {
|
||||
} = *self;
|
||||
|
||||
if alt && query.alt {
|
||||
return self.contains(Modifiers {
|
||||
return self.contains(Self {
|
||||
alt: false,
|
||||
..query
|
||||
});
|
||||
}
|
||||
if shift && query.shift {
|
||||
return self.contains(Modifiers {
|
||||
return self.contains(Self {
|
||||
shift: false,
|
||||
..query
|
||||
});
|
||||
}
|
||||
|
||||
if (ctrl || command) && (query.ctrl || query.command) {
|
||||
return self.contains(Modifiers {
|
||||
return self.contains(Self {
|
||||
command: false,
|
||||
ctrl: false,
|
||||
..query
|
||||
});
|
||||
}
|
||||
if (mac_cmd || command) && (query.mac_cmd || query.command) {
|
||||
return self.contains(Modifiers {
|
||||
return self.contains(Self {
|
||||
mac_cmd: false,
|
||||
command: false,
|
||||
..query
|
||||
@@ -1287,13 +1287,13 @@ impl Key {
|
||||
// Before we do we must first make sure they are supported in `Fonts` though,
|
||||
// so perhaps this functions needs to take a `supports_character: impl Fn(char) -> bool` or something.
|
||||
match self {
|
||||
Key::ArrowDown => "⏷",
|
||||
Key::ArrowLeft => "⏴",
|
||||
Key::ArrowRight => "⏵",
|
||||
Key::ArrowUp => "⏶",
|
||||
Key::Minus => crate::MINUS_CHAR_STR,
|
||||
Key::Plus => "+",
|
||||
Key::Equals => "=",
|
||||
Self::ArrowDown => "⏷",
|
||||
Self::ArrowLeft => "⏴",
|
||||
Self::ArrowRight => "⏵",
|
||||
Self::ArrowUp => "⏶",
|
||||
Self::Minus => crate::MINUS_CHAR_STR,
|
||||
Self::Plus => "+",
|
||||
Self::Equals => "=",
|
||||
_ => self.name(),
|
||||
}
|
||||
}
|
||||
@@ -1301,98 +1301,98 @@ impl Key {
|
||||
/// Human-readable English name.
|
||||
pub fn name(self) -> &'static str {
|
||||
match self {
|
||||
Key::ArrowDown => "Down",
|
||||
Key::ArrowLeft => "Left",
|
||||
Key::ArrowRight => "Right",
|
||||
Key::ArrowUp => "Up",
|
||||
Self::ArrowDown => "Down",
|
||||
Self::ArrowLeft => "Left",
|
||||
Self::ArrowRight => "Right",
|
||||
Self::ArrowUp => "Up",
|
||||
|
||||
Key::Escape => "Escape",
|
||||
Key::Tab => "Tab",
|
||||
Key::Backspace => "Backspace",
|
||||
Key::Enter => "Enter",
|
||||
Key::Space => "Space",
|
||||
Self::Escape => "Escape",
|
||||
Self::Tab => "Tab",
|
||||
Self::Backspace => "Backspace",
|
||||
Self::Enter => "Enter",
|
||||
Self::Space => "Space",
|
||||
|
||||
Key::Insert => "Insert",
|
||||
Key::Delete => "Delete",
|
||||
Key::Home => "Home",
|
||||
Key::End => "End",
|
||||
Key::PageUp => "PageUp",
|
||||
Key::PageDown => "PageDown",
|
||||
Self::Insert => "Insert",
|
||||
Self::Delete => "Delete",
|
||||
Self::Home => "Home",
|
||||
Self::End => "End",
|
||||
Self::PageUp => "PageUp",
|
||||
Self::PageDown => "PageDown",
|
||||
|
||||
Key::Copy => "Copy",
|
||||
Key::Cut => "Cut",
|
||||
Key::Paste => "Paste",
|
||||
Self::Copy => "Copy",
|
||||
Self::Cut => "Cut",
|
||||
Self::Paste => "Paste",
|
||||
|
||||
Key::Colon => "Colon",
|
||||
Key::Comma => "Comma",
|
||||
Key::Minus => "Minus",
|
||||
Key::Period => "Period",
|
||||
Key::Plus => "Plus",
|
||||
Key::Equals => "Equals",
|
||||
Key::Semicolon => "Semicolon",
|
||||
Self::Colon => "Colon",
|
||||
Self::Comma => "Comma",
|
||||
Self::Minus => "Minus",
|
||||
Self::Period => "Period",
|
||||
Self::Plus => "Plus",
|
||||
Self::Equals => "Equals",
|
||||
Self::Semicolon => "Semicolon",
|
||||
|
||||
Key::Backslash => "Backslash",
|
||||
Key::OpenBracket => "OpenBracket",
|
||||
Key::CloseBracket => "CloseBracket",
|
||||
Key::Backtick => "Backtick",
|
||||
Self::Backslash => "Backslash",
|
||||
Self::OpenBracket => "OpenBracket",
|
||||
Self::CloseBracket => "CloseBracket",
|
||||
Self::Backtick => "Backtick",
|
||||
|
||||
Key::Num0 => "0",
|
||||
Key::Num1 => "1",
|
||||
Key::Num2 => "2",
|
||||
Key::Num3 => "3",
|
||||
Key::Num4 => "4",
|
||||
Key::Num5 => "5",
|
||||
Key::Num6 => "6",
|
||||
Key::Num7 => "7",
|
||||
Key::Num8 => "8",
|
||||
Key::Num9 => "9",
|
||||
Self::Num0 => "0",
|
||||
Self::Num1 => "1",
|
||||
Self::Num2 => "2",
|
||||
Self::Num3 => "3",
|
||||
Self::Num4 => "4",
|
||||
Self::Num5 => "5",
|
||||
Self::Num6 => "6",
|
||||
Self::Num7 => "7",
|
||||
Self::Num8 => "8",
|
||||
Self::Num9 => "9",
|
||||
|
||||
Key::A => "A",
|
||||
Key::B => "B",
|
||||
Key::C => "C",
|
||||
Key::D => "D",
|
||||
Key::E => "E",
|
||||
Key::F => "F",
|
||||
Key::G => "G",
|
||||
Key::H => "H",
|
||||
Key::I => "I",
|
||||
Key::J => "J",
|
||||
Key::K => "K",
|
||||
Key::L => "L",
|
||||
Key::M => "M",
|
||||
Key::N => "N",
|
||||
Key::O => "O",
|
||||
Key::P => "P",
|
||||
Key::Q => "Q",
|
||||
Key::R => "R",
|
||||
Key::S => "S",
|
||||
Key::T => "T",
|
||||
Key::U => "U",
|
||||
Key::V => "V",
|
||||
Key::W => "W",
|
||||
Key::X => "X",
|
||||
Key::Y => "Y",
|
||||
Key::Z => "Z",
|
||||
Key::F1 => "F1",
|
||||
Key::F2 => "F2",
|
||||
Key::F3 => "F3",
|
||||
Key::F4 => "F4",
|
||||
Key::F5 => "F5",
|
||||
Key::F6 => "F6",
|
||||
Key::F7 => "F7",
|
||||
Key::F8 => "F8",
|
||||
Key::F9 => "F9",
|
||||
Key::F10 => "F10",
|
||||
Key::F11 => "F11",
|
||||
Key::F12 => "F12",
|
||||
Key::F13 => "F13",
|
||||
Key::F14 => "F14",
|
||||
Key::F15 => "F15",
|
||||
Key::F16 => "F16",
|
||||
Key::F17 => "F17",
|
||||
Key::F18 => "F18",
|
||||
Key::F19 => "F19",
|
||||
Key::F20 => "F20",
|
||||
Self::A => "A",
|
||||
Self::B => "B",
|
||||
Self::C => "C",
|
||||
Self::D => "D",
|
||||
Self::E => "E",
|
||||
Self::F => "F",
|
||||
Self::G => "G",
|
||||
Self::H => "H",
|
||||
Self::I => "I",
|
||||
Self::J => "J",
|
||||
Self::K => "K",
|
||||
Self::L => "L",
|
||||
Self::M => "M",
|
||||
Self::N => "N",
|
||||
Self::O => "O",
|
||||
Self::P => "P",
|
||||
Self::Q => "Q",
|
||||
Self::R => "R",
|
||||
Self::S => "S",
|
||||
Self::T => "T",
|
||||
Self::U => "U",
|
||||
Self::V => "V",
|
||||
Self::W => "W",
|
||||
Self::X => "X",
|
||||
Self::Y => "Y",
|
||||
Self::Z => "Z",
|
||||
Self::F1 => "F1",
|
||||
Self::F2 => "F2",
|
||||
Self::F3 => "F3",
|
||||
Self::F4 => "F4",
|
||||
Self::F5 => "F5",
|
||||
Self::F6 => "F6",
|
||||
Self::F7 => "F7",
|
||||
Self::F8 => "F8",
|
||||
Self::F9 => "F9",
|
||||
Self::F10 => "F10",
|
||||
Self::F11 => "F11",
|
||||
Self::F12 => "F12",
|
||||
Self::F13 => "F13",
|
||||
Self::F14 => "F14",
|
||||
Self::F15 => "F15",
|
||||
Self::F16 => "F16",
|
||||
Self::F17 => "F17",
|
||||
Self::F18 => "F18",
|
||||
Self::F19 => "F19",
|
||||
Self::F20 => "F20",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,42 +363,42 @@ pub enum CursorIcon {
|
||||
}
|
||||
|
||||
impl CursorIcon {
|
||||
pub const ALL: [CursorIcon; 35] = [
|
||||
CursorIcon::Default,
|
||||
CursorIcon::None,
|
||||
CursorIcon::ContextMenu,
|
||||
CursorIcon::Help,
|
||||
CursorIcon::PointingHand,
|
||||
CursorIcon::Progress,
|
||||
CursorIcon::Wait,
|
||||
CursorIcon::Cell,
|
||||
CursorIcon::Crosshair,
|
||||
CursorIcon::Text,
|
||||
CursorIcon::VerticalText,
|
||||
CursorIcon::Alias,
|
||||
CursorIcon::Copy,
|
||||
CursorIcon::Move,
|
||||
CursorIcon::NoDrop,
|
||||
CursorIcon::NotAllowed,
|
||||
CursorIcon::Grab,
|
||||
CursorIcon::Grabbing,
|
||||
CursorIcon::AllScroll,
|
||||
CursorIcon::ResizeHorizontal,
|
||||
CursorIcon::ResizeNeSw,
|
||||
CursorIcon::ResizeNwSe,
|
||||
CursorIcon::ResizeVertical,
|
||||
CursorIcon::ResizeEast,
|
||||
CursorIcon::ResizeSouthEast,
|
||||
CursorIcon::ResizeSouth,
|
||||
CursorIcon::ResizeSouthWest,
|
||||
CursorIcon::ResizeWest,
|
||||
CursorIcon::ResizeNorthWest,
|
||||
CursorIcon::ResizeNorth,
|
||||
CursorIcon::ResizeNorthEast,
|
||||
CursorIcon::ResizeColumn,
|
||||
CursorIcon::ResizeRow,
|
||||
CursorIcon::ZoomIn,
|
||||
CursorIcon::ZoomOut,
|
||||
pub const ALL: [Self; 35] = [
|
||||
Self::Default,
|
||||
Self::None,
|
||||
Self::ContextMenu,
|
||||
Self::Help,
|
||||
Self::PointingHand,
|
||||
Self::Progress,
|
||||
Self::Wait,
|
||||
Self::Cell,
|
||||
Self::Crosshair,
|
||||
Self::Text,
|
||||
Self::VerticalText,
|
||||
Self::Alias,
|
||||
Self::Copy,
|
||||
Self::Move,
|
||||
Self::NoDrop,
|
||||
Self::NotAllowed,
|
||||
Self::Grab,
|
||||
Self::Grabbing,
|
||||
Self::AllScroll,
|
||||
Self::ResizeHorizontal,
|
||||
Self::ResizeNeSw,
|
||||
Self::ResizeNwSe,
|
||||
Self::ResizeVertical,
|
||||
Self::ResizeEast,
|
||||
Self::ResizeSouthEast,
|
||||
Self::ResizeSouth,
|
||||
Self::ResizeSouthWest,
|
||||
Self::ResizeWest,
|
||||
Self::ResizeNorthWest,
|
||||
Self::ResizeNorth,
|
||||
Self::ResizeNorthEast,
|
||||
Self::ResizeColumn,
|
||||
Self::ResizeRow,
|
||||
Self::ZoomIn,
|
||||
Self::ZoomOut,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -436,12 +436,12 @@ pub enum OutputEvent {
|
||||
impl OutputEvent {
|
||||
pub fn widget_info(&self) -> &WidgetInfo {
|
||||
match self {
|
||||
OutputEvent::Clicked(info)
|
||||
| OutputEvent::DoubleClicked(info)
|
||||
| OutputEvent::TripleClicked(info)
|
||||
| OutputEvent::FocusGained(info)
|
||||
| OutputEvent::TextSelectionChanged(info)
|
||||
| OutputEvent::ValueChanged(info) => info,
|
||||
Self::Clicked(info)
|
||||
| Self::DoubleClicked(info)
|
||||
| Self::TripleClicked(info)
|
||||
| Self::FocusGained(info)
|
||||
| Self::TextSelectionChanged(info)
|
||||
| Self::ValueChanged(info) => info,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,17 +42,17 @@ impl Id {
|
||||
}
|
||||
|
||||
/// Generate a new [`Id`] by hashing some source (e.g. a string or integer).
|
||||
pub fn new(source: impl std::hash::Hash) -> Id {
|
||||
Id(epaint::ahash::RandomState::with_seeds(1, 2, 3, 4).hash_one(source))
|
||||
pub fn new(source: impl std::hash::Hash) -> Self {
|
||||
Self(epaint::ahash::RandomState::with_seeds(1, 2, 3, 4).hash_one(source))
|
||||
}
|
||||
|
||||
/// Generate a new [`Id`] by hashing the parent [`Id`] and the given argument.
|
||||
pub fn with(self, child: impl std::hash::Hash) -> Id {
|
||||
pub fn with(self, child: impl std::hash::Hash) -> Self {
|
||||
use std::hash::{BuildHasher, Hasher};
|
||||
let mut hasher = epaint::ahash::RandomState::with_seeds(1, 2, 3, 4).build_hasher();
|
||||
hasher.write_u64(self.0);
|
||||
child.hash(&mut hasher);
|
||||
Id(hasher.finish())
|
||||
Self(hasher.finish())
|
||||
}
|
||||
|
||||
/// Short and readable summary
|
||||
|
||||
@@ -149,7 +149,7 @@ impl InputState {
|
||||
mut new: RawInput,
|
||||
requested_repaint_last_frame: bool,
|
||||
pixels_per_point: f32,
|
||||
) -> InputState {
|
||||
) -> Self {
|
||||
crate::profile_function!();
|
||||
|
||||
let time = new.time.unwrap_or(self.time + new.predicted_dt as f64);
|
||||
@@ -212,7 +212,7 @@ impl InputState {
|
||||
keys_down = Default::default();
|
||||
}
|
||||
|
||||
InputState {
|
||||
Self {
|
||||
pointer,
|
||||
touch_states: self.touch_states,
|
||||
scroll_delta,
|
||||
@@ -538,15 +538,15 @@ pub(crate) enum PointerEvent {
|
||||
|
||||
impl PointerEvent {
|
||||
pub fn is_press(&self) -> bool {
|
||||
matches!(self, PointerEvent::Pressed { .. })
|
||||
matches!(self, Self::Pressed { .. })
|
||||
}
|
||||
|
||||
pub fn is_release(&self) -> bool {
|
||||
matches!(self, PointerEvent::Released { .. })
|
||||
matches!(self, Self::Released { .. })
|
||||
}
|
||||
|
||||
pub fn is_click(&self) -> bool {
|
||||
matches!(self, PointerEvent::Released { click: Some(_), .. })
|
||||
matches!(self, Self::Released { click: Some(_), .. })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -634,7 +634,7 @@ impl Default for PointerState {
|
||||
|
||||
impl PointerState {
|
||||
#[must_use]
|
||||
pub(crate) fn begin_frame(mut self, time: f64, new: &RawInput) -> PointerState {
|
||||
pub(crate) fn begin_frame(mut self, time: f64, new: &RawInput) -> Self {
|
||||
self.time = time;
|
||||
|
||||
self.pointer_events.clear();
|
||||
|
||||
@@ -31,7 +31,7 @@ pub enum Order {
|
||||
|
||||
impl Order {
|
||||
const COUNT: usize = 6;
|
||||
const ALL: [Order; Self::COUNT] = [
|
||||
const ALL: [Self; Self::COUNT] = [
|
||||
Self::Background,
|
||||
Self::PanelResizeLine,
|
||||
Self::Middle,
|
||||
|
||||
@@ -88,16 +88,16 @@ impl Direction {
|
||||
#[inline(always)]
|
||||
pub fn is_horizontal(self) -> bool {
|
||||
match self {
|
||||
Direction::LeftToRight | Direction::RightToLeft => true,
|
||||
Direction::TopDown | Direction::BottomUp => false,
|
||||
Self::LeftToRight | Self::RightToLeft => true,
|
||||
Self::TopDown | Self::BottomUp => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn is_vertical(self) -> bool {
|
||||
match self {
|
||||
Direction::LeftToRight | Direction::RightToLeft => false,
|
||||
Direction::TopDown | Direction::BottomUp => true,
|
||||
Self::LeftToRight | Self::RightToLeft => false,
|
||||
Self::TopDown | Self::BottomUp => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,28 +177,28 @@ impl Debug for Bytes {
|
||||
impl From<&'static [u8]> for Bytes {
|
||||
#[inline]
|
||||
fn from(value: &'static [u8]) -> Self {
|
||||
Bytes::Static(value)
|
||||
Self::Static(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<const N: usize> From<&'static [u8; N]> for Bytes {
|
||||
#[inline]
|
||||
fn from(value: &'static [u8; N]) -> Self {
|
||||
Bytes::Static(value)
|
||||
Self::Static(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Arc<[u8]>> for Bytes {
|
||||
#[inline]
|
||||
fn from(value: Arc<[u8]>) -> Self {
|
||||
Bytes::Shared(value)
|
||||
Self::Shared(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<u8>> for Bytes {
|
||||
#[inline]
|
||||
fn from(value: Vec<u8>) -> Self {
|
||||
Bytes::Shared(value.into())
|
||||
Self::Shared(value.into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,8 +206,8 @@ impl AsRef<[u8]> for Bytes {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &[u8] {
|
||||
match self {
|
||||
Bytes::Static(bytes) => bytes,
|
||||
Bytes::Shared(bytes) => bytes,
|
||||
Self::Static(bytes) => bytes,
|
||||
Self::Shared(bytes) => bytes,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -439,16 +439,16 @@ impl TexturePoll {
|
||||
#[inline]
|
||||
pub fn size(&self) -> Option<Vec2> {
|
||||
match self {
|
||||
TexturePoll::Pending { size } => *size,
|
||||
TexturePoll::Ready { texture } => Some(texture.size),
|
||||
Self::Pending { size } => *size,
|
||||
Self::Ready { texture } => Some(texture.size),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn texture_id(&self) -> Option<TextureId> {
|
||||
match self {
|
||||
TexturePoll::Pending { .. } => None,
|
||||
TexturePoll::Ready { texture } => Some(texture.id),
|
||||
Self::Pending { .. } => None,
|
||||
Self::Ready { texture } => Some(texture.id),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,12 +144,9 @@ enum FocusDirection {
|
||||
impl FocusDirection {
|
||||
fn is_cardinal(&self) -> bool {
|
||||
match self {
|
||||
FocusDirection::Up
|
||||
| FocusDirection::Right
|
||||
| FocusDirection::Down
|
||||
| FocusDirection::Left => true,
|
||||
Self::Up | Self::Right | Self::Down | Self::Left => true,
|
||||
|
||||
FocusDirection::Previous | FocusDirection::Next | FocusDirection::None => false,
|
||||
Self::Previous | Self::Next | Self::None => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,11 +359,7 @@ impl MenuRoot {
|
||||
}
|
||||
|
||||
/// Interaction with a context menu (secondary clicks).
|
||||
fn context_interaction(
|
||||
response: &Response,
|
||||
root: &mut Option<MenuRoot>,
|
||||
id: Id,
|
||||
) -> MenuResponse {
|
||||
fn context_interaction(response: &Response, root: &mut Option<Self>, id: Id) -> MenuResponse {
|
||||
let response = response.interact(Sense::click());
|
||||
response.ctx.input(|input| {
|
||||
let pointer = &input.pointer;
|
||||
@@ -389,7 +385,7 @@ impl MenuRoot {
|
||||
fn handle_menu_response(root: &mut MenuRootManager, menu_response: MenuResponse) {
|
||||
match menu_response {
|
||||
MenuResponse::Create(pos, id) => {
|
||||
root.inner = Some(MenuRoot::new(pos, id));
|
||||
root.inner = Some(Self::new(pos, id));
|
||||
}
|
||||
MenuResponse::Close => root.inner = None,
|
||||
MenuResponse::Stay => {}
|
||||
@@ -458,7 +454,7 @@ impl SubMenuButton {
|
||||
}
|
||||
|
||||
pub(crate) fn show(self, ui: &mut Ui, menu_state: &MenuState, sub_id: Id) -> Response {
|
||||
let SubMenuButton { text, icon, .. } = self;
|
||||
let Self { text, icon, .. } = self;
|
||||
|
||||
let text_style = TextStyle::Button;
|
||||
let sense = Sense::click();
|
||||
@@ -655,11 +651,11 @@ impl MenuState {
|
||||
self.sub_menu.as_ref().map(|(id, _)| *id)
|
||||
}
|
||||
|
||||
fn current_submenu(&self) -> Option<&Arc<RwLock<MenuState>>> {
|
||||
fn current_submenu(&self) -> Option<&Arc<RwLock<Self>>> {
|
||||
self.sub_menu.as_ref().map(|(_, sub)| sub)
|
||||
}
|
||||
|
||||
fn submenu(&mut self, id: Id) -> Option<&Arc<RwLock<MenuState>>> {
|
||||
fn submenu(&mut self, id: Id) -> Option<&Arc<RwLock<Self>>> {
|
||||
self.sub_menu
|
||||
.as_ref()
|
||||
.and_then(|(k, sub)| if id == *k { Some(sub) } else { None })
|
||||
@@ -668,7 +664,7 @@ impl MenuState {
|
||||
/// Open submenu at position, if not already open.
|
||||
fn open_submenu(&mut self, id: Id, pos: Pos2) {
|
||||
if !self.is_open(id) {
|
||||
self.sub_menu = Some((id, Arc::new(RwLock::new(MenuState::new(pos)))));
|
||||
self.sub_menu = Some((id, Arc::new(RwLock::new(Self::new(pos)))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1933,14 +1933,14 @@ impl HandleShape {
|
||||
pub fn ui(&mut self, ui: &mut Ui) {
|
||||
ui.label("Widget handle shape");
|
||||
ui.horizontal(|ui| {
|
||||
ui.radio_value(self, HandleShape::Circle, "Circle");
|
||||
ui.radio_value(self, Self::Circle, "Circle");
|
||||
if ui
|
||||
.radio(matches!(self, HandleShape::Rect { .. }), "Rectangle")
|
||||
.radio(matches!(self, Self::Rect { .. }), "Rectangle")
|
||||
.clicked()
|
||||
{
|
||||
*self = HandleShape::Rect { aspect_ratio: 0.5 };
|
||||
*self = Self::Rect { aspect_ratio: 0.5 };
|
||||
}
|
||||
if let HandleShape::Rect { aspect_ratio } = self {
|
||||
if let Self::Rect { aspect_ratio } = self {
|
||||
ui.add(Slider::new(aspect_ratio, 0.1..=3.0).text("Aspect ratio"));
|
||||
}
|
||||
});
|
||||
@@ -1983,8 +1983,8 @@ impl NumericColorSpace {
|
||||
impl std::fmt::Display for NumericColorSpace {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
NumericColorSpace::GammaByte => write!(f, "U8"),
|
||||
NumericColorSpace::Linear => write!(f, "F"),
|
||||
Self::GammaByte => write!(f, "U8"),
|
||||
Self::Linear => write!(f, "F"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#![warn(missing_docs)] // Let's keep `Ui` well-documented.
|
||||
#![allow(clippy::use_self)]
|
||||
|
||||
use std::hash::Hash;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -187,7 +187,7 @@ impl From<IconData> for epaint::ColorImage {
|
||||
width,
|
||||
height,
|
||||
} = icon;
|
||||
epaint::ColorImage::from_rgba_premultiplied([width as usize, height as usize], &rgba)
|
||||
Self::from_rgba_premultiplied([width as usize, height as usize], &rgba)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ impl From<&IconData> for epaint::ColorImage {
|
||||
width,
|
||||
height,
|
||||
} = icon;
|
||||
epaint::ColorImage::from_rgba_premultiplied([*width as usize, *height as usize], rgba)
|
||||
Self::from_rgba_premultiplied([*width as usize, *height as usize], rgba)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -569,8 +569,8 @@ impl ViewportBuilder {
|
||||
/// Update this `ViewportBuilder` with a delta,
|
||||
/// returning a list of commands and a bool intdicating if the window needs to be recreated.
|
||||
#[must_use]
|
||||
pub fn patch(&mut self, new_vp_builder: ViewportBuilder) -> (Vec<ViewportCommand>, bool) {
|
||||
let ViewportBuilder {
|
||||
pub fn patch(&mut self, new_vp_builder: Self) -> (Vec<ViewportCommand>, bool) {
|
||||
let Self {
|
||||
title: new_title,
|
||||
app_id: new_app_id,
|
||||
position: new_position,
|
||||
|
||||
@@ -42,28 +42,28 @@ pub struct RichText {
|
||||
impl From<&str> for RichText {
|
||||
#[inline]
|
||||
fn from(text: &str) -> Self {
|
||||
RichText::new(text)
|
||||
Self::new(text)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&String> for RichText {
|
||||
#[inline]
|
||||
fn from(text: &String) -> Self {
|
||||
RichText::new(text)
|
||||
Self::new(text)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&mut String> for RichText {
|
||||
#[inline]
|
||||
fn from(text: &mut String) -> Self {
|
||||
RichText::new(text.clone())
|
||||
Self::new(text.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for RichText {
|
||||
#[inline]
|
||||
fn from(text: String) -> Self {
|
||||
RichText::new(text)
|
||||
Self::new(text)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -512,7 +512,7 @@ impl RadioButton {
|
||||
|
||||
impl Widget for RadioButton {
|
||||
fn ui(self, ui: &mut Ui) -> Response {
|
||||
let RadioButton { checked, text } = self;
|
||||
let Self { checked, text } = self;
|
||||
|
||||
let spacing = &ui.spacing();
|
||||
let icon_width = spacing.icon_width;
|
||||
|
||||
@@ -31,7 +31,7 @@ impl Link {
|
||||
|
||||
impl Widget for Link {
|
||||
fn ui(self, ui: &mut Ui) -> Response {
|
||||
let Link { text } = self;
|
||||
let Self { text } = self;
|
||||
let label = Label::new(text).sense(Sense::click());
|
||||
|
||||
let (pos, galley, response) = label.layout_in_ui(ui);
|
||||
|
||||
@@ -395,9 +395,9 @@ pub enum ImageFit {
|
||||
impl ImageFit {
|
||||
pub fn resolve(self, available_size: Vec2, image_size: Vec2) -> Vec2 {
|
||||
match self {
|
||||
ImageFit::Original { scale } => image_size * scale,
|
||||
ImageFit::Fraction(fract) => available_size * fract,
|
||||
ImageFit::Exact(size) => size,
|
||||
Self::Original { scale } => image_size * scale,
|
||||
Self::Fraction(fract) => available_size * fract,
|
||||
Self::Exact(size) => size,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ impl ProgressBar {
|
||||
|
||||
impl Widget for ProgressBar {
|
||||
fn ui(self, ui: &mut Ui) -> Response {
|
||||
let ProgressBar {
|
||||
let Self {
|
||||
progress,
|
||||
desired_width,
|
||||
desired_height,
|
||||
|
||||
@@ -87,7 +87,7 @@ impl Separator {
|
||||
|
||||
impl Widget for Separator {
|
||||
fn ui(self, ui: &mut Ui) -> Response {
|
||||
let Separator {
|
||||
let Self {
|
||||
spacing,
|
||||
grow,
|
||||
is_horizontal_line,
|
||||
|
||||
Reference in New Issue
Block a user