mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Add panel view
This commit is contained in:
parent
6c71ac14b0
commit
c1c9322319
@ -17,12 +17,11 @@ fn main() {
|
|||||||
|
|
||||||
let n_max = 1000;
|
let n_max = 1000;
|
||||||
|
|
||||||
s.find_id::<Dialog>("dialog")
|
s.pop_layer();
|
||||||
.unwrap()
|
s.add_layer(Panel::new(FullView::full_width(ProgressBar::new()
|
||||||
.set_content(ProgressBar::new()
|
|
||||||
.range(0, n_max)
|
.range(0, n_max)
|
||||||
.with_value(value.clone())
|
.with_value(value.clone())
|
||||||
.with_callback(cb.clone()));
|
.with_callback(cb.clone()))));
|
||||||
|
|
||||||
// Spawn a thread to process things in the background.
|
// Spawn a thread to process things in the background.
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
@ -44,7 +43,7 @@ fn main() {
|
|||||||
.padding((0, 0, 1, 1))
|
.padding((0, 0, 1, 1))
|
||||||
.with_id("dialog"));
|
.with_id("dialog"));
|
||||||
|
|
||||||
siv.set_fps(10);
|
siv.set_fps(30);
|
||||||
|
|
||||||
siv.run();
|
siv.run();
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
pub use {Cursive, Printer, With};
|
pub use {Cursive, Printer, With};
|
||||||
pub use event::{Event, Key};
|
pub use event::{Event, Key};
|
||||||
pub use view::{BoxView, Button, Checkbox, Dialog, EditView, FullView, IdView,
|
pub use view::{BoxView, Button, Checkbox, Dialog, EditView, FullView, IdView,
|
||||||
Identifiable, KeyEventView, LinearLayout, ListView,
|
Identifiable, KeyEventView, LinearLayout, ListView, Panel,
|
||||||
ProgressBar, SelectView, Selector, TextView, View};
|
ProgressBar, SelectView, Selector, TextView, View};
|
||||||
pub use vec::Vec2;
|
pub use vec::Vec2;
|
||||||
pub use menu::MenuTree;
|
pub use menu::MenuTree;
|
||||||
|
@ -58,6 +58,7 @@ mod linear_layout;
|
|||||||
mod list_view;
|
mod list_view;
|
||||||
mod menubar;
|
mod menubar;
|
||||||
mod menu_popup;
|
mod menu_popup;
|
||||||
|
mod panel;
|
||||||
mod progress_bar;
|
mod progress_bar;
|
||||||
mod shadow_view;
|
mod shadow_view;
|
||||||
mod select_view;
|
mod select_view;
|
||||||
@ -92,6 +93,7 @@ pub use self::list_view::ListView;
|
|||||||
pub use self::menubar::Menubar;
|
pub use self::menubar::Menubar;
|
||||||
pub use self::menu_popup::MenuPopup;
|
pub use self::menu_popup::MenuPopup;
|
||||||
pub use self::view_path::ViewPath;
|
pub use self::view_path::ViewPath;
|
||||||
|
pub use self::panel::Panel;
|
||||||
pub use self::progress_bar::ProgressBar;
|
pub use self::progress_bar::ProgressBar;
|
||||||
pub use self::select_view::SelectView;
|
pub use self::select_view::SelectView;
|
||||||
pub use self::shadow_view::ShadowView;
|
pub use self::shadow_view::ShadowView;
|
||||||
|
33
src/view/panel.rs
Normal file
33
src/view/panel.rs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
use Printer;
|
||||||
|
use vec::Vec2;
|
||||||
|
use view::{View, ViewWrapper};
|
||||||
|
|
||||||
|
/// Draws a border around a wrapped view.
|
||||||
|
pub struct Panel<V: View> {
|
||||||
|
view: V,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<V: View> Panel<V> {
|
||||||
|
/// Creates a new panel around the given view.
|
||||||
|
pub fn new(view: V) -> Self {
|
||||||
|
Panel {
|
||||||
|
view: view,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl<V: View> ViewWrapper for Panel<V> {
|
||||||
|
wrap_impl!(&self.view);
|
||||||
|
|
||||||
|
fn wrap_get_min_size(&mut self, req: Vec2) -> Vec2 {
|
||||||
|
// TODO: make borders conditional?
|
||||||
|
self.view.get_min_size(req - (2, 2)) + (2, 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn wrap_draw(&self, printer: &Printer) {
|
||||||
|
printer.print_box((0, 0), printer.size);
|
||||||
|
self.view
|
||||||
|
.draw(&printer.sub_printer((1, 1), printer.size - (2, 2), true));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user