Skip to content

Commit

Permalink
Merge pull request #291 from apekros/issue-290
Browse files Browse the repository at this point in the history
update egui to 0.23.0
  • Loading branch information
Nazariglez authored Oct 15, 2023
2 parents 150a3bf + 4661349 commit 047bf0d
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 48 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ All notable changes to this project will be documented in this file.
## UNRELEASED

- Added traits `Serialize` and `Deserialize` to `Color` with the feature `serde` enabled.
- Fixed an error acquiring the GL Context due required samples configuration.
- Updated EGUI to `0.23`.
- Fixed an error acquiring the GL Context due required samples configuration.

## v0.10.0 - 11/09/2023

Expand Down
72 changes: 52 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ shaderc = ["notan_macro/shaderc", "notan_glyph?/shaderc", "notan_draw?/shaderc",
serde = ["notan_app/serde", "notan_math/serde", "notan_core/serde", "notan_input/serde", "notan_graphics/serde"]

[dev-dependencies]
egui_demo_lib = "0.22.0"
egui_demo_lib = "0.23.0"
bytemuck = "1.14.0"

[[example]]
Expand Down
2 changes: 1 addition & 1 deletion crates/notan_egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ notan_macro.workspace = true
log.workspace = true
bytemuck.workspace = true

egui = { version = "0.22.0", features = ["bytemuck"] }
egui = { version = "0.23.0", features = ["bytemuck"] }

[features]
links = []
Expand Down
18 changes: 10 additions & 8 deletions crates/notan_egui/src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use crate::epaint::Primitive;
use crate::plugin::Output;
use crate::TextureId;
use egui::load::SizedTexture;
use egui::{PaintCallbackInfo, Rect};
use notan_app::{
BlendFactor, BlendMode, Buffer, CullMode, Device, Graphics, Pipeline, RenderTexture,
Expand Down Expand Up @@ -149,14 +150,15 @@ impl EguiExtension {
})
}

pub fn add_texture(&mut self, texture: &Texture) -> egui::TextureId {
pub fn add_texture(&mut self, texture: &Texture) -> SizedTexture {
let id = egui::TextureId::User(texture.id());
let size: egui::Vec2 = texture.size().into();
self.textures.insert(id, texture.clone());
id
SizedTexture { id, size }
}

pub fn remove_texture(&mut self, id: egui::TextureId) {
self.free_texture(id);
pub fn remove_texture(&mut self, id: impl Into<TextureId>) {
self.free_texture(id.into());
}

fn set_texture(
Expand Down Expand Up @@ -388,18 +390,18 @@ impl EguiExtension {
}

pub trait EguiRegisterTexture {
fn egui_register_texture(&mut self, texture: &Texture) -> egui::TextureId;
fn egui_remove_texture(&mut self, id: egui::TextureId);
fn egui_register_texture(&mut self, texture: &Texture) -> egui::load::SizedTexture;
fn egui_remove_texture(&mut self, id: impl Into<egui::TextureId>);
}

impl EguiRegisterTexture for Graphics {
fn egui_register_texture(&mut self, texture: &Texture) -> TextureId {
fn egui_register_texture(&mut self, texture: &Texture) -> SizedTexture {
self.extension_mut::<Output, EguiExtension>()
.unwrap()
.add_texture(texture)
}

fn egui_remove_texture(&mut self, id: TextureId) {
fn egui_remove_texture(&mut self, id: impl Into<TextureId>) {
self.extension_mut::<Output, EguiExtension>()
.unwrap()
.remove_texture(id);
Expand Down
1 change: 1 addition & 0 deletions crates/notan_egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ pub use config::EguiConfig;
pub use extension::{EguiCallbackFn, EguiExtension, EguiRegisterTexture};
pub use plugin::{EguiPlugin, EguiPluginSugar};

pub use egui::load::SizedTexture;
pub use egui::*;
8 changes: 4 additions & 4 deletions crates/notan_egui/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,22 +255,22 @@ impl Plugin for EguiPlugin {
id: egui::TouchId(*id),
phase: egui::TouchPhase::Start,
pos: (*x, *y).into(),
force: 0.0,
force: Some(0.0),
}),
Event::TouchMove { id, x, y } => self.add_event(egui::Event::Touch {
device_id: egui::TouchDeviceId(0),
id: egui::TouchId(*id),
phase: egui::TouchPhase::Move,
pos: (*x, *y).into(),
force: 0.0,
force: Some(0.0),
}),
Event::TouchEnd { id, x, y } => {
self.add_event(egui::Event::Touch {
device_id: egui::TouchDeviceId(0),
id: egui::TouchId(*id),
phase: egui::TouchPhase::End,
pos: (*x, *y).into(),
force: 0.0,
force: Some(0.0),
});

is_touch_end = true;
Expand All @@ -281,7 +281,7 @@ impl Plugin for EguiPlugin {
id: egui::TouchId(*id),
phase: egui::TouchPhase::Cancel,
pos: (*x, *y).into(),
force: 0.0,
force: Some(0.0),
});
is_touch_end = true;
}
Expand Down
11 changes: 4 additions & 7 deletions examples/egui_render_texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use notan::prelude::*;
struct State {
cube: Cube,
render_texture: RenderTexture,
tex_id: egui::TextureId,
img_size: egui::Vec2,
sized_texture: SizedTexture,
}

impl State {
Expand All @@ -20,14 +19,12 @@ impl State {
.build()
.unwrap();

let img_size = render_texture.size().into();
let tex_id = gfx.egui_register_texture(&render_texture);
let sized_texture = gfx.egui_register_texture(&render_texture);

Self {
img_size,
tex_id,
cube,
render_texture,
sized_texture,
}
}
}
Expand All @@ -47,7 +44,7 @@ fn draw(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut St

let mut output = plugins.egui(|ctx| {
egui::Window::new("Notan Render Texture").show(ctx, |ui| {
ui.image(state.tex_id, state.img_size);
ui.image(state.sized_texture);
});
});
output.clear_color(Color::BLACK);
Expand Down
10 changes: 4 additions & 6 deletions examples/egui_texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use notan::prelude::*;

#[derive(AppState)]
struct State {
tex_id: egui::TextureId,
img_size: egui::Vec2,
sized_texture: egui::SizedTexture,
}

impl State {
Expand All @@ -16,10 +15,9 @@ impl State {
.build()
.unwrap();

let img_size: egui::Vec2 = texture.size().into();
let tex_id = gfx.egui_register_texture(&texture);
let sized_texture = gfx.egui_register_texture(&texture);

Self { img_size, tex_id }
Self { sized_texture }
}
}

Expand All @@ -34,7 +32,7 @@ fn main() -> Result<(), String> {
fn draw(gfx: &mut Graphics, plugins: &mut Plugins, state: &mut State) {
let mut output = plugins.egui(|ctx| {
egui::Window::new("Notan Texture").show(ctx, |ui| {
ui.image(state.tex_id, state.img_size);
ui.image(state.sized_texture);
});
});

Expand Down

0 comments on commit 047bf0d

Please sign in to comment.