Avoid restoring window sizes with ViziaState
Unless specified otherwise. This avoids some bugs where old, now incorrect sizes are being recalled.
This commit is contained in:
parent
e621ec9b59
commit
e3a923ff3b
|
@ -6,6 +6,13 @@ new and what's changed, this document lists all breaking changes in reverse
|
||||||
chronological order. If a new feature did not require any changes to existing
|
chronological order. If a new feature did not require any changes to existing
|
||||||
code then it will not be listed here.
|
code then it will not be listed here.
|
||||||
|
|
||||||
|
## [2023-02-28]
|
||||||
|
|
||||||
|
- `ViziaState::from_size()` now takes a third boolean argument to control
|
||||||
|
whether the window's size is persisted or not. This avoids a potential bug
|
||||||
|
where an old window size is recalled after the plugin's GUI's size has changed
|
||||||
|
in an update to the plugin.
|
||||||
|
|
||||||
## [2023-02-20]
|
## [2023-02-20]
|
||||||
|
|
||||||
- The way audio IO layouts are configured has changed completely to align better
|
- The way audio IO layouts are configured has changed completely to align better
|
||||||
|
|
|
@ -95,11 +95,17 @@ pub struct ViziaState {
|
||||||
/// Whether the editor's window is currently open.
|
/// Whether the editor's window is currently open.
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
open: AtomicBool,
|
open: AtomicBool,
|
||||||
|
|
||||||
|
/// Whether the size should be saved. If the window's size is always scaled uniformly, then this
|
||||||
|
/// is not needed and can only result in problems.
|
||||||
|
should_save_size: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> PersistentField<'a, ViziaState> for Arc<ViziaState> {
|
impl<'a> PersistentField<'a, ViziaState> for Arc<ViziaState> {
|
||||||
fn set(&self, new_value: ViziaState) {
|
fn set(&self, new_value: ViziaState) {
|
||||||
|
if self.should_save_size {
|
||||||
self.size.store(new_value.size.load());
|
self.size.store(new_value.size.load());
|
||||||
|
}
|
||||||
self.scale_factor.store(new_value.scale_factor.load());
|
self.scale_factor.store(new_value.scale_factor.load());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,22 +120,34 @@ impl<'a> PersistentField<'a, ViziaState> for Arc<ViziaState> {
|
||||||
impl ViziaState {
|
impl ViziaState {
|
||||||
/// Initialize the GUI's state. This value can be passed to [`create_vizia_editor()`]. The
|
/// Initialize the GUI's state. This value can be passed to [`create_vizia_editor()`]. The
|
||||||
/// window size is in logical pixels, so before it is multiplied by the DPI scaling factor.
|
/// window size is in logical pixels, so before it is multiplied by the DPI scaling factor.
|
||||||
pub fn from_size(width: u32, height: u32) -> Arc<ViziaState> {
|
///
|
||||||
|
/// Setting `should_save_size` to `false` may be useful when the size is supposed to be fixed
|
||||||
|
/// and only the scaling factor changes. This allows the object to be persisted in a `Params`
|
||||||
|
/// object without accidentally restoring old sizes after the window's logical size has changed
|
||||||
|
/// in a plugin update.
|
||||||
|
pub fn from_size(width: u32, height: u32, should_save_size: bool) -> Arc<ViziaState> {
|
||||||
Arc::new(ViziaState {
|
Arc::new(ViziaState {
|
||||||
size: AtomicCell::new((width, height)),
|
size: AtomicCell::new((width, height)),
|
||||||
scale_factor: AtomicCell::new(1.0),
|
scale_factor: AtomicCell::new(1.0),
|
||||||
open: AtomicBool::new(false),
|
open: AtomicBool::new(false),
|
||||||
|
should_save_size,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The same as [`from_size()`][Self::from_size()], but with a separate initial scale factor.
|
/// The same as [`from_size()`][Self::from_size()], but with a separate initial scale factor.
|
||||||
/// This scale factor gets applied on top of any HiDPI scaling, and it can be modified at
|
/// This scale factor gets applied on top of any HiDPI scaling, and it can be modified at
|
||||||
/// runtime by changing `cx.user_scale_factor`.
|
/// runtime by changing `cx.user_scale_factor`.
|
||||||
pub fn from_size_with_scale(width: u32, height: u32, scale_factor: f64) -> Arc<ViziaState> {
|
pub fn from_size_with_scale(
|
||||||
|
width: u32,
|
||||||
|
height: u32,
|
||||||
|
scale_factor: f64,
|
||||||
|
should_save_size: bool,
|
||||||
|
) -> Arc<ViziaState> {
|
||||||
Arc::new(ViziaState {
|
Arc::new(ViziaState {
|
||||||
size: AtomicCell::new((width, height)),
|
size: AtomicCell::new((width, height)),
|
||||||
scale_factor: AtomicCell::new(scale_factor),
|
scale_factor: AtomicCell::new(scale_factor),
|
||||||
open: AtomicBool::new(false),
|
open: AtomicBool::new(false),
|
||||||
|
should_save_size,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ impl Model for Data {}
|
||||||
|
|
||||||
// Makes sense to also define this here, makes it a bit easier to keep track of
|
// Makes sense to also define this here, makes it a bit easier to keep track of
|
||||||
pub(crate) fn default_state() -> Arc<ViziaState> {
|
pub(crate) fn default_state() -> Arc<ViziaState> {
|
||||||
ViziaState::from_size(400, 390)
|
ViziaState::from_size(400, 390, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn create(
|
pub(crate) fn create(
|
||||||
|
|
|
@ -60,7 +60,7 @@ impl Model for Data {}
|
||||||
|
|
||||||
// Makes sense to also define this here, makes it a bit easier to keep track of
|
// Makes sense to also define this here, makes it a bit easier to keep track of
|
||||||
pub(crate) fn default_state() -> Arc<ViziaState> {
|
pub(crate) fn default_state() -> Arc<ViziaState> {
|
||||||
ViziaState::from_size(EDITOR_WIDTH, EDITOR_HEIGHT)
|
ViziaState::from_size(EDITOR_WIDTH, EDITOR_HEIGHT, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn create(editor_data: Data, editor_state: Arc<ViziaState>) -> Option<Box<dyn Editor>> {
|
pub(crate) fn create(editor_data: Data, editor_state: Arc<ViziaState>) -> Option<Box<dyn Editor>> {
|
||||||
|
|
|
@ -19,7 +19,7 @@ impl Model for Data {}
|
||||||
|
|
||||||
// Makes sense to also define this here, makes it a bit easier to keep track of
|
// Makes sense to also define this here, makes it a bit easier to keep track of
|
||||||
pub(crate) fn default_state() -> Arc<ViziaState> {
|
pub(crate) fn default_state() -> Arc<ViziaState> {
|
||||||
ViziaState::from_size(200, 150)
|
ViziaState::from_size(200, 150, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn create(
|
pub(crate) fn create(
|
||||||
|
|
|
@ -36,7 +36,7 @@ impl Model for Data {}
|
||||||
|
|
||||||
// Makes sense to also define this here, makes it a bit easier to keep track of
|
// Makes sense to also define this here, makes it a bit easier to keep track of
|
||||||
pub(crate) fn default_state() -> Arc<ViziaState> {
|
pub(crate) fn default_state() -> Arc<ViziaState> {
|
||||||
ViziaState::from_size(680, 535)
|
ViziaState::from_size(680, 535, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn create(
|
pub(crate) fn create(
|
||||||
|
|
Loading…
Reference in a new issue