use super::super::{NoAction, Scroll, Style, Ui, UiNode};
pub struct ScrollBuilder<'a, A = NoAction> {
ui: &'a mut Ui<A>,
scroll: Option<Scroll<A>>,
}
impl<'a, A: Clone> ScrollBuilder<'a, A> {
pub(crate) fn new(ui: &'a mut Ui<A>) -> Self {
Self {
ui,
scroll: Some(Scroll::new()),
}
}
pub fn id(mut self, id: impl Into<String>) -> Self {
if let Some(scroll) = self.scroll.as_mut() {
scroll.id = Some(id.into());
}
self
}
pub fn key(mut self, key: impl Into<String>) -> Self {
if let Some(scroll) = self.scroll.as_mut() {
scroll.key = Some(key.into());
}
self
}
pub fn class(mut self, class: impl Into<String>) -> Self {
if let Some(scroll) = self.scroll.as_mut() {
scroll.class = Some(class.into());
}
self
}
pub fn customMinimumSize(mut self, width: u32, height: u32) -> Self {
if let Some(scroll) = self.scroll.as_mut() {
scroll.customMinimumSize = Some((width, height));
}
self
}
pub fn style(mut self, configure: impl FnOnce(&mut Style)) -> Self {
if let Some(scroll) = self.scroll.as_mut() {
configure(&mut scroll.style);
}
self
}
pub fn children(mut self, build: impl FnOnce(&mut Ui<A>)) {
if let Some(mut scroll) = self.scroll.take() {
let mut ui = Ui::new();
build(&mut ui);
scroll.children = ui.nodes;
self.ui.nodes.push(UiNode::Scroll(scroll));
}
}
pub fn empty(mut self) {
if let Some(scroll) = self.scroll.take() {
self.ui.nodes.push(UiNode::Scroll(scroll));
}
}
}
impl<A> Drop for ScrollBuilder<'_, A> {
fn drop(&mut self) {
if let Some(scroll) = self.scroll.take() {
self.ui.nodes.push(UiNode::Scroll(scroll));
}
}
}