Add 'show_divider' field in (V|H)Split

embed
Manos Pitsidianakis 2018-07-22 14:45:22 +03:00
parent 892b3d389a
commit bf0eb66b02
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 25 additions and 17 deletions

View File

@ -85,7 +85,7 @@ fn main() {
let menu = Entity {component: Box::new(AccountMenu::new(&state.context.accounts)) }; let menu = Entity {component: Box::new(AccountMenu::new(&state.context.accounts)) };
let listing = MailListing::new(); let listing = MailListing::new();
let b = Entity { component: Box::new(listing) }; let b = Entity { component: Box::new(listing) };
let window = Entity { component: Box::new(VSplit::new(menu, b, 90)) }; let window = Entity { component: Box::new(VSplit::new(menu, b, 90, true)) };
let status_bar = Entity { component: Box::new(StatusBar::new(window)) }; let status_bar = Entity { component: Box::new(StatusBar::new(window)) };
state.register_entity(status_bar); state.register_entity(status_bar);

View File

@ -8,14 +8,16 @@ use melib::mailbox::email::interpret_format_flowed;
pub struct HSplit { pub struct HSplit {
top: Entity, top: Entity,
bottom: Entity, bottom: Entity,
show_divider: bool,
ratio: usize, // bottom/whole height * 100 ratio: usize, // bottom/whole height * 100
} }
impl HSplit { impl HSplit {
pub fn new(top: Entity, bottom: Entity, ratio: usize) -> Self { pub fn new(top: Entity, bottom: Entity, ratio: usize, show_divider: bool) -> Self {
HSplit { HSplit {
top: top, top: top,
bottom: bottom, bottom: bottom,
show_divider: show_divider,
ratio: ratio, ratio: ratio,
} }
} }
@ -33,8 +35,10 @@ impl Component for HSplit {
let bottom_entity_height = (self.ratio*total_rows )/100; let bottom_entity_height = (self.ratio*total_rows )/100;
let mid = get_y(upper_left) + total_rows - bottom_entity_height; let mid = get_y(upper_left) + total_rows - bottom_entity_height;
for i in get_x(upper_left)..=get_x(bottom_right) { if self.show_divider {
grid[(i, mid)].set_ch('─'); for i in get_x(upper_left)..=get_x(bottom_right) {
grid[(i, mid)].set_ch('─');
}
} }
let _ = self.top.component.draw(grid, let _ = self.top.component.draw(grid,
(upper_left, (get_x(bottom_right), get_y(upper_left) + mid-1)), (upper_left, (get_x(bottom_right), get_y(upper_left) + mid-1)),
@ -57,15 +61,17 @@ impl Component for HSplit {
pub struct VSplit { pub struct VSplit {
left: Entity, left: Entity,
right: Entity, right: Entity,
show_divider: bool,
/// This is the width of the right container to the entire width. /// This is the width of the right container to the entire width.
ratio: usize, // right/(container width) * 100 ratio: usize, // right/(container width) * 100
} }
impl VSplit { impl VSplit {
pub fn new(left: Entity, right: Entity, ratio: usize) -> Self { pub fn new(left: Entity, right: Entity, ratio: usize, show_divider: bool) -> Self {
VSplit { VSplit {
left: left, left: left,
right: right, right: right,
show_divider: show_divider,
ratio: ratio, ratio: ratio,
} }
} }
@ -93,18 +99,20 @@ impl Component for VSplit {
} }
} }
for i in get_y(upper_left)..=get_y(bottom_right) { if self.show_divider {
grid[(mid, i)].set_ch(VERT_BOUNDARY); for i in get_y(upper_left)..=get_y(bottom_right) {
grid[(mid, i)].set_fg(Color::Default); grid[(mid, i)].set_ch(VERT_BOUNDARY);
grid[(mid, i)].set_bg(Color::Default); grid[(mid, i)].set_fg(Color::Default);
} grid[(mid, i)].set_bg(Color::Default);
if get_y(bottom_right)> 1 { }
let c = grid.get(mid, get_y(bottom_right)-1).map(|a| a.ch()).unwrap_or_else(|| ' '); if get_y(bottom_right)> 1 {
match c { let c = grid.get(mid, get_y(bottom_right)-1).map(|a| a.ch()).unwrap_or_else(|| ' ');
HORZ_BOUNDARY => { match c {
grid[(mid, get_y(bottom_right)+1)].set_ch(LIGHT_UP_AND_HORIZONTAL); HORZ_BOUNDARY => {
}, grid[(mid, get_y(bottom_right)+1)].set_ch(LIGHT_UP_AND_HORIZONTAL);
_ => {}, },
_ => {},
}
} }
} }
let _ = self.left.component.draw(grid, let _ = self.left.component.draw(grid,