use super::*;
impl Widget {
pub fn id(&self) -> WidgetId {
self.0
}
pub fn is_alive(&self) -> bool {
core::is_alive(self.0)
}
pub fn destroy(&self) {
core::destroy(self.0)
}
pub fn set_enabled(&self, v: bool) {
core::set_flag(self.0, false, v)
}
pub fn enabled(&self) -> bool {
core::read(self.0, |n| n.enabled).unwrap_or(false)
}
pub fn set_visible(&self, v: bool) {
core::set_flag(self.0, true, v)
}
pub fn visible(&self) -> bool {
core::read(self.0, |n| n.visible).unwrap_or(false)
}
pub fn set_tooltip(&self, t: &str) {
core::set(
self.0,
false,
|n| n.tooltip = t.to_string(),
Prop::Tooltip(t),
);
}
pub fn focus(&self) {
core::set(self.0, false, |_| {}, Prop::Focus);
}
pub fn set_expand(&self, weight: f32) {
core::update(self.0, true, |n| n.lay.expand = weight.max(0.0));
}
pub fn set_align(&self, a: Align) {
core::update(self.0, true, |n| n.lay.align = a);
}
pub fn set_min_size(&self, w: i32, h: i32) {
let min = Size::new(px(w), px(h));
if core::update(self.0, true, |n| n.lay.min = min) == Some(Kind::Window) {
B::set(self.0, &Prop::MinSize(min));
}
}
pub fn set_fixed_size(&self, w: i32, h: i32) {
core::update(self.0, true, |n| {
n.lay.fixed = Some(Size::new(px(w), px(h)))
});
}
pub fn set_spacing(&self, px: i32) {
core::update(self.0, true, |n| n.lay.spacing = self::px(px));
}
pub fn set_padding(&self, px: i32) {
core::update(self.0, true, |n| n.lay.padding = self::px(px));
}
pub fn set_cell(&self, col: usize, row: usize, colspan: usize, rowspan: usize) {
core::update(self.0, true, |n| {
n.lay.cell = Some((
col.min(MAX_CELL),
row.min(MAX_CELL),
colspan.clamp(1, MAX_CELL),
rowspan.clamp(1, MAX_CELL),
))
});
}
pub fn bounds(&self) -> Rect {
core::read(self.0, |n| n.bounds).unwrap_or_default()
}
pub fn set_a11y_name(&self, s: &str) {
core::update(self.0, false, |n| n.a11y.name = Some(s.to_string()));
}
pub fn set_a11y_description(&self, s: &str) {
core::update(self.0, false, |n| n.a11y.desc = Some(s.to_string()));
}
pub fn set_a11y_role(&self, r: A11yRole) {
core::update(self.0, false, |n| n.a11y.role = Some(r));
}
pub fn a11y(&self) -> A11yProps {
core::read(self.0, |n| n.a11y.clone()).unwrap_or_default()
}
pub fn set_context_menu(&self, popup: impl Into<WidgetId>) {
let p = popup.into();
core::update(self.0, false, |n| n.context_menu = Some(p));
}
pub fn clear_context_menu(&self) {
core::update(self.0, false, |n| n.context_menu = None);
}
pub fn on_context_menu(&self, mut f: impl FnMut(i32, i32) + 'static) {
on(self.0, Ev::ContextMenu, move |e| {
if let Event::ContextMenu { x, y } = e {
f(*x, *y)
}
});
}
pub fn native_handle(&self) -> Option<NativeHandle> {
core::native_handle(self.0)
}
}