Add basis for ScrollView

This commit is contained in:
Alexandre Bury 2018-04-04 17:48:51 -07:00
parent 8f04356baa
commit 4042a45b8d
3 changed files with 29 additions and 0 deletions

View File

@ -14,15 +14,24 @@ use vec::Vec2;
pub struct Printer<'a> { pub struct Printer<'a> {
/// Offset into the window this printer should start drawing at. /// Offset into the window this printer should start drawing at.
pub offset: Vec2, pub offset: Vec2,
/// Offset into the view for this printer.
pub content_offset: Vec2,
/// Size of the area we are allowed to draw on. /// Size of the area we are allowed to draw on.
///
/// Anything outside of this should be discarded.
pub size: Vec2, pub size: Vec2,
/// Whether the view to draw is currently focused or not. /// Whether the view to draw is currently focused or not.
pub focused: bool, pub focused: bool,
/// Currently used theme /// Currently used theme
pub theme: &'a Theme, pub theme: &'a Theme,
/// `true` if nothing has been drawn yet. /// `true` if nothing has been drawn yet.
new: Rc<Cell<bool>>, new: Rc<Cell<bool>>,
/// Backend used to actually draw things /// Backend used to actually draw things
backend: &'a backend::Concrete, backend: &'a backend::Concrete,
} }
@ -37,6 +46,7 @@ impl<'a> Printer<'a> {
) -> Self { ) -> Self {
Printer { Printer {
offset: Vec2::zero(), offset: Vec2::zero(),
content_offset: Vec2::zero(),
size: size.into(), size: size.into(),
focused: true, focused: true,
theme: theme, theme: theme,

View File

@ -53,6 +53,7 @@ mod menu_popup;
mod panel; mod panel;
mod progress_bar; mod progress_bar;
mod radio; mod radio;
mod scroll_view;
mod select_view; mod select_view;
mod slider_view; mod slider_view;
mod shadow_view; mod shadow_view;
@ -79,6 +80,7 @@ pub use self::on_event_view::OnEventView;
pub use self::panel::Panel; pub use self::panel::Panel;
pub use self::progress_bar::{Counter, ProgressBar}; pub use self::progress_bar::{Counter, ProgressBar};
pub use self::radio::{RadioButton, RadioGroup}; pub use self::radio::{RadioButton, RadioGroup};
pub use self::scroll_view::ScrollView;
pub use self::select_view::SelectView; pub use self::select_view::SelectView;
pub use self::shadow_view::ShadowView; pub use self::shadow_view::ShadowView;
pub use self::sized_view::SizedView; pub use self::sized_view::SizedView;

17
src/views/scroll_view.rs Normal file
View File

@ -0,0 +1,17 @@
use view::View;
use Printer;
use vec::Vec2;
/// Wraps a view in a scrollable area.
pub struct ScrollView<V> {
inner: V,
offset: Vec2,
}
impl <V> View for ScrollView<V> where V: View {
fn draw(&self, printer: &Printer) {
self.printer.offset
self.inner.draw(printer);
}
}