From 85543e1668bcc9085be5e0e45504e46b9f481be1 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Thu, 22 Sep 2022 19:52:11 +0200 Subject: [PATCH] Update Vizia --- BREAKING_CHANGES.md | 2 + Cargo.lock | 299 ++++++++++---------- nih_plug_vizia/src/lib.rs | 6 +- nih_plug_vizia/src/widgets.rs | 4 +- nih_plug_vizia/src/widgets/param_slider.rs | 30 +- nih_plug_vizia/src/widgets/peak_meter.rs | 33 +-- nih_plug_vizia/src/widgets/resize_handle.rs | 31 +- nih_plug_vizia/src/widgets/util.rs | 32 +-- 8 files changed, 213 insertions(+), 224 deletions(-) diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index c5ec6f63..d4c40c22 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -9,6 +9,8 @@ code then it will not be listed here. ## [2022-09-22] - `nih_plug_egui` has been updated from egui 0.17 to egui 0.19. +- `nih_plug_vizia` has been updated. Custom widgets will need to be updated + because of changes Vizia itself. ## [2022-09-06] diff --git a/Cargo.lock b/Cargo.lock index f96b8aa8..65387783 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -96,12 +96,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "android_glue" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "000444226fcff248f2bc4c7625be32c63caccfecc2723a2b9f78a7487a49c407" - [[package]] name = "anyhow" version = "1.0.57" @@ -364,11 +358,11 @@ version = "0.1.0" source = "git+https://github.com/robbert-vdh/baseview.git?branch=feature/mouse-event-modifiers#5b57af2463ef55c4ac702ef662c3472c328a3c6b" dependencies = [ "cocoa", - "core-foundation 0.9.3", + "core-foundation", "keyboard-types", "nix 0.22.3", "objc", - "raw-window-handle", + "raw-window-handle 0.4.3", "uuid", "winapi", "x11", @@ -382,11 +376,11 @@ version = "0.1.0" source = "git+https://github.com/robbert-vdh/baseview.git?branch=feature/resize#b5d0751c82c3fd0301366f1f31c07f3cd53aa52f" dependencies = [ "cocoa", - "core-foundation 0.9.3", + "core-foundation", "keyboard-types", "nix 0.22.3", "objc", - "raw-window-handle", + "raw-window-handle 0.4.3", "uuid", "winapi", "x11", @@ -400,11 +394,11 @@ version = "0.1.0" source = "git+https://github.com/RustAudio/baseview.git?rev=eae4033e7d2cc9c31ccaa2794d5d08eedf2f510c#eae4033e7d2cc9c31ccaa2794d5d08eedf2f510c" dependencies = [ "cocoa", - "core-foundation 0.9.3", + "core-foundation", "keyboard-types", "nix 0.22.3", "objc", - "raw-window-handle", + "raw-window-handle 0.4.3", "uuid", "winapi", "x11", @@ -664,8 +658,8 @@ dependencies = [ "bitflags", "block", "cocoa-foundation", - "core-foundation 0.9.3", - "core-graphics 0.22.3", + "core-foundation", + "core-graphics", "foreign-types", "libc", "objc", @@ -679,7 +673,7 @@ checksum = "7ade49b65d560ca58c403a479bb396592b155c0185eada742ee323d1d68d6318" dependencies = [ "bitflags", "block", - "core-foundation 0.9.3", + "core-foundation", "core-graphics-types", "foreign-types", "libc", @@ -765,50 +759,22 @@ dependencies = [ "x11-clipboard 0.6.1", ] -[[package]] -name = "core-foundation" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" -dependencies = [ - "core-foundation-sys 0.7.0", - "libc", -] - [[package]] name = "core-foundation" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" dependencies = [ - "core-foundation-sys 0.8.3", + "core-foundation-sys", "libc", ] -[[package]] -name = "core-foundation-sys" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" - [[package]] name = "core-foundation-sys" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" -[[package]] -name = "core-graphics" -version = "0.19.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3889374e6ea6ab25dba90bb5d96202f61108058361f6dc72e8b03e6f8bbe923" -dependencies = [ - "bitflags", - "core-foundation 0.7.0", - "foreign-types", - "libc", -] - [[package]] name = "core-graphics" version = "0.22.3" @@ -816,7 +782,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" dependencies = [ "bitflags", - "core-foundation 0.9.3", + "core-foundation", "core-graphics-types", "foreign-types", "libc", @@ -829,7 +795,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b" dependencies = [ "bitflags", - "core-foundation 0.9.3", + "core-foundation", "foreign-types", "libc", ] @@ -840,25 +806,12 @@ version = "19.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99d74ada66e07c1cefa18f8abfba765b486f250de2e4a999e5727fc0dd4b4a25" dependencies = [ - "core-foundation 0.9.3", - "core-graphics 0.22.3", + "core-foundation", + "core-graphics", "foreign-types", "libc", ] -[[package]] -name = "core-video-sys" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34ecad23610ad9757664d644e369246edde1803fcb43ed72876565098a5d3828" -dependencies = [ - "cfg-if 0.1.10", - "core-foundation-sys 0.7.0", - "core-graphics 0.19.2", - "libc", - "objc", -] - [[package]] name = "coreaudio-rs" version = "0.10.0" @@ -885,7 +838,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74117836a5124f3629e4b474eed03e479abaf98988b4bb317e29f08cfe0e4116" dependencies = [ "alsa", - "core-foundation-sys 0.8.3", + "core-foundation-sys", "coreaudio-rs", "jni", "js-sys", @@ -1224,7 +1177,7 @@ dependencies = [ "egui", "egui_glow", "keyboard-types", - "raw-window-handle", + "raw-window-handle 0.4.3", ] [[package]] @@ -1308,8 +1261,8 @@ dependencies = [ [[package]] name = "femtovg" -version = "0.3.3" -source = "git+https://github.com/femtovg/femtovg?rev=87fe627794f3f793d8e3a338c838a2f8e8a8aa9d#87fe627794f3f793d8e3a338c838a2f8e8a8aa9d" +version = "0.3.5" +source = "git+https://github.com/femtovg/femtovg?rev=8df076f1dd610b5e0a584f0d7fd7f210988b3684#8df076f1dd610b5e0a584f0d7fd7f210988b3684" dependencies = [ "bitflags", "fnv", @@ -1408,8 +1361,8 @@ checksum = "46c9a156ec38864999bc9c4156e5f3b50224d4a5578028a64e5a3875caa9ee28" dependencies = [ "bitflags", "byteorder", - "core-foundation 0.9.3", - "core-graphics 0.22.3", + "core-foundation", + "core-graphics", "core-text", "dirs-next", "dwrote", @@ -1732,45 +1685,38 @@ dependencies = [ [[package]] name = "glutin" -version = "0.28.0" +version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00ea9dbe544bc8a657c4c4a798c2d16cd01b549820e47657297549d28371f6d2" +checksum = "444c9ad294fdcaf20ccf6726b78f380b5450275540c9b68ab62f49726ad1c713" dependencies = [ - "android_glue", "cgl", "cocoa", - "core-foundation 0.9.3", + "core-foundation", "glutin_egl_sys", - "glutin_emscripten_sys", "glutin_gles2_sys", "glutin_glx_sys", "glutin_wgl_sys", - "lazy_static", "libloading", "log", "objc", + "once_cell", "osmesa-sys", - "parking_lot 0.11.2", + "parking_lot 0.12.1", + "raw-window-handle 0.5.0", "winapi", "winit", ] [[package]] name = "glutin_egl_sys" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2abb6aa55523480c4adc5a56bbaa249992e2dddb2fc63dc96e04a3355364c211" +checksum = "68900f84b471f31ea1d1355567eb865a2cf446294f06cef8d653ed7bcf5f013d" dependencies = [ "gl_generator", "winapi", ] -[[package]] -name = "glutin_emscripten_sys" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80de4146df76e8a6c32b03007bc764ff3249dcaeb4f675d68a06caf1bac363f1" - [[package]] name = "glutin_gles2_sys" version = "0.1.5" @@ -1783,9 +1729,9 @@ dependencies = [ [[package]] name = "glutin_glx_sys" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e393c8fc02b807459410429150e9c4faffdb312d59b8c038566173c81991351" +checksum = "d93d0575865098580c5b3a423188cd959419912ea60b1e48e8b3b526f6d02468" dependencies = [ "gl_generator", "x11-dl", @@ -1949,7 +1895,7 @@ dependencies = [ "iced_native", "iced_wgpu", "keyboard-types", - "raw-window-handle", + "raw-window-handle 0.4.3", ] [[package]] @@ -2003,7 +1949,7 @@ dependencies = [ "iced_style", "lyon", "qrcode", - "raw-window-handle", + "raw-window-handle 0.4.3", "thiserror", ] @@ -2043,7 +1989,7 @@ dependencies = [ "image 0.23.14", "kamadak-exif", "log", - "raw-window-handle", + "raw-window-handle 0.4.3", "resvg", "tiny-skia", "usvg", @@ -2545,19 +2491,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "ndk" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d868f654c72e75f8687572699cdabe755f03effbb62542768e995d5b8d699d" -dependencies = [ - "bitflags", - "jni-sys", - "ndk-sys 0.2.2", - "num_enum", - "thiserror", -] - [[package]] name = "ndk" version = "0.6.0" @@ -2571,27 +2504,26 @@ dependencies = [ "thiserror", ] +[[package]] +name = "ndk" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "451422b7e4718271c8b5b3aadf5adedba43dc76312454b387e98fae0fc951aa0" +dependencies = [ + "bitflags", + "jni-sys", + "ndk-sys 0.4.0", + "num_enum", + "raw-window-handle 0.5.0", + "thiserror", +] + [[package]] name = "ndk-context" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b" -[[package]] -name = "ndk-glue" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c71bee8ea72d685477e28bd004cfe1bf99c754d688cd78cad139eae4089484d4" -dependencies = [ - "lazy_static", - "libc", - "log", - "ndk 0.5.0", - "ndk-context", - "ndk-macro", - "ndk-sys 0.2.2", -] - [[package]] name = "ndk-glue" version = "0.6.2" @@ -2607,6 +2539,22 @@ dependencies = [ "ndk-sys 0.3.0", ] +[[package]] +name = "ndk-glue" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0434fabdd2c15e0aab768ca31d5b7b333717f03cf02037d5a0a3ff3c278ed67f" +dependencies = [ + "libc", + "log", + "ndk 0.7.0", + "ndk-context", + "ndk-macro", + "ndk-sys 0.4.0", + "once_cell", + "parking_lot 0.12.1", +] + [[package]] name = "ndk-macro" version = "0.3.0" @@ -2620,12 +2568,6 @@ dependencies = [ "syn", ] -[[package]] -name = "ndk-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1bcdd74c20ad5d95aacd60ef9ba40fdf77f767051040541df557b7a9b2a2121" - [[package]] name = "ndk-sys" version = "0.3.0" @@ -2635,6 +2577,15 @@ dependencies = [ "jni-sys", ] +[[package]] +name = "ndk-sys" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21d83ec9c63ec5bf950200a8e508bdad6659972187b625469f58ef8c08e29046" +dependencies = [ + "jni-sys", +] + [[package]] name = "nih_plug" version = "0.0.0" @@ -2659,7 +2610,7 @@ dependencies = [ "midi-consts", "nih_plug_derive", "parking_lot 0.12.1", - "raw-window-handle", + "raw-window-handle 0.4.3", "rtrb", "serde", "serde_json", @@ -2961,9 +2912,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.12.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225" +checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" [[package]] name = "ordered-float" @@ -3480,6 +3431,15 @@ dependencies = [ "cty", ] +[[package]] +name = "raw-window-handle" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed7e3d950b66e19e0c372f3fa3fbbcf85b1746b571f74e0c2af6042a5c93420a" +dependencies = [ + "cty", +] + [[package]] name = "rayon" version = "1.5.3" @@ -4230,7 +4190,7 @@ version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "rand 0.8.5", "static_assertions", ] @@ -4377,7 +4337,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "vizia" version = "0.1.0" -source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#87672c6fdee89d33d4c4a2e1bfff17b4c24a778c" +source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#c4572d7b266c474c5d8387233472341eadca2a54" dependencies = [ "vizia_baseview", "vizia_core", @@ -4387,23 +4347,24 @@ dependencies = [ [[package]] name = "vizia_baseview" version = "0.1.0" -source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#87672c6fdee89d33d4c4a2e1bfff17b4c24a778c" +source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#c4572d7b266c474c5d8387233472341eadca2a54" dependencies = [ "baseview 0.1.0 (git+https://github.com/robbert-vdh/baseview.git?branch=feature/resize)", "femtovg", - "keyboard-types", "lazy_static", - "raw-window-handle", + "raw-window-handle 0.4.3", "vizia_core", + "vizia_id", + "vizia_input", ] [[package]] name = "vizia_core" version = "0.1.0" -source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#87672c6fdee89d33d4c4a2e1bfff17b4c24a778c" +source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#c4572d7b266c474c5d8387233472341eadca2a54" dependencies = [ "bitflags", - "copypasta 0.7.1", + "copypasta 0.8.1", "cssparser", "femtovg", "fluent-bundle", @@ -4412,36 +4373,75 @@ dependencies = [ "fnv", "image 0.24.2", "instant", - "keyboard-types", "morphorm", "sys-locale", "unic-langid", "unicode-bidi", "unicode-segmentation", "vizia_derive", + "vizia_id", + "vizia_input", + "vizia_storage", + "vizia_window", "web-sys", ] [[package]] name = "vizia_derive" version = "0.1.0" -source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#87672c6fdee89d33d4c4a2e1bfff17b4c24a778c" +source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#c4572d7b266c474c5d8387233472341eadca2a54" dependencies = [ "proc-macro2", "quote", "syn", ] +[[package]] +name = "vizia_id" +version = "0.1.0" +source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#c4572d7b266c474c5d8387233472341eadca2a54" + +[[package]] +name = "vizia_input" +version = "0.1.0" +source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#c4572d7b266c474c5d8387233472341eadca2a54" +dependencies = [ + "bitflags", + "keyboard-types", + "vizia_id", +] + +[[package]] +name = "vizia_storage" +version = "0.1.0" +source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#c4572d7b266c474c5d8387233472341eadca2a54" +dependencies = [ + "morphorm", + "vizia_id", +] + +[[package]] +name = "vizia_window" +version = "0.1.0" +source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#c4572d7b266c474c5d8387233472341eadca2a54" +dependencies = [ + "morphorm", + "vizia_input", +] + [[package]] name = "vizia_winit" version = "0.1.0" -source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#87672c6fdee89d33d4c4a2e1bfff17b4c24a778c" +source = "git+https://github.com/robbert-vdh/vizia.git?branch=patched#c4572d7b266c474c5d8387233472341eadca2a54" dependencies = [ "console_error_panic_hook", + "copypasta 0.8.1", "femtovg", "glutin", - "keyboard-types", "vizia_core", + "vizia_id", + "vizia_input", + "vizia_window", "wasm-bindgen", "web-sys", "winit", @@ -4703,7 +4703,7 @@ dependencies = [ "log", "naga", "parking_lot 0.11.2", - "raw-window-handle", + "raw-window-handle 0.4.3", "smallvec", "wasm-bindgen", "wasm-bindgen-futures", @@ -4729,7 +4729,7 @@ dependencies = [ "naga", "parking_lot 0.11.2", "profiling", - "raw-window-handle", + "raw-window-handle 0.4.3", "smallvec", "thiserror", "wgpu-hal", @@ -4765,7 +4765,7 @@ dependencies = [ "parking_lot 0.11.2", "profiling", "range-alloc", - "raw-window-handle", + "raw-window-handle 0.4.3", "renderdoc-sys", "thiserror", "wasm-bindgen", @@ -4929,31 +4929,30 @@ checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" [[package]] name = "winit" -version = "0.26.1" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b43cc931d58b99461188607efd7acb2a093e65fc621f54cad78517a6063e73a" +checksum = "a22e94ba35ca3ff11820044bfa0dc48b95a3a15569c0068555566a12ef41c9e5" dependencies = [ "bitflags", "cocoa", - "core-foundation 0.9.3", - "core-graphics 0.22.3", - "core-video-sys", + "core-foundation", + "core-graphics", "dispatch", "instant", - "lazy_static", "libc", "log", "mio", - "ndk 0.5.0", - "ndk-glue 0.5.2", - "ndk-sys 0.2.2", + "ndk 0.7.0", + "ndk-glue 0.7.0", "objc", - "parking_lot 0.11.2", + "once_cell", + "parking_lot 0.12.1", "percent-encoding", - "raw-window-handle", + "raw-window-handle 0.4.3", + "raw-window-handle 0.5.0", "wasm-bindgen", "web-sys", - "winapi", + "windows-sys", "x11-dl", ] diff --git a/nih_plug_vizia/src/lib.rs b/nih_plug_vizia/src/lib.rs index ca2e5061..6a92f535 100644 --- a/nih_plug_vizia/src/lib.rs +++ b/nih_plug_vizia/src/lib.rs @@ -192,14 +192,14 @@ impl Editor for ViziaEditor { cx.set_default_font(assets::NOTO_SANS_LIGHT); // TOOD: `:root { background-color: #fafafa; }` in a stylesheet doesn't work - cx.style() + cx.style .background_color .insert(Entity::root(), Color::rgb(250, 250, 250)); - cx.style() + cx.style .font_color .insert(Entity::root(), Color::rgb(10, 10, 10)); // VIZIA uses points instead of pixels, this is 20px - cx.style().font_size.insert(Entity::root(), 15.0); + cx.style.font_size.insert(Entity::root(), 15.0); cx.add_theme(include_str!("../assets/theme.css")); // There doesn't seem to be any way to bundle styles with a widget, so we'll always diff --git a/nih_plug_vizia/src/widgets.rs b/nih_plug_vizia/src/widgets.rs index e4662fb0..1c729edd 100644 --- a/nih_plug_vizia/src/widgets.rs +++ b/nih_plug_vizia/src/widgets.rs @@ -75,7 +75,7 @@ pub(crate) struct WindowModel { } impl Model for ParamModel { - fn event(&mut self, _cx: &mut Context, event: &mut Event) { + fn event(&mut self, _cx: &mut EventContext, event: &mut Event) { // `ParamEvent` gets downcast into `NormalizedParamEvent` by the `Message` // implementation below event.map(|param_event, _| match *param_event { @@ -91,7 +91,7 @@ impl Model for ParamModel { } impl Model for WindowModel { - fn event(&mut self, cx: &mut Context, event: &mut Event) { + fn event(&mut self, cx: &mut EventContext, event: &mut Event) { // This gets fired whenever the inner window gets resized event.map(|window_event, _| { if let WindowEvent::WindowResize = window_event { diff --git a/nih_plug_vizia/src/widgets/param_slider.rs b/nih_plug_vizia/src/widgets/param_slider.rs index de310cef..902ce987 100644 --- a/nih_plug_vizia/src/widgets/param_slider.rs +++ b/nih_plug_vizia/src/widgets/param_slider.rs @@ -33,13 +33,11 @@ pub struct ParamSlider { /// active. granular_drag_start_x_value: Option<(f32, f32)>, - /// What style to use for the slider. style: ParamSliderStyle, /// Will be set to `true` when the field gets Alt+Click'ed which will replace the label with a /// text box. text_input_active: bool, - } /// How the [`ParamSlider`] should display its values. Set this using @@ -115,7 +113,6 @@ impl ParamSlider { text_input_active: false, } .build(cx, move |cx| { - Binding::new(cx, ParamSlider::style, move |cx, style| { let style = style.get(cx); let draw_fill_from_default = matches!(style, ParamSliderStyle::Centered) @@ -350,7 +347,7 @@ impl ParamSlider { /// Set the normalized value for a parameter if that would change the parameter's plain value /// (to avoid unnecessary duplicate parameter changes). The begin- and end set parameter /// messages need to be sent before calling this function. - fn set_normalized_value(&self, cx: &mut Context, normalized_value: f32) { + fn set_normalized_value(&self, cx: &mut EventContext, normalized_value: f32) { // This snaps to the nearest plain value if the parameter is stepped in some way. // TODO: As an optimization, we could add a `const CONTINUOUS: bool` to the parameter to // avoid this normalized->plain->normalized conversion for parameters that don't need @@ -370,12 +367,11 @@ impl ParamSlider { /// `set_normalized_value()`, but resulting from a mouse drag. When using the 'even' stepped /// slider styles from [`ParamSliderStyle`] this will remap the normalized range to match up /// with the fill value display. - fn set_normalized_value_drag(&self, cx: &mut Context, normalized_value: f32) { + fn set_normalized_value_drag(&self, cx: &mut EventContext, normalized_value: f32) { let normalized_value = match (self.style, unsafe { self.param_ptr.step_count() }) { ( - - ParamSliderStyle::CurrentStep { even: true } | ParamSliderStyle::CurrentStepLabeled { even: true }, - + ParamSliderStyle::CurrentStep { even: true } + | ParamSliderStyle::CurrentStepLabeled { even: true }, Some(step_count), ) => { // We'll remap the value range to be the same as the displayed range, e.g. with each @@ -397,7 +393,7 @@ impl View for ParamSlider { Some("param-slider") } - fn event(&mut self, cx: &mut Context, event: &mut Event) { + fn event(&mut self, cx: &mut EventContext, event: &mut Event) { event.map(|param_slider_event, _| match param_slider_event { ParamSliderEvent::CancelTextInput => { self.text_input_active = false; @@ -418,11 +414,11 @@ impl View for ParamSlider { event.map(|window_event, _| match window_event { WindowEvent::MouseDown(MouseButton::Left) => { - if cx.modifiers().alt() { + if cx.modifiers.alt() { // ALt+Click brings up a text entry dialog self.text_input_active = true; cx.set_active(true); - } else if cx.modifiers().command() || self.is_double_click { + } else if cx.modifiers.command() || self.is_double_click { // Ctrl+Click and double click should reset the parameter instead of initiating // a drag operation cx.emit(RawParamEvent::BeginSetParameter(self.param_ptr)); @@ -441,15 +437,15 @@ impl View for ParamSlider { // When holding down shift while clicking on a parameter we want to granuarly // edit the parameter without jumping to a new value cx.emit(RawParamEvent::BeginSetParameter(self.param_ptr)); - if cx.modifiers().shift() { - self.granular_drag_start_x_value = Some((cx.mouse().cursorx, unsafe { + if cx.modifiers.shift() { + self.granular_drag_start_x_value = Some((cx.mouse.cursorx, unsafe { self.param_ptr.unmodulated_normalized_value() })); } else { self.granular_drag_start_x_value = None; self.set_normalized_value_drag( cx, - util::remap_current_entity_x_coordinate(cx, cx.mouse().cursorx), + util::remap_current_entity_x_coordinate(cx, cx.mouse.cursorx), ); } } @@ -475,10 +471,10 @@ impl View for ParamSlider { if self.drag_active { // If shift is being held then the drag should be more granular instead of // absolute - if cx.modifiers().shift() { + if cx.modifiers.shift() { let (drag_start_x, drag_start_value) = *self.granular_drag_start_x_value.get_or_insert_with(|| { - (cx.mouse().cursorx, unsafe { + (cx.mouse.cursorx, unsafe { self.param_ptr.unmodulated_normalized_value() }) }); @@ -509,7 +505,7 @@ impl View for ParamSlider { self.granular_drag_start_x_value = None; self.set_normalized_value( cx, - util::remap_current_entity_x_coordinate(cx, cx.mouse().cursorx), + util::remap_current_entity_x_coordinate(cx, cx.mouse.cursorx), ); } } diff --git a/nih_plug_vizia/src/widgets/peak_meter.rs b/nih_plug_vizia/src/widgets/peak_meter.rs index b12cee0e..1b42d381 100644 --- a/nih_plug_vizia/src/widgets/peak_meter.rs +++ b/nih_plug_vizia/src/widgets/peak_meter.rs @@ -47,11 +47,11 @@ impl PeakMeter { // Now for something that may be illegal under some jurisdictions. If a hold time is // given, then we'll build a new lens that always gives the held peak level for the // current moment in time by mutating some values captured into the mapping closure. - let peak_dbfs = match hold_time { - Some(hold_time) => { - let held_peak_value_db = Cell::new(f32::MIN); - let last_held_peak_value: Cell> = Cell::new(None); - level_dbfs.clone().map(move |level| -> f32 { + let held_peak_value_db = Cell::new(f32::MIN); + let last_held_peak_value: Cell> = Cell::new(None); + let peak_dbfs = level_dbfs.clone().map(move |level| -> f32 { + match hold_time { + Some(hold_time) => { let mut peak_level = held_peak_value_db.get(); let peak_time = last_held_peak_value.get(); @@ -66,12 +66,10 @@ impl PeakMeter { } peak_level - }) + } + None => util::MINUS_INFINITY_DB, } - None => level_dbfs - .clone() - .map(|_level| -> f32 { util::MINUS_INFINITY_DB }), - }; + }); PeakMeterBar { level_dbfs, @@ -98,8 +96,8 @@ impl PeakMeter { Element::new(cx).class("ticks__tick"); } - let font_size = cx.style_ref().font_size.get(cx.current()).unwrap_or(&15.0) - * cx.style_ref().dpi_factor as f32; + let font_size = cx.style.font_size.get(cx.current()).unwrap_or(&15.0) + * cx.style.dpi_factor as f32; let label = if first_tick { Label::new(cx, "-inf") .class("ticks__label") @@ -149,23 +147,22 @@ where let peak_dbfs = self.peak_dbfs.get(cx); // These basics are taken directly from the default implementation of this function - let entity = cx.current(); - let bounds = cx.cache().get_bounds(entity); + let bounds = cx.bounds(); if bounds.w == 0.0 || bounds.h == 0.0 { return; } // TODO: It would be cool to allow the text color property to control the gradient here. For // now we'll only support basic background colors and borders. - let background_color = cx.background_color(entity).cloned().unwrap_or_default(); - let border_color = cx.border_color(entity).cloned().unwrap_or_default(); - let opacity = cx.cache().get_opacity(entity); + let background_color = cx.background_color().cloned().unwrap_or_default(); + let border_color = cx.border_color().cloned().unwrap_or_default(); + let opacity = cx.opacity(); let mut background_color: vg::Color = background_color.into(); background_color.set_alphaf(background_color.a * opacity); let mut border_color: vg::Color = border_color.into(); border_color.set_alphaf(border_color.a * opacity); - let border_width = match cx.border_width(entity).unwrap_or_default() { + let border_width = match cx.border_width().unwrap_or_default() { Units::Pixels(val) => val, Units::Percentage(val) => bounds.w.min(bounds.h) * (val / 100.0), _ => 0.0, diff --git a/nih_plug_vizia/src/widgets/resize_handle.rs b/nih_plug_vizia/src/widgets/resize_handle.rs index a6b7bae9..4fb938b9 100644 --- a/nih_plug_vizia/src/widgets/resize_handle.rs +++ b/nih_plug_vizia/src/widgets/resize_handle.rs @@ -40,24 +40,24 @@ impl View for ResizeHandle { Some("resize-handle") } - fn event(&mut self, cx: &mut Context, event: &mut Event) { + fn event(&mut self, cx: &mut EventContext, event: &mut Event) { event.map(|window_event, meta| match *window_event { WindowEvent::MouseDown(MouseButton::Left) => { // The handle is a triangle, so we should also interac twith it as if it was a // triangle if intersects_triangle( - cx.cache_ref().get_bounds(cx.current()), - (cx.mouse().cursorx, cx.mouse().cursory), + cx.cache.get_bounds(cx.current()), + (cx.mouse.cursorx, cx.mouse.cursory), ) { cx.capture(); cx.set_active(true); self.drag_active = true; self.start_scale_factor = cx.user_scale_factor(); - self.start_dpi_factor = cx.style().dpi_factor; + self.start_dpi_factor = cx.style.dpi_factor; self.start_physical_coordinates = ( - cx.mouse().cursorx * cx.style().dpi_factor as f32, - cx.mouse().cursory * cx.style().dpi_factor as f32, + cx.mouse.cursorx * cx.style.dpi_factor as f32, + cx.mouse.cursory * cx.style.dpi_factor as f32, ); meta.consume(); @@ -75,7 +75,7 @@ impl View for ResizeHandle { } WindowEvent::MouseMove(x, y) => { cx.set_hover(intersects_triangle( - cx.cache_ref().get_bounds(cx.current()), + cx.cache.get_bounds(cx.current()), (x, y), )); @@ -111,21 +111,20 @@ impl View for ResizeHandle { // We'll draw the handle directly as styling elements for this is going to be a bit tricky // These basics are taken directly from the default implementation of this function - let entity = cx.current(); - let bounds = cx.cache().get_bounds(entity); + let bounds = cx.bounds(); if bounds.w == 0.0 || bounds.h == 0.0 { return; } - let background_color = cx.background_color(entity).copied().unwrap_or_default(); - let border_color = cx.border_color(entity).copied().unwrap_or_default(); - let opacity = cx.cache().get_opacity(entity); + let background_color = cx.background_color().copied().unwrap_or_default(); + let border_color = cx.border_color().copied().unwrap_or_default(); + let opacity = cx.opacity(); let mut background_color: vg::Color = background_color.into(); background_color.set_alphaf(background_color.a * opacity); let mut border_color: vg::Color = border_color.into(); border_color.set_alphaf(border_color.a * opacity); - let border_width = match cx.border_width(entity).unwrap_or_default() { + let border_width = match cx.border_width().unwrap_or_default() { Units::Pixels(val) => val, Units::Percentage(val) => bounds.w.min(bounds.h) * (val / 100.0), _ => 0.0, @@ -180,11 +179,7 @@ impl View for ResizeHandle { // path.move_to(x + (w / 3.0 * 1.5), y + h); // path.close(); - let mut color: vg::Color = cx - .font_color(entity) - .copied() - .unwrap_or(Color::white()) - .into(); + let mut color: vg::Color = cx.font_color().copied().unwrap_or(Color::white()).into(); color.set_alphaf(color.a * opacity); let paint = vg::Paint::color(color); canvas.fill_path(&mut path, paint); diff --git a/nih_plug_vizia/src/widgets/util.rs b/nih_plug_vizia/src/widgets/util.rs index 55461657..0e5d2750 100644 --- a/nih_plug_vizia/src/widgets/util.rs +++ b/nih_plug_vizia/src/widgets/util.rs @@ -36,48 +36,48 @@ impl ModifiersExt for Modifiers { /// Remap a `[0, 1]` value to an x-coordinate within the current entity's bounding box. The value /// will be clamped to `[0, 1]` if it isn't already in that range. This ignores the border width. -pub fn remap_current_entity_x_t(cx: &Context, t: f32) -> f32 { - let border_width = match cx.style_ref().border_width.get(cx.current()) { +pub fn remap_current_entity_x_t(cx: &EventContext, t: f32) -> f32 { + let border_width = match cx.style.border_width.get(cx.current()) { Some(Units::Pixels(x)) => *x, _ => 0.0, }; - let x_pos = cx.cache_ref().get_posx(cx.current()) + border_width; - let width = cx.cache_ref().get_width(cx.current()) - (border_width * 2.0); + let x_pos = cx.cache.get_posx(cx.current()) + border_width; + let width = cx.cache.get_width(cx.current()) - (border_width * 2.0); x_pos + (width * t.clamp(0.0, 1.0)) } /// Remap a `[0, 1]` value to a y-coordinate within the current entity's bounding box. The value /// will be clamped to `[0, 1]` if it isn't already in that range. This ignores the border width. -pub fn remap_current_entity_y_t(cx: &Context, t: f32) -> f32 { - let border_width = match cx.style_ref().border_width.get(cx.current()) { +pub fn remap_current_entity_y_t(cx: &EventContext, t: f32) -> f32 { + let border_width = match cx.style.border_width.get(cx.current()) { Some(Units::Pixels(x)) => *x, _ => 0.0, }; - let y_pos = cx.cache_ref().get_posy(cx.current()) + border_width; - let height = cx.cache_ref().get_height(cx.current()) - (border_width * 2.0); + let y_pos = cx.cache.get_posy(cx.current()) + border_width; + let height = cx.cache.get_height(cx.current()) - (border_width * 2.0); y_pos + (height * t.clamp(0.0, 1.0)) } /// Remap an x-coordinate to a `[0, 1]` value within the current entity's bounding box. The value /// will be clamped to `[0, 1]` if it isn't already in that range. This ignores the border width. -pub fn remap_current_entity_x_coordinate(cx: &Context, x_coord: f32) -> f32 { - let border_width = match cx.style_ref().border_width.get(cx.current()) { +pub fn remap_current_entity_x_coordinate(cx: &EventContext, x_coord: f32) -> f32 { + let border_width = match cx.style.border_width.get(cx.current()) { Some(Units::Pixels(x)) => *x, _ => 0.0, }; - let x_pos = cx.cache_ref().get_posx(cx.current()) + border_width; - let width = cx.cache_ref().get_width(cx.current()) - (border_width * 2.0); + let x_pos = cx.cache.get_posx(cx.current()) + border_width; + let width = cx.cache.get_width(cx.current()) - (border_width * 2.0); ((x_coord - x_pos) / width).clamp(0.0, 1.0) } /// Remap an y-coordinate to a `[0, 1]` value within the current entity's bounding box. The value /// will be clamped to `[0, 1]` if it isn't already in that range. This ignores the border width. -pub fn remap_current_entity_y_coordinate(cx: &Context, y_coord: f32) -> f32 { - let border_width = match cx.style_ref().border_width.get(cx.current()) { +pub fn remap_current_entity_y_coordinate(cx: &EventContext, y_coord: f32) -> f32 { + let border_width = match cx.style.border_width.get(cx.current()) { Some(Units::Pixels(x)) => *x, _ => 0.0, }; - let y_pos = cx.cache_ref().get_posy(cx.current()) + border_width; - let height = cx.cache_ref().get_height(cx.current()) - (border_width * 2.0); + let y_pos = cx.cache.get_posy(cx.current()) + border_width; + let height = cx.cache.get_height(cx.current()) - (border_width * 2.0); ((y_coord - y_pos) / height).clamp(0.0, 1.0) }