update egui and egui_baseview

This commit is contained in:
Billy Messenger
2024-02-22 11:49:11 -06:00
committed by Robbert van der Helm
parent 7a01b57735
commit 0dccb4501f
9 changed files with 119 additions and 53 deletions

View File

@@ -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

View File

@@ -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;
@@ -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)
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;
@@ -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> {
@@ -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);
@@ -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,
));
}
}
}

View File

@@ -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 {