use std::cell::Cell;
use std::rc::Rc;
use crate::geometry::{Rect, Size};
use crate::layout_props::{HAnchor, Insets, VAnchor};
use super::{Window, VISIBILITY_FADE_SECS};
impl Window {
pub fn with_live_content(mut self, live: bool) -> Self {
self.live_content = live;
self
}
pub fn on_raised(mut self, cb: impl FnMut(&str) + 'static) -> Self {
self.on_raised = Some(Box::new(cb));
self
}
pub fn with_bounds(mut self, b: Rect) -> Self {
self.pre_collapse_h = b.height;
self.bounds = b;
if self.maximized {
self.pre_maximize_bounds = b;
}
self
}
pub fn with_font_size(mut self, size: f64) -> Self {
self.font_size = size;
self
}
pub fn with_visible_cell(mut self, cell: Rc<Cell<bool>>) -> Self {
let visible = cell.get();
self.last_visible.set(visible);
self.fade_out_active.set(false);
self.visibility_anim =
crate::animation::Tween::new(if visible { 1.0 } else { 0.0 }, VISIBILITY_FADE_SECS);
self.visible_cell = Some(cell);
self
}
pub fn with_reset_cell(mut self, cell: Rc<Cell<Option<Rect>>>) -> Self {
self.reset_to = Some(cell);
self
}
pub fn with_position_cell(mut self, cell: Rc<Cell<Rect>>) -> Self {
self.position_cell = Some(cell);
self
}
pub fn with_maximized_cell(mut self, cell: Rc<Cell<bool>>) -> Self {
self.maximized = cell.get();
if self.maximized {
self.pre_maximize_bounds = self.bounds;
}
self.maximized_cell = Some(cell);
self
}
pub fn with_margin(mut self, m: Insets) -> Self {
self.base.margin = m;
self
}
pub fn with_h_anchor(mut self, h: HAnchor) -> Self {
self.base.h_anchor = h;
self
}
pub fn with_v_anchor(mut self, v: VAnchor) -> Self {
self.base.v_anchor = v;
self
}
pub fn with_min_size(mut self, s: Size) -> Self {
self.base.min_size = s;
self
}
pub fn with_max_size(mut self, s: Size) -> Self {
self.base.max_size = s;
self
}
pub fn with_constrain(mut self, constrain: bool) -> Self {
self.constrain = constrain;
self
}
pub fn with_gl_backbuffer(mut self, enabled: bool) -> Self {
self.use_gl_backbuffer = enabled;
self.backbuffer.invalidate();
self
}
pub fn with_auto_size(mut self, auto: bool) -> Self {
self.auto_size = auto;
self
}
pub fn with_resizable(mut self, on: bool) -> Self {
self.resizable = on;
self
}
pub fn with_resizable_axes(mut self, h: bool, v: bool) -> Self {
self.resizable = h || v;
self.resizable_h = h;
self.resizable_v = v;
self
}
pub fn with_tight_content_fit(mut self, on: bool) -> Self {
self.tight_content_fit = on;
self
}
pub fn with_height_floor_to_content(mut self, on: bool) -> Self {
self.floor_content_height = on;
self
}
pub fn with_vscroll(mut self, vscroll: bool) -> Self {
if vscroll {
if let Some(content) = self.children.pop() {
let scroll = crate::widgets::ScrollView::new(content)
.vertical(true)
.horizontal(false);
self.children.push(Box::new(scroll));
}
}
self
}
pub fn on_close(mut self, cb: impl FnMut() + 'static) -> Self {
self.on_close = Some(Box::new(cb));
self
}
}