mirror of
https://github.com/robbert-vdh/nih-plug.git
synced 2026-07-01 02:36:54 +00:00
Update to egui 0.22
This commit is contained in:
committed by
Robbert van der Helm
parent
07a310f778
commit
eb968ba446
@@ -19,12 +19,12 @@ opengl = []
|
||||
[dependencies]
|
||||
nih_plug = { path = ".." }
|
||||
|
||||
baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "eae4033e7d2cc9c31ccaa2794d5d08eedf2f510c" }
|
||||
baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "1d9806d5bd92275d0d8142d9c9c90198757b9b25" }
|
||||
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.19", default-features = false }
|
||||
egui-baseview = { git = "https://github.com/BillyDM/egui-baseview.git", rev = "46e21cc11c57c705fb83611389399ec3d2670a44" }
|
||||
egui = { version = "0.22", default-features = false }
|
||||
egui-baseview = { git = "https://github.com/BillyDM/egui-baseview.git", rev = "27c027c22a83d2eb214074f922ba4115f712e483" }
|
||||
lazy_static = "1.4"
|
||||
parking_lot = "0.12"
|
||||
# To make the state persistable
|
||||
|
||||
@@ -79,20 +79,20 @@ impl<'a, P: Param> ParamSlider<'a, P> {
|
||||
|
||||
/// Enable the keyboard entry part of the widget.
|
||||
fn begin_keyboard_entry(&self, ui: &Ui) {
|
||||
ui.memory().request_focus(self.keyboard_focus_id.unwrap());
|
||||
ui.memory_mut(|mem| mem.request_focus(self.keyboard_focus_id.unwrap()));
|
||||
|
||||
// Always initialize the field to the current value, that seems nicer than having to
|
||||
// being typing from scratch
|
||||
let value_entry_mutex = ui
|
||||
.memory()
|
||||
.data
|
||||
.get_temp_mut_or_default::<Arc<Mutex<String>>>(*VALUE_ENTRY_MEMORY_ID)
|
||||
.clone();
|
||||
let value_entry_mutex = ui.memory_mut(|mem| {
|
||||
mem.data
|
||||
.get_temp_mut_or_default::<Arc<Mutex<String>>>(*VALUE_ENTRY_MEMORY_ID)
|
||||
.clone()
|
||||
});
|
||||
*value_entry_mutex.lock() = self.string_value();
|
||||
}
|
||||
|
||||
fn keyboard_entry_active(&self, ui: &Ui) -> bool {
|
||||
ui.memory().has_focus(self.keyboard_focus_id.unwrap())
|
||||
ui.memory(|mem| mem.has_focus(self.keyboard_focus_id.unwrap()))
|
||||
}
|
||||
|
||||
fn begin_drag(&self) {
|
||||
@@ -151,27 +151,26 @@ impl<'a, P: Param> ParamSlider<'a, P> {
|
||||
}
|
||||
|
||||
fn get_drag_normalized_start_value_memory(ui: &Ui) -> f32 {
|
||||
ui.memory()
|
||||
.data
|
||||
.get_temp(*DRAG_NORMALIZED_START_VALUE_MEMORY_ID)
|
||||
.unwrap_or(0.5)
|
||||
ui.memory(|mem| {
|
||||
mem.data
|
||||
.get_temp(*DRAG_NORMALIZED_START_VALUE_MEMORY_ID)
|
||||
.unwrap_or(0.5)
|
||||
})
|
||||
}
|
||||
|
||||
fn set_drag_normalized_start_value_memory(ui: &Ui, amount: f32) {
|
||||
ui.memory()
|
||||
.data
|
||||
.insert_temp(*DRAG_NORMALIZED_START_VALUE_MEMORY_ID, amount);
|
||||
ui.memory_mut(|mem| {
|
||||
mem.data
|
||||
.insert_temp(*DRAG_NORMALIZED_START_VALUE_MEMORY_ID, amount)
|
||||
});
|
||||
}
|
||||
|
||||
fn get_drag_amount_memory(ui: &Ui) -> f32 {
|
||||
ui.memory()
|
||||
.data
|
||||
.get_temp(*DRAG_AMOUNT_MEMORY_ID)
|
||||
.unwrap_or(0.0)
|
||||
ui.memory(|mem| mem.data.get_temp(*DRAG_AMOUNT_MEMORY_ID).unwrap_or(0.0))
|
||||
}
|
||||
|
||||
fn set_drag_amount_memory(ui: &Ui, amount: f32) {
|
||||
ui.memory().data.insert_temp(*DRAG_AMOUNT_MEMORY_ID, amount);
|
||||
ui.memory_mut(|mem| mem.data.insert_temp(*DRAG_AMOUNT_MEMORY_ID, amount));
|
||||
}
|
||||
|
||||
fn slider_ui(&self, ui: &mut Ui, response: &mut Response) {
|
||||
@@ -184,7 +183,7 @@ impl<'a, P: Param> ParamSlider<'a, P> {
|
||||
Self::set_drag_amount_memory(ui, 0.0);
|
||||
}
|
||||
if let Some(click_pos) = response.interact_pointer_pos() {
|
||||
if ui.input().modifiers.command {
|
||||
if ui.input(|i| i.modifiers.command) {
|
||||
// Like double clicking, Ctrl+Click should reset the parameter
|
||||
self.reset_param();
|
||||
response.mark_changed();
|
||||
@@ -194,7 +193,7 @@ impl<'a, P: Param> ParamSlider<'a, P> {
|
||||
// // Allow typing in the value on an Alt+Click. Right now this is shown as part of the
|
||||
// // value field, so it only makes sense when we're drawing that.
|
||||
// self.begin_keyboard_entry(ui);
|
||||
} else if ui.input().modifiers.shift {
|
||||
} else if ui.input(|i| i.modifiers.shift) {
|
||||
// And shift dragging should switch to a more granulra input method
|
||||
self.granular_drag(ui, response.drag_delta());
|
||||
response.mark_changed();
|
||||
@@ -250,11 +249,11 @@ impl<'a, P: Param> ParamSlider<'a, P> {
|
||||
// has been clicked on
|
||||
let keyboard_focus_id = self.keyboard_focus_id.unwrap();
|
||||
if self.keyboard_entry_active(ui) {
|
||||
let value_entry_mutex = ui
|
||||
.memory()
|
||||
.data
|
||||
.get_temp_mut_or_default::<Arc<Mutex<String>>>(*VALUE_ENTRY_MEMORY_ID)
|
||||
.clone();
|
||||
let value_entry_mutex = ui.memory_mut(|mem| {
|
||||
mem.data
|
||||
.get_temp_mut_or_default::<Arc<Mutex<String>>>(*VALUE_ENTRY_MEMORY_ID)
|
||||
.clone()
|
||||
});
|
||||
let mut value_entry = value_entry_mutex.lock();
|
||||
|
||||
ui.add(
|
||||
@@ -262,16 +261,16 @@ impl<'a, P: Param> ParamSlider<'a, P> {
|
||||
.id(keyboard_focus_id)
|
||||
.font(TextStyle::Monospace),
|
||||
);
|
||||
if ui.input().key_pressed(Key::Escape) {
|
||||
if ui.input(|i| i.key_pressed(Key::Escape)) {
|
||||
// Cancel when pressing escape
|
||||
ui.memory().surrender_focus(keyboard_focus_id);
|
||||
} else if ui.input().key_pressed(Key::Enter) {
|
||||
ui.memory_mut(|mem| mem.surrender_focus(keyboard_focus_id));
|
||||
} else if ui.input(|i| i.key_pressed(Key::Enter)) {
|
||||
// And try to set the value by string when pressing enter
|
||||
self.begin_drag();
|
||||
self.set_from_string(&value_entry);
|
||||
self.end_drag();
|
||||
|
||||
ui.memory().surrender_focus(keyboard_focus_id);
|
||||
ui.memory_mut(|mem| mem.surrender_focus(keyboard_focus_id));
|
||||
}
|
||||
} else {
|
||||
let text = WidgetText::from(self.string_value()).into_galley(
|
||||
|
||||
@@ -4,7 +4,7 @@ use egui::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 {
|
||||
let mut hsv = egui::color::Hsva::from(color);
|
||||
let mut hsv = egui::epaint::Hsva::from(color);
|
||||
hsv.h += h;
|
||||
hsv.s += s;
|
||||
hsv.v += v;
|
||||
@@ -13,7 +13,7 @@ pub fn add_hsv(color: Color32, h: f32, s: f32, v: f32) -> Color32 {
|
||||
|
||||
/// Multiplicatively modify the hue, saturation, and lightness [0, 1] values of a color.
|
||||
pub fn scale_hsv(color: Color32, h: f32, s: f32, v: f32) -> Color32 {
|
||||
let mut hsv = egui::color::Hsva::from(color);
|
||||
let mut hsv = egui::epaint::Hsva::from(color);
|
||||
hsv.h *= h;
|
||||
hsv.s *= s;
|
||||
hsv.v *= v;
|
||||
|
||||
Reference in New Issue
Block a user