diff --git a/src/printer.rs b/src/printer.rs index 16b6bbc..a74e78e 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -14,15 +14,24 @@ use vec::Vec2; pub struct Printer<'a> { /// Offset into the window this printer should start drawing at. pub offset: Vec2, + + /// Offset into the view for this printer. + pub content_offset: Vec2, + /// Size of the area we are allowed to draw on. + /// + /// Anything outside of this should be discarded. pub size: Vec2, + /// Whether the view to draw is currently focused or not. pub focused: bool, + /// Currently used theme pub theme: &'a Theme, /// `true` if nothing has been drawn yet. new: Rc>, + /// Backend used to actually draw things backend: &'a backend::Concrete, } @@ -37,6 +46,7 @@ impl<'a> Printer<'a> { ) -> Self { Printer { offset: Vec2::zero(), + content_offset: Vec2::zero(), size: size.into(), focused: true, theme: theme, diff --git a/src/views/mod.rs b/src/views/mod.rs index b26217a..4435d9d 100644 --- a/src/views/mod.rs +++ b/src/views/mod.rs @@ -53,6 +53,7 @@ mod menu_popup; mod panel; mod progress_bar; mod radio; +mod scroll_view; mod select_view; mod slider_view; mod shadow_view; @@ -79,6 +80,7 @@ pub use self::on_event_view::OnEventView; pub use self::panel::Panel; pub use self::progress_bar::{Counter, ProgressBar}; pub use self::radio::{RadioButton, RadioGroup}; +pub use self::scroll_view::ScrollView; pub use self::select_view::SelectView; pub use self::shadow_view::ShadowView; pub use self::sized_view::SizedView; diff --git a/src/views/scroll_view.rs b/src/views/scroll_view.rs new file mode 100644 index 0000000..40ea325 --- /dev/null +++ b/src/views/scroll_view.rs @@ -0,0 +1,17 @@ +use view::View; +use Printer; +use vec::Vec2; + +/// Wraps a view in a scrollable area. +pub struct ScrollView { + inner: V, + offset: Vec2, +} + +impl View for ScrollView where V: View { + + fn draw(&self, printer: &Printer) { + self.printer.offset + self.inner.draw(printer); + } +}