diff --git a/examples/select.rs b/examples/select.rs index 2fe2efc..bb47598 100644 --- a/examples/select.rs +++ b/examples/select.rs @@ -9,7 +9,7 @@ fn main() { // Read the list of cities from separate file, and fill the view with it. // (We include the file at compile-time to avoid runtime read errors.) let content = include_str!("../assets/cities.txt"); - select.add_all_str(content.split('\n')); + select.add_all_str(content.lines()); // Sets the callback for when "Enter" is pressed. select.set_on_submit(show_next_window); diff --git a/src/view/scroll.rs b/src/view/scroll.rs index 589486c..bb8f1dd 100644 --- a/src/view/scroll.rs +++ b/src/view/scroll.rs @@ -24,6 +24,9 @@ pub struct ScrollBase { /// (Useful when each item includes its own side borders, /// to draw the scrollbar inside.) pub scrollbar_offset: usize, + + /// Blank between the text and the scrollbar. + pub right_padding: usize, } impl ScrollBase { @@ -34,6 +37,7 @@ impl ScrollBase { content_height: 0, view_height: 0, scrollbar_offset: 0, + right_padding: 1, } } @@ -42,8 +46,16 @@ impl ScrollBase { /// Used by views that draw their side borders in the children. /// Pushing the scrollbar to the left allows it to stay inside /// the borders. - pub fn bar_offset(mut self, padding: usize) -> Self { - self.scrollbar_offset = padding; + pub fn scrollbar_offset(mut self, offset: usize) -> Self { + self.scrollbar_offset = offset; + self + } + + /// Sets the number of blank cells between the text and the scrollbar. + /// + /// Defaults to 1. + pub fn right_padding(mut self, padding: usize) -> Self { + self.right_padding = padding; self } @@ -143,7 +155,8 @@ impl ScrollBase { if printer.size.x < 2 { return; } - printer.size.x - 2 + self.scrollbar_offset + // We have to remove the bar width and the padding. + printer.size.x - 1 - self.right_padding } else { printer.size.x }; @@ -183,7 +196,7 @@ impl ScrollBase { let scrollbar_x = printer.size.x - 1 - self.scrollbar_offset; printer.print_vline((scrollbar_x, 0), printer.size.y, "|"); printer.with_color(color, |printer| { - printer.print_vline((scrollbar_x, start), height, " "); + printer.print_vline((scrollbar_x, start), height, "▒"); }); } } diff --git a/src/views/menu_popup.rs b/src/views/menu_popup.rs index 14b7525..caa525f 100644 --- a/src/views/menu_popup.rs +++ b/src/views/menu_popup.rs @@ -7,7 +7,7 @@ use Cursive; use With; use menu::{MenuItem, MenuTree}; use Printer; -use view::{View, Position, ScrollBase}; +use view::{Position, ScrollBase, View}; use views::KeyEventView; use align::Align; use vec::Vec2; @@ -29,7 +29,7 @@ impl MenuPopup { MenuPopup { menu: menu, focus: 0, - scrollbase: ScrollBase::new().bar_offset(1), + scrollbase: ScrollBase::new().scrollbar_offset(1).right_padding(0), align: Align::top_left(), on_dismiss: None, on_action: None, diff --git a/src/views/select_view.rs b/src/views/select_view.rs index 70a0c5a..4a2fd8c 100644 --- a/src/views/select_view.rs +++ b/src/views/select_view.rs @@ -241,7 +241,7 @@ impl SelectView { } fn focus_down(&mut self, n: usize) { - let focus = min(self.focus() + n, self.items.len()); + let focus = min(self.focus() + n, self.items.len() - 1); self.focus.set(focus); } } diff --git a/src/views/text_area.rs b/src/views/text_area.rs index 9d19f82..6635cf9 100644 --- a/src/views/text_area.rs +++ b/src/views/text_area.rs @@ -52,7 +52,7 @@ impl TextArea { width: 0, }], enabled: true, - scrollbase: ScrollBase::new(), + scrollbase: ScrollBase::new().right_padding(0), last_size: None, cursor: 0, } @@ -287,12 +287,8 @@ impl View for TextArea { self.move_left(); } } - Event::Ctrl(Key::Home) => { - self.cursor = 0 - } - Event::Ctrl(Key::End) => { - self.cursor = self.content.len() - } + Event::Ctrl(Key::Home) => self.cursor = 0, + Event::Ctrl(Key::End) => self.cursor = self.content.len(), Event::Key(Key::Home) => { self.cursor = self.rows[self.selected_row()].start }