use super::*;
impl Splitter {
pub fn new(parent: impl Into<WidgetId>, orientation: Orientation) -> Splitter {
let s = make(Splitter::from_id, Kind::Splitter, parent, |n| {
n.lay.padding = 0;
n.lay.expand = 1.0;
if let Some(sp) = n.split_mut() {
sp.orient = orientation;
}
});
if s.is_alive() {
core::create_sash(s.id(), orientation);
}
s
}
pub fn orientation(&self) -> Orientation {
core::read(self.id(), |n| n.split().map(|s| s.orient))
.flatten()
.unwrap_or_default()
}
pub fn set_position(&self, px: i32) {
core::split_set(self.id(), self::px(px), false);
}
pub fn position(&self) -> i32 {
core::read(self.id(), |n| {
n.split().map_or(0, |s| {
if s.laid_out {
s.actual
} else {
s.pos.unwrap_or(0)
}
})
})
.unwrap_or(0)
}
pub fn set_min_pane_sizes(&self, first: i32, second: i32) {
core::update(self.id(), true, |n| {
if let Some(s) = n.split_mut() {
s.min = (self::px(first), self::px(second));
}
});
}
pub fn on_move(&self, mut f: impl FnMut(i32) + 'static) {
on(self.id(), Ev::SashMoved, move |e| {
if let Event::SashDragged(p) = e {
f(*p)
}
});
}
}