Add scrollbar padding option to iced generic UI
This makes the scroll bar look less cramped.
This commit is contained in:
parent
1ddc305be5
commit
82f1923399
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -614,7 +614,7 @@ name = "crisp"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"nih_plug",
|
"nih_plug",
|
||||||
"nih_plug_egui",
|
"nih_plug_iced",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
//! list of sliders and labels.
|
//! list of sliders and labels.
|
||||||
|
|
||||||
use atomic_refcell::AtomicRefCell;
|
use atomic_refcell::AtomicRefCell;
|
||||||
use iced_baseview::Row;
|
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
@ -16,7 +15,7 @@ use crate::backend::Renderer;
|
||||||
use crate::text::Renderer as TextRenderer;
|
use crate::text::Renderer as TextRenderer;
|
||||||
use crate::{
|
use crate::{
|
||||||
alignment, event, layout, renderer, widget, Alignment, Clipboard, Element, Event, Layout,
|
alignment, event, layout, renderer, widget, Alignment, Clipboard, Element, Event, Layout,
|
||||||
Length, Point, Rectangle, Scrollable, Shell, Text, Widget,
|
Length, Point, Rectangle, Row, Scrollable, Shell, Space, Text, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A widget that can be used to create a generic UI with. This is used in conjuction with empty
|
/// A widget that can be used to create a generic UI with. This is used in conjuction with empty
|
||||||
|
@ -69,6 +68,7 @@ pub struct GenericUi<'a, W: ParamWidget> {
|
||||||
height: Length,
|
height: Length,
|
||||||
max_width: u32,
|
max_width: u32,
|
||||||
max_height: u32,
|
max_height: u32,
|
||||||
|
pad_scrollbar: bool,
|
||||||
|
|
||||||
/// We don't emit any messages or store the actual widgets, but iced requires us to define some
|
/// We don't emit any messages or store the actual widgets, but iced requires us to define some
|
||||||
/// message type anyways.
|
/// message type anyways.
|
||||||
|
@ -104,6 +104,7 @@ where
|
||||||
height: Length::Fill,
|
height: Length::Fill,
|
||||||
max_width: u32::MAX,
|
max_width: u32::MAX,
|
||||||
max_height: u32::MAX,
|
max_height: u32::MAX,
|
||||||
|
pad_scrollbar: false,
|
||||||
|
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
}
|
}
|
||||||
|
@ -133,6 +134,12 @@ where
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Include additional room on the right for the scroll bar.
|
||||||
|
pub fn pad_scrollbar(mut self) -> Self {
|
||||||
|
self.pad_scrollbar = true;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a temporary [`Scrollable`]. This needs to be created on demand because it needs to
|
/// Create a temporary [`Scrollable`]. This needs to be created on demand because it needs to
|
||||||
/// mutably borrow the `Scrollable`'s widget state.
|
/// mutably borrow the `Scrollable`'s widget state.
|
||||||
fn with_scrollable_widget<T, R, F>(
|
fn with_scrollable_widget<T, R, F>(
|
||||||
|
@ -178,22 +185,27 @@ where
|
||||||
unsafe { &mut *(widget_state.get_mut(¶m_ptr).unwrap() as *mut _) };
|
unsafe { &mut *(widget_state.get_mut(¶m_ptr).unwrap() as *mut _) };
|
||||||
|
|
||||||
// Show the label next to the parameter for better use of the space
|
// Show the label next to the parameter for better use of the space
|
||||||
scrollable = scrollable.push(
|
let mut row = Row::new()
|
||||||
Row::new()
|
.width(Length::Fill)
|
||||||
.width(Length::Fill)
|
.align_items(Alignment::Center)
|
||||||
.align_items(Alignment::Center)
|
.spacing(spacing * 2)
|
||||||
.spacing(spacing * 2)
|
.push(
|
||||||
.push(
|
Text::new(unsafe { param_ptr.name() })
|
||||||
Text::new(unsafe { param_ptr.name() })
|
.height(20.into())
|
||||||
.height(20.into())
|
.width(Length::Fill)
|
||||||
.width(Length::Fill)
|
.horizontal_alignment(alignment::Horizontal::Right)
|
||||||
.horizontal_alignment(alignment::Horizontal::Right)
|
.vertical_alignment(alignment::Vertical::Center),
|
||||||
.vertical_alignment(alignment::Vertical::Center),
|
)
|
||||||
)
|
.push(unsafe {
|
||||||
.push(unsafe {
|
W::into_widget_element_raw(¶m_ptr, self.context, widget_state)
|
||||||
W::into_widget_element_raw(¶m_ptr, self.context, widget_state)
|
});
|
||||||
}),
|
if self.pad_scrollbar {
|
||||||
);
|
// There's already spacing applied, so this element doesn't actually need to hae any
|
||||||
|
// size of its own
|
||||||
|
row = row.push(Space::with_width(Length::Units(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollable = scrollable.push(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
f(scrollable, renderer)
|
f(scrollable, renderer)
|
||||||
|
|
Loading…
Reference in a new issue