use std::ops::{Deref, DerefMut};
use crate::{
prelude::{Control, NotDesktop, NotWindow},
system::Handle,
ui::Layout,
};
use super::ControlBase;
#[repr(C)]
#[derive(Default)]
pub struct ContainerBase {
pub(crate) control_base: ControlBase,
}
impl ContainerBase {
pub fn new(layout: Layout, accept_input: bool) -> Self {
Self {
control_base: ControlBase::new(layout, accept_input),
}
}
pub fn with_focus_overlay(layout: Layout) -> Self {
Self {
control_base: ControlBase::with_focus_overlay(layout),
}
}
#[inline(always)]
pub fn add<T>(&mut self, control: T) -> Handle<T>
where
T: Control + NotWindow + NotDesktop + 'static,
{
self.add_child(control)
}
#[inline]
pub fn set_margins(&mut self, left: u8, top: u8, right: u8, bottom: u8) {
self.margins.left = left;
self.margins.top = top;
self.margins.bottom = bottom;
self.margins.right = right;
}
}
impl Deref for ContainerBase {
type Target = ControlBase;
#[inline(always)]
fn deref(&self) -> &Self::Target {
&self.control_base
}
}
impl DerefMut for ContainerBase {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.control_base
}
}