Skip to content

Commit

Permalink
update egui and egui_baseview
Browse files Browse the repository at this point in the history
  • Loading branch information
Billy Messenger authored and robbert-vdh committed Feb 22, 2024
1 parent 7a01b57 commit 0dccb45
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 53 deletions.
115 changes: 90 additions & 25 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,6 @@ strip = "symbols"
inherits = "release"
debug = true
strip = "none"

[toolchain]
channel = "nightly"
22 changes: 7 additions & 15 deletions nih_plug_egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,19 @@ license = "ISC"
description = "An adapter to use egui GUIs with NIH-plug"

[features]
default = ["egui-default-features", "opengl"]

# Use egui's default features
egui-default-features = ["egui/default"]
default = ["opengl", "default_fonts"]
# `nih_plug_egui` always uses OpenGL since egui's wgpu backend is still unstable
# depending on the platform
opengl = []
opengl = ["egui-baseview/opengl"]
default_fonts = ["egui-baseview/default_fonts"]
rayon = ["egui-baseview/rayon"]

[dependencies]
nih_plug = { path = ".." }

# The currently targeted version of baseview uses a different version of
# `raw_window_handle` than NIH-plug, so we need to manually convert between them
raw-window-handle = "0.4"

baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "1d9806d5bd92275d0d8142d9c9c90198757b9b25" }
raw-window-handle = "0.5"
baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "2c1b1a7b0fef1a29a5150a6a8f6fef6a0cbab8c4" }
crossbeam = "0.8"
# The `egui-default-features` feature enables the default features. This makes
# it possible to opt out of this if needed.
egui = { version = "0.22", default-features = false }
egui-baseview = { git = "https://github.com/BillyDM/egui-baseview.git", rev = "27c027c22a83d2eb214074f922ba4115f712e483" }
egui-baseview = { git = "https://github.com/BillyDM/egui-baseview.git", rev = "1fe7e1d0081ab29474b0a5cdc567f60a3219b20d", default-features = false }
lazy_static = "1.4"
parking_lot = "0.12"
# To make the state persistable
Expand Down
8 changes: 4 additions & 4 deletions nih_plug_egui/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use baseview::gl::GlConfig;
use baseview::{Size, WindowHandle, WindowOpenOptions, WindowScalePolicy};
use crossbeam::atomic::AtomicCell;
use egui::Context;
use egui_baseview::egui::Context;
use egui_baseview::EguiWindow;
use nih_plug::prelude::{Editor, GuiContext, ParamSetter, ParentWindowHandle};
use parking_lot::RwLock;
Expand Down Expand Up @@ -37,17 +37,17 @@ unsafe impl HasRawWindowHandle for ParentWindowHandleAdapter {
fn raw_window_handle(&self) -> RawWindowHandle {
match self.0 {
ParentWindowHandle::X11Window(window) => {
let mut handle = raw_window_handle::XcbHandle::empty();
let mut handle = raw_window_handle::XcbWindowHandle::empty();
handle.window = window;
RawWindowHandle::Xcb(handle)
}
ParentWindowHandle::AppKitNsView(ns_view) => {
let mut handle = raw_window_handle::AppKitHandle::empty();
let mut handle = raw_window_handle::AppKitWindowHandle::empty();
handle.ns_view = ns_view;
RawWindowHandle::AppKit(handle)
}
ParentWindowHandle::Win32Hwnd(hwnd) => {
let mut handle = raw_window_handle::Win32Handle::empty();
let mut handle = raw_window_handle::Win32WindowHandle::empty();
handle.hwnd = hwnd;
RawWindowHandle::Win32(handle)
}
Expand Down
2 changes: 1 addition & 1 deletion nih_plug_egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::sync::Arc;
compile_error!("There's currently no software rendering support for egui");

/// Re-export for convenience.
pub use egui;
pub use egui_baseview::egui;

mod editor;
pub mod widgets;
Expand Down
2 changes: 1 addition & 1 deletion nih_plug_egui/src/widgets/generic_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use std::sync::Arc;

use egui::{TextStyle, Ui, Vec2};
use egui_baseview::egui::{self, TextStyle, Ui, Vec2};
use nih_plug::prelude::{Param, ParamFlags, ParamPtr, ParamSetter, Params};

use super::ParamSlider;
Expand Down
17 changes: 12 additions & 5 deletions nih_plug_egui/src/widgets/param_slider.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::sync::Arc;

use egui::{vec2, Key, Response, Sense, Stroke, TextEdit, TextStyle, Ui, Vec2, Widget, WidgetText};
use egui_baseview::egui::{
self, emath, vec2, Key, Response, Sense, Stroke, TextEdit, TextStyle, Ui, Vec2, Widget,
WidgetText,
};
use lazy_static::lazy_static;
use nih_plug::prelude::{Param, ParamSetter};
use parking_lot::Mutex;
Expand Down Expand Up @@ -35,7 +38,7 @@ pub struct ParamSlider<'a, P: Param> {
slider_width: Option<f32>,

/// Will be set in the `ui()` function so we can request keyboard input focus on Alt+click.
keyboard_focus_id: Option<egui::Id>,
keyboard_focus_id: Option<egui_baseview::egui::Id>,
}

impl<'a, P: Param> ParamSlider<'a, P> {
Expand Down Expand Up @@ -199,8 +202,7 @@ impl<'a, P: Param> ParamSlider<'a, P> {
response.mark_changed();
} else {
let proportion =
egui::emath::remap_clamp(click_pos.x, response.rect.x_range(), 0.0..=1.0)
as f64;
emath::remap_clamp(click_pos.x, response.rect.x_range(), 0.0..=1.0) as f64;
self.set_normalized_value(proportion as f32);
response.mark_changed();
Self::set_drag_amount_memory(ui, 0.0);
Expand Down Expand Up @@ -301,7 +303,12 @@ impl<'a, P: Param> ParamSlider<'a, P> {
.layout()
.align_size_within_rect(text.size(), response.rect.shrink2(padding))
.min;
text.paint_with_visuals(ui.painter(), text_pos, &visuals);

ui.painter().add(egui::epaint::TextShape::new(
text_pos,
text,
visuals.fg_stroke.color,
));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion nih_plug_egui/src/widgets/util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Utilities for creating these widgets.

use egui::Color32;
use egui_baseview::egui::{self, Color32};

/// Additively modify the hue, saturation, and lightness [0, 1] values of a color.
pub fn add_hsv(color: Color32, h: f32, s: f32, v: f32) -> Color32 {
Expand Down
1 change: 0 additions & 1 deletion plugins/examples/gain_gui_egui/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use atomic_float::AtomicF32;
use nih_plug::prelude::*;
use nih_plug_egui::{create_egui_editor, egui, widgets, EguiState};
use std::sync::Arc;
Expand Down

0 comments on commit 0dccb45

Please sign in to comment.