1
0
mirror of https://github.com/bobwen-dev/hunter synced 2025-04-12 00:55:41 +02:00

hbox working

This commit is contained in:
rabite 2019-01-22 15:11:15 +01:00
parent 7b74dcd037
commit 00c2eb8e46

View File

@ -9,27 +9,65 @@ use crate::widget::Widget;
// active: bool // active: bool
// } // }
pub struct HBox { pub struct HBox {
dimensions: (u16, u16), dimensions: (u16, u16),
position: (u16, u16), position: (u16, u16),
children: Vec<Box<Widget>>, children: Vec<Box<Widget>>,
main: usize active: usize
} }
impl HBox { impl HBox {
pub fn new(widgets: Vec<Box<Widget>>, pub fn new(widgets: Vec<Box<Widget>>,
dimensions: (u16, u16), dimensions: (u16, u16),
position: (u16, u16), position: (u16, u16),
main: usize) -> HBox { main: usize) -> HBox {
HBox { let mut hbox = HBox {
dimensions: dimensions, dimensions: dimensions,
position: position, position: position,
children: widgets, children: widgets,
main: main active: main
};
hbox.resize_children();
hbox
}
pub fn resize_children(&mut self) {
let hbox_size = dbg!(self.dimensions);
let hbox_position = dbg!(self.position);
let cell_size = dbg!(hbox_size.0 / self.children.len() as u16);
let mut current_pos = dbg!(hbox_position.1);
let mut current_edge = dbg!(cell_size);
for mut widget in &mut self.children {
widget.set_dimensions(dbg!((cell_size, hbox_size.1)));
widget.set_position(dbg!((current_pos, hbox_position.1)));
widget.refresh();
dbg!(current_pos += cell_size);
dbg!(current_edge += cell_size);
} }
} }
pub fn resize_child(&mut self, index: usize, size: (u16, u16)) {
self.children[index].set_dimensions(size);
}
pub fn widget(&self, index: usize) -> &Box<Widget> {
&self.children[index]
}
pub fn active_widget(&self, index: usize) -> &Box<Widget> {
&self.children[self.active]
}
} }
impl Widget for HBox { impl Widget for HBox {
fn render(&self) -> Vec<String> { fn render(&self) -> Vec<String> {
// HBox doesnt' draw anything itself // HBox doesnt' draw anything itself