use std::cell::Cell;
use newt_sys::*;
use crate::component::Component;
use crate::grid::Parent;
use crate::widgets::Button;
use crate::asm;
#[derive(Grid)]
pub struct ButtonBar {
co: Cell<newtGrid>,
added_to_parent: Cell<bool>,
children: Vec<Button>
}
impl ButtonBar {
pub fn new(buttons: &[&str]) -> ButtonBar {
let grid: newtGrid;
let len = buttons.len();
let mut buttons_buf: Vec<newtComponent> = Vec::with_capacity(len);
unsafe {
let buttons_ptr: *mut newtComponent = buttons_buf.as_mut_ptr();
grid = asm::button_bar_new(buttons, buttons_ptr);
buttons_buf.set_len(len);
}
let mut buttons = Vec::with_capacity(len);
for co in buttons_buf {
buttons.push(Button::new_co(co));
}
ButtonBar {
co: Cell::new(grid),
added_to_parent: Cell::new(false),
children: buttons
}
}
pub fn buttons(&self) -> &[Button] {
self.children.as_slice()
}
}
impl Parent for ButtonBar {
fn children(&self) -> Vec<&dyn Component> {
let len = self.children.len();
let mut vec: Vec<&dyn Component> = Vec::with_capacity(len);
for child in self.children.iter() {
vec.push(child);
}
vec
}
}