Skip to content

Commit

Permalink
Update egui and fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmerlin committed Dec 19, 2024
1 parent de250ea commit 7a3fdee
Show file tree
Hide file tree
Showing 13 changed files with 855 additions and 557 deletions.
1,289 changes: 806 additions & 483 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ egui_thumbhash = { path = "./crates/egui_thumbhash", version = "0.5.0" }
egui_material_icons = { path = "./crates/egui_material_icons", version = "0.1.0" }
hello_egui = { path = ".", version = "0.6.0" }

egui = { version = "0.29", default-features = false }
egui_kittest = { version = "0.29" }
eframe = { version = "0.29", default-features = false }
egui_extras = { version = "0.29", default-features = false }
egui = { version = "0.30.0", default-features = false }
egui_kittest = { version = "0.30" }
eframe = { version = "0.30.0", default-features = false }
egui_extras = { version = "0.30.0", default-features = false }
rand = "0.8.5"
simple-easing = "1"
serde_json = "1"
Expand Down Expand Up @@ -135,7 +135,7 @@ doc_markdown = { level = "allow", priority = 21 }
#winit = { path = "../../IdeaProjects/github/winit" }

#
egui = { git = "https://github.com/emilk/egui", branch = "master" }
eframe = { git = "https://github.com/emilk/egui", branch = "master" }
egui_extras = { git = "https://github.com/emilk/egui", branch = "master" }
egui_kittest = { git = "https://github.com/emilk/egui", branch = "master" }
#egui = { git = "https://github.com/emilk/egui", branch = "master" }
#eframe = { git = "https://github.com/emilk/egui", branch = "master" }
#egui_extras = { git = "https://github.com/emilk/egui", branch = "master" }
#egui_kittest = { git = "https://github.com/emilk/egui", branch = "master" }
3 changes: 3 additions & 0 deletions crates/egui_dnd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ impl<'a> Dnd<'a> {
items: impl Iterator<Item = T>,
mut item_ui: impl FnMut(&mut Ui, T, Handle, ItemState),
) -> DragDropResponse {
#[allow(clippy::used_underscore_items)]
self._show_with_inner(|_id, ui, drag_drop_ui| {
drag_drop_ui.ui(ui, |ui, iter| {
items.enumerate().for_each(|(i, item)| {
Expand All @@ -159,6 +160,7 @@ impl<'a> Dnd<'a> {
size: egui::Vec2,
mut item_ui: impl FnMut(&mut Ui, T, Handle, ItemState),
) -> DragDropResponse {
#[allow(clippy::used_underscore_items)]
self._show_with_inner(|_id, ui, drag_drop_ui| {
drag_drop_ui.ui(ui, |ui, iter| {
items.enumerate().for_each(|(i, item)| {
Expand Down Expand Up @@ -198,6 +200,7 @@ impl<'a> Dnd<'a> {
/// This will allow for very flexible UI. You can use it to e.g. render outlines around items
/// or render items in complex layouts. This is **experimental**.
pub fn show_custom(self, f: impl FnOnce(&mut Ui, &mut ItemIterator)) -> DragDropResponse {
#[allow(clippy::used_underscore_items)]
self._show_with_inner(|_id, ui, drag_drop_ui| drag_drop_ui.ui(ui, f))
}

Expand Down
8 changes: 4 additions & 4 deletions crates/egui_flex/src/flex_widget.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::{FlexContainerResponse, FlexContainerUi, FlexInstance, FlexItem};
use egui::Ui;
use crate::{FlexInstance, FlexItem};

/// Implement this trait for a widget to make it usable in a flex container.
///
Expand All @@ -13,6 +12,8 @@ pub trait FlexWidget {
/// The response type of the widget
type Response;

/// Returns the default [`FlexItem`] for this widget.
/// Implement this to allow overriding the item config.
fn default_item() -> FlexItem<'static> {
FlexItem::new()
}
Expand All @@ -24,13 +25,12 @@ pub trait FlexWidget {
}

mod egui_widgets {
use super::{FlexContainerResponse, FlexContainerUi, FlexWidget, Ui};
use super::FlexWidget;
use crate::{FlexInstance, FlexItem};
use egui::widgets::{
Button, Checkbox, DragValue, Hyperlink, Image, ImageButton, Label, Link, ProgressBar,
RadioButton, SelectableLabel, Slider, Spinner, TextEdit,
};
use egui::InnerResponse;

macro_rules! impl_widget {
($($widget:ty),*) => {
Expand Down
50 changes: 22 additions & 28 deletions crates/egui_flex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
#![warn(missing_docs)]

mod flex_widget;
mod utils;

pub use crate::flex_widget::FlexWidget;
use crate::utils::with_visual_transform;
use egui::emath::TSTransform;
use egui::{
Align, Align2, Direction, Frame, Id, InnerResponse, Layout, Margin, Pos2, Rect, Response,
Sense, Ui, UiBuilder, Vec2, Widget,
};
use std::cmp::min;
use std::fmt::Debug;
use std::mem;

Expand Down Expand Up @@ -101,14 +98,16 @@ pub struct Flex {
height: Option<Size>,
}

type FrameBuilder<'a> = Box<dyn FnOnce(&Ui, &Response) -> (Frame, TSTransform) + 'a>;

/// Configuration for a flex item.
#[derive(Default)]
pub struct FlexItem<'a> {
frame_builder: Option<Box<dyn FnOnce(&Ui, &Response) -> (Frame, TSTransform) + 'a>>,
frame_builder: Option<FrameBuilder<'a>>,
inner: FlexItemInner,
}

impl<'a> FlexItem<'a> {
impl FlexItem<'_> {
fn build_into_inner(self, ui: &Ui, response: &Response) -> FlexItemInner {
let FlexItem {
mut inner,
Expand All @@ -121,13 +120,6 @@ impl<'a> FlexItem<'a> {
}
inner
}

fn or(self, b: FlexItem<'a>) -> FlexItem<'a> {
FlexItem {
inner: self.inner.or(b.inner),
frame_builder: self.frame_builder.or(b.frame_builder),
}
}
}

#[derive(Debug, Clone, Copy, Default, PartialEq)]
Expand Down Expand Up @@ -263,6 +255,7 @@ impl<'a> FlexItem<'a> {
self
}

/// Set a sense for the FlexItem. The response will be passed to the FrameBuilder closure.
pub fn sense(mut self, sense: Sense) -> Self {
self.inner.sense = Some(sense);
self
Expand Down Expand Up @@ -781,6 +774,7 @@ impl Flex {
self.show_inside(ui, None, None, f).1
}

/// Show this flex in another Flex. See also [FlexInstance::add_flex].
#[track_caller]
pub fn show_in<R>(
self,
Expand Down Expand Up @@ -847,7 +841,7 @@ pub struct FlexInstance<'a> {
size: [Option<f32>; 2],
}

impl<'a> FlexInstance<'a> {
impl FlexInstance<'_> {
fn row_ui(parent: &mut Ui, row: Option<&RowData>) -> Ui {
let rect = row.map_or(parent.max_rect(), |row| row.rect.unwrap());

Expand All @@ -874,26 +868,32 @@ impl<'a> FlexInstance<'a> {
&self.row_ui
}

/// Access the underlying [`egui::Painter`].
pub fn painter(&self) -> &egui::Painter {
self.row_ui.painter()
}

/// Access the underlying [`egui::Output`].
pub fn visuals(&self) -> &egui::style::Visuals {
self.row_ui.visuals()
}

/// Access the underlying [`egui::style::Visuals`].
pub fn visuals_mut(&mut self) -> &mut egui::style::Visuals {
self.row_ui.visuals_mut()
}

/// Access the underlying [`egui::style::Style`].
pub fn style(&self) -> &egui::style::Style {
self.row_ui.style()
}

/// Access the underlying [`egui::style::Style`] mutably.
pub fn style_mut(&mut self) -> &mut egui::style::Style {
self.row_ui.style_mut()
}

/// Access the underlying [`egui::Spacing`].
pub fn spacing(&self) -> &egui::Spacing {
self.row_ui.spacing()
}
Expand Down Expand Up @@ -1054,10 +1054,10 @@ impl<'a> FlexInstance<'a> {
ui.new_child(UiBuilder::new().max_rect(frame_rect).layout(*ui.layout()));
child_ui.spacing_mut().item_spacing = self.item_spacing;

let res = with_visual_transform(ui, transform, |ui| {
let res = child_ui.with_visual_transform(transform, |ui| {
frame
.show(&mut child_ui, |ui| {
let res = content(
.show(ui, |ui| {
content(
ui,
FlexContainerUi {
direction: self.direction,
Expand All @@ -1073,14 +1073,12 @@ impl<'a> FlexInstance<'a> {
|| item.content_id != item_state.config.content_id,
last_inner_size: Some(item_state.inner_size),
target_inner_size,
item: item.clone(),
item,
},
);

res
)
})
.inner
});
}).inner;
let (_, _r) = ui.allocate_space(child_ui.min_rect().size());

let mut inner_size = res.child_rect.size();
Expand Down Expand Up @@ -1115,7 +1113,7 @@ impl<'a> FlexInstance<'a> {
remeasure_widget: false,
last_inner_size: None,
target_inner_size: rect.size(),
item: item.clone(),
item,
},
);

Expand Down Expand Up @@ -1202,9 +1200,9 @@ impl<'a> FlexInstance<'a> {
widget.flex_ui(item, self)
}

/// Add a [`egui::Widget`] to the flex container.
/// Add a [`Widget`] to the flex container.
/// The default egui widgets implement [`FlexWidget`] Aso you can just use [`Self::add`] instead.
/// If the widget reports it's intrinsic size via the [`egui::Response`] it will be able to
/// If the widget reports it's intrinsic size via the [`Response`] it will be able to
/// grow it's frame according to the flex layout.
pub fn add_widget<W: Widget>(&mut self, item: FlexItem, widget: W) -> InnerResponse<Response> {
self.add_container(
Expand Down Expand Up @@ -1300,8 +1298,6 @@ impl FlexContainerUi {
let child_rect = content_rect;
// let child_rect = content_rect.intersect(ui.max_rect());

let min_size = ui.min_size();

let mut child = ui.new_child(UiBuilder::new().max_rect(child_rect));

let r = content(&mut child);
Expand Down Expand Up @@ -1388,8 +1384,6 @@ impl FlexContainerUi {
ui: &mut Ui,
widget: impl Widget,
) -> FlexContainerResponse<Response> {
let min_size = ui.min_size();

let id_salt = ui.id().with("flex_widget");
let mut builder = UiBuilder::new()
.id_salt(id_salt)
Expand Down
24 changes: 0 additions & 24 deletions crates/egui_flex/src/utils.rs

This file was deleted.

6 changes: 3 additions & 3 deletions crates/egui_infinite_scroll/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl<T: Debug + Send + Sync + 'static, Cursor: Clone + Debug + Send + 'static>
});
}

fn filtered_items<'a>(items: &'a mut [T], filter: &Option<FilterType<T>>) -> Vec<&'a mut T> {
fn filtered_items<'a>(items: &'a mut [T], filter: Option<&FilterType<T>>) -> Vec<&'a mut T> {
if let Some(filter) = filter {
items
.iter_mut()
Expand All @@ -295,7 +295,7 @@ impl<T: Debug + Send + Sync + 'static, Cursor: Clone + Debug + Send + 'static>
) -> VirtualListResponse {
self.read_inboxes(ui);

let mut items = Self::filtered_items(&mut self.items, &self.filter);
let mut items = Self::filtered_items(&mut self.items, self.filter.as_ref());

let response = self
.virtual_list
Expand All @@ -309,7 +309,7 @@ impl<T: Debug + Send + Sync + 'static, Cursor: Clone + Debug + Send + 'static>
}

fn update_items(&mut self, item_range: &Range<usize>, end_prefetch: usize) {
let items = Self::filtered_items(&mut self.items, &self.filter);
let items = Self::filtered_items(&mut self.items, self.filter.as_ref());

if item_range.end + end_prefetch >= items.len()
&& matches!(self.bottom_loading_state, LoadingState::Idle { .. })
Expand Down
2 changes: 1 addition & 1 deletion crates/egui_suspense/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct State<'a> {
reload_fn: ReloadFnRef<'a>,
}

impl<'a> State<'a> {
impl State<'_> {
/// Call this to reload the data.
pub fn reload(&mut self) {
(self.reload_fn)();
Expand Down
2 changes: 2 additions & 0 deletions crates/egui_taffy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ impl<'a, 'f> TaffyPass<'a, 'f> {
content: impl FnMut(&mut Ui) + Send + 'f,
f: impl FnMut(&mut TaffyPass<'a, 'f>),
) {
#[allow(clippy::used_underscore_items)]
self._add_children(style, Some(Box::new(content)), f);
}

pub fn add_children(&mut self, style: Style, f: impl FnMut(&mut TaffyPass<'a, 'f>)) {
#[allow(clippy::used_underscore_items)]
self._add_children(style, None, f);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/egui_thumbhash/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl<'a, 'h> ThumbhashImage<'a, 'h> {
}
}

impl<'a, 'h> Widget for ThumbhashImage<'a, 'h> {
impl Widget for ThumbhashImage<'_, '_> {
fn ui(self, ui: &mut Ui) -> Response {
self.ui(ui)
}
Expand Down
2 changes: 1 addition & 1 deletion fancy-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ serde_json.workspace = true

casey = "0.4.0"

egui_commonmark = { version = "0.18.0", features = [] }
egui_commonmark = { version = "0.19.0", features = [] }

validator = { version = "0.18.1", features = ["derive"] }
env_logger = "0.11"
Expand Down
4 changes: 2 additions & 2 deletions fancy-example/tests/snapshots/example/gallery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions fancy-example/tests/snapshots/gallery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7a3fdee

Please sign in to comment.