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"
|
||||
dependencies = [
|
||||
"nih_plug",
|
||||
"nih_plug_egui",
|
||||
"nih_plug_iced",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
//! list of sliders and labels.
|
||||
|
||||
use atomic_refcell::AtomicRefCell;
|
||||
use iced_baseview::Row;
|
||||
use std::borrow::Borrow;
|
||||
use std::collections::HashMap;
|
||||
use std::marker::PhantomData;
|
||||
|
@ -16,7 +15,7 @@ use crate::backend::Renderer;
|
|||
use crate::text::Renderer as TextRenderer;
|
||||
use crate::{
|
||||
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
|
||||
|
@ -69,6 +68,7 @@ pub struct GenericUi<'a, W: ParamWidget> {
|
|||
height: Length,
|
||||
max_width: 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
|
||||
/// message type anyways.
|
||||
|
@ -104,6 +104,7 @@ where
|
|||
height: Length::Fill,
|
||||
max_width: u32::MAX,
|
||||
max_height: u32::MAX,
|
||||
pad_scrollbar: false,
|
||||
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
|
@ -133,6 +134,12 @@ where
|
|||
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
|
||||
/// mutably borrow the `Scrollable`'s widget state.
|
||||
fn with_scrollable_widget<T, R, F>(
|
||||
|
@ -178,8 +185,7 @@ where
|
|||
unsafe { &mut *(widget_state.get_mut(¶m_ptr).unwrap() as *mut _) };
|
||||
|
||||
// Show the label next to the parameter for better use of the space
|
||||
scrollable = scrollable.push(
|
||||
Row::new()
|
||||
let mut row = Row::new()
|
||||
.width(Length::Fill)
|
||||
.align_items(Alignment::Center)
|
||||
.spacing(spacing * 2)
|
||||
|
@ -192,8 +198,14 @@ where
|
|||
)
|
||||
.push(unsafe {
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue