Skip to content

Commit

Permalink
Bump egui
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfbacon committed Nov 3, 2023
1 parent 5351762 commit f0867bc
Show file tree
Hide file tree
Showing 8 changed files with 965 additions and 412 deletions.
1,308 changes: 926 additions & 382 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ bytemuck = "1"
clru = { version = "0.6.1" }
crossbeam-channel = "0.5"
directories-next = "2"
eframe = { version = "0.20", features = ["serde"] }
egui = "0.20"
eframe = { version = "0.23", features = ["serde"] }
egui = "0.23"
humansize = "2"
image = { version = "0.24", features = ["jpeg_rayon", "avif-decoder"] }
once_cell = "1"
Expand Down
24 changes: 12 additions & 12 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn format_to_string(format: ImageFormat) -> &'static str {
impl config::Background {
fn draw(self, painter: &Painter, rect: Rect) {
fn draw_solid(painter: &Painter, rect: Rect, color: Color32) {
painter.rect_filled(rect, Rounding::none(), color);
painter.rect_filled(rect, Rounding::ZERO, color);
}

fn draw_checker(painter: &Painter, rect: Rect, color1: Color32, color2: Color32) {
Expand All @@ -140,7 +140,7 @@ impl config::Background {
const CHECKER_VEC: Vec2 = Vec2::splat(CHECKER_SIZE as f32);
const STEP: usize = (CHECKER_SIZE * 2) as usize;

painter.rect_filled(rect, Rounding::none(), color1);
painter.rect_filled(rect, Rounding::ZERO, color1);

let base_pos = rect.left_top();
// only add rects for color2
Expand All @@ -150,15 +150,15 @@ impl config::Background {
for x in (0..az::cast(rect.width())).step_by(STEP) {
painter.rect_filled(
Rect::from_min_size(base_pos + Vec2::new(az::cast(x), az::cast(y)), CHECKER_VEC),
Rounding::none(),
Rounding::ZERO,
color2,
);
painter.rect_filled(
Rect::from_min_size(
base_pos + Vec2::new(az::cast(x), az::cast(y)) + CHECKER_VEC,
CHECKER_VEC,
),
Rounding::none(),
Rounding::ZERO,
color2,
);
}
Expand Down Expand Up @@ -224,7 +224,8 @@ impl App {
"Click to copy"
});
if clicked {
ui.output().copied_text = current_path.display().to_string();
let copied_text = current_path.display().to_string();
ui.output_mut(|output| output.copied_text = copied_text);
}
}
}
Expand Down Expand Up @@ -275,7 +276,7 @@ impl App {
}

fn delete_file(&mut self, ui: &egui::Ui, path: Arc<Path>) {
if ui.input().modifiers.shift {
if ui.input(|input| input.modifiers.shift) {
self.asking_to_delete = None;
self.image_state.delete_file(path);
} else {
Expand All @@ -288,7 +289,7 @@ impl App {
let style = ctx.style();
let frame = Frame {
inner_margin: Margin::symmetric(4.0, 2.0),
rounding: Rounding::none(),
rounding: Rounding::ZERO,
fill: style.visuals.window_fill(),
stroke: style.visuals.window_stroke(),
..Default::default()
Expand Down Expand Up @@ -417,7 +418,7 @@ impl App {
}

fn update_slideshow(&mut self, ctx: &Context) {
let elapsed = ctx.input().unstable_dt;
let elapsed = ctx.input(|input| input.unstable_dt);

let next_from_slideshow = self
.slideshow
Expand Down Expand Up @@ -482,7 +483,7 @@ impl App {
*playing = !*playing;
}
if *playing {
let elapsed = ctx.input().unstable_dt;
let elapsed = ctx.input(|input| input.unstable_dt);
current_frame.advance(
Duration::new_secs_f32_saturating(elapsed),
image.frames.len(),
Expand Down Expand Up @@ -555,7 +556,7 @@ impl App {
fn handle_global_keys(&mut self, ctx: &Context, _frame: &mut eframe::Frame) {
use egui::Key;

let key = |key: Key| ctx.input_mut().consume_key(egui::Modifiers::NONE, key);
let key = |key: Key| ctx.input_mut(|input| input.consume_key(egui::Modifiers::NONE, key));

if key(Key::ArrowRight) {
self.move_right();
Expand All @@ -564,8 +565,7 @@ impl App {
self.move_left();
}
if ctx
.input_mut()
.consume_key(egui::Modifiers::CTRL | egui::Modifiers::SHIFT, Key::I)
.input_mut(|input| input.consume_key(egui::Modifiers::CTRL | egui::Modifiers::SHIFT, Key::I))
{
self.internal_open = !self.internal_open;
}
Expand Down
3 changes: 2 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ pub fn show(error: String) {
"Error!",
NativeOptions::default(),
Box::new(|_cc| Box::new(App { error })),
);
)
.unwrap();
}

struct App {
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ fn main_() -> Result<(), error::Stringed> {
"Image Viewer",
native_options,
Box::new(move |cc| Box::new(app::App::new(args, config, cc))),
);
)
.unwrap();

Ok(())
}
9 changes: 7 additions & 2 deletions src/widgets/image.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use egui::load::SizedTexture;
use egui::{Rect, Response, Sense, TextureHandle, TextureId, Ui, Vec2, Widget};

use super::image_size;
Expand Down Expand Up @@ -40,7 +41,7 @@ impl Zoom {
if let Some(pointer) = response.hover_pos() {
let pointer = pointer - response.rect.center();
let old_zoom = self.zoom_factor();
self.zoom += response.ctx.input().scroll_delta.y * 0.01;
self.zoom += response.ctx.input(|input| input.scroll_delta.y) * 0.01;
let zoom_delta = self.zoom_factor() / old_zoom;
self.center -= pointer;
self.center *= zoom_delta;
Expand Down Expand Up @@ -97,7 +98,11 @@ impl Image {

image_rect = self.zoom.apply(image_rect);

egui::widgets::Image::new(self.texture, scaled_size).paint_at(&mut ui, image_rect);
let texture = SizedTexture {
id: self.texture,
size: scaled_size,
};
egui::widgets::Image::from_texture(texture).paint_at(&mut ui, image_rect);

image_rect
}
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/image_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Widget for ImageButton {
if ui.is_rect_visible(rect) {
let (rounding, fill, stroke) = if selected {
let visuals = ui.visuals().selection;
(egui::Rounding::none(), visuals.bg_fill, visuals.stroke)
(egui::Rounding::ZERO, visuals.bg_fill, visuals.stroke)
} else {
let visuals = ui.style().interact(&response);
(visuals.rounding, visuals.bg_fill, visuals.bg_stroke)
Expand Down
24 changes: 13 additions & 11 deletions src/widgets/unit_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ impl<GS: FnMut(Option<&str>) -> String> Widget for UnitInput<GS> {
fn ui(mut self, ui: &mut Ui) -> Response {
let kb_edit_id = ui.id().with("kb_edit");

let mut buffer = if ui.memory().has_focus(kb_edit_id) {
std::mem::take(
ui.memory()
.data
.get_temp_mut_or_insert_with(kb_edit_id, || (self.get_set)(None)),
)
let mut buffer = if ui.memory(|memory| memory.has_focus(kb_edit_id)) {
ui.memory_mut(|memory| {
let data = &mut memory.data;
let buffer = data.get_temp_mut_or_insert_with(kb_edit_id, || (self.get_set)(None));
std::mem::take(buffer)
})
} else {
(self.get_set)(None)
};
Expand All @@ -94,14 +94,16 @@ impl<GS: FnMut(Option<&str>) -> String> Widget for UnitInput<GS> {
}

if response.has_focus() {
if ui.input().key_pressed(Key::Enter) {
ui.memory().surrender_focus(kb_edit_id);
ui.memory().data.remove::<String>(kb_edit_id);
if ui.input(|input| input.key_pressed(Key::Enter)) {
ui.memory_mut(|memory| {
memory.surrender_focus(kb_edit_id);
memory.data.remove::<String>(kb_edit_id);
});
} else {
*ui.memory().data.get_temp_mut_or(kb_edit_id, String::new()) = buffer;
ui.memory_mut(|memory| *memory.data.get_temp_mut_or(kb_edit_id, String::new()) = buffer);
}
} else if response.lost_focus() {
ui.memory().data.remove::<String>(kb_edit_id);
ui.memory_mut(|memory| memory.data.remove::<String>(kb_edit_id));
}

// propagating `response.changed()`
Expand Down

0 comments on commit f0867bc

Please sign in to comment.