Skip to content

Commit

Permalink
update to egui 0.29
Browse files Browse the repository at this point in the history
  • Loading branch information
MoAlyousef committed Sep 26, 2024
1 parent e86fd9a commit f20a2e3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 48 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fltk-egui"
version = "0.16.0"
version = "0.17.0"
edition = "2021"
authors = ["MoAlyousef <[email protected]>", "Adia Robbie <[email protected]>"]
description = "FLTK backend for egui"
Expand All @@ -13,14 +13,14 @@ license = "MIT"
rust-version = "1.72"

[dependencies]
egui = { version = "0.27" }
egui_glow = { version = "0.27", default-features = false }
egui = { version = "0.29" }
egui_glow = { version = "0.29", default-features = false }
arboard = { version = "3.3" }
fltk = { version = "1.4.12", features = ["enable-glwindow"] }

# for the demo_windows example
[dev-dependencies]
egui_demo_lib = { version = "0.27" }
egui_demo_lib = { version = "0.29" }

[features]
wayland = ["fltk/use-wayland"]
Expand Down
71 changes: 27 additions & 44 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use std::{sync::Arc, time::Instant};

use egui::{pos2, vec2, CursorIcon, Event, Key, Modifiers, Pos2, RawInput, Rect, Vec2};
use egui::{pos2, vec2, CursorIcon, Event, Key, Modifiers, MouseWheelUnit, Pos2, RawInput, Rect};
use egui_glow::{glow, Painter};
use egui_image::RetainedEguiImage;
use fltk::{
Expand All @@ -21,7 +21,7 @@ pub fn init(win: &mut GlWindow) -> (Painter, EguiState) {
app::set_screen_scale(win.screen_num(), 1.);
app::keyboard_screen_scaling(false);
let gl = unsafe { glow::Context::from_loader_function(|s| win.get_proc_address(s) as _) };
let painter = Painter::new(Arc::from(gl), "", None)
let painter = Painter::new(Arc::from(gl), "", None, false)
.unwrap_or_else(|error| panic!("some OpenGL error occurred {}\n", error));
let max_texture_side = painter.max_texture_side();
(painter, EguiState::new(&win, max_texture_side))
Expand Down Expand Up @@ -294,49 +294,32 @@ pub fn input_to_egui(
}

enums::Event::MouseWheel => {
if app::is_event_ctrl() {
let zoom_factor = state.zoom_factor;
match app::event_dy() {
app::MouseWheel::Up => {
let delta = egui::vec2(1., -1.) * zoom_factor;

// Treat as zoom in:
state
.input
.events
.push(Event::Zoom((delta.y / 200.0).exp()));
}
app::MouseWheel::Down => {
let delta = egui::vec2(-1., 1.) * zoom_factor;

// Treat as zoom out:
state
.input
.events
.push(Event::Zoom((delta.y / 200.0).exp()));
}
_ => (),
}
} else {
let scroll_factor = state.scroll_factor;
match app::event_dy() {
app::MouseWheel::Up => {
state.input.events.push(Event::Scroll(Vec2 {
x: 0.,
y: -scroll_factor,
}));
}
app::MouseWheel::Down => {
state.input.events.push(Event::Scroll(Vec2 {
x: 0.,
y: scroll_factor,
}));
}
_ => (),
}
}
let keymod = app::event_state();
state.input.modifiers = Modifiers {
alt: (keymod & enums::EventState::Alt == enums::EventState::Alt),
ctrl: (keymod & enums::EventState::Ctrl == enums::EventState::Ctrl),
shift: (keymod & enums::EventState::Shift == enums::EventState::Shift),
mac_cmd: keymod & enums::EventState::Meta == enums::EventState::Meta,

//TOD: Test on both windows and mac
command: (keymod & enums::EventState::Command == enums::EventState::Command),
};
let negx = match app::event_dx() {
app::MouseWheel::Right => 1.,
app::MouseWheel::Left => -1.,
_ => 0.,
};
let negy = match app::event_dy() {
app::MouseWheel::Up => -1.,
app::MouseWheel::Down => 1.,
_ => 0.,
};
state.input.events.push(Event::MouseWheel {
unit: MouseWheelUnit::Line,
delta: vec2(1. * negx, 1. * negy) ,
modifiers: state.input.modifiers,
});
}

_ => {
//dbg!(event);
}
Expand Down

0 comments on commit f20a2e3

Please sign in to comment.