Introduce viewport to Widget::draw

This should eventually allow us to only generate primitives that are
visible.
This commit is contained in:
Héctor Ramón Jiménez 2020-08-18 03:37:32 +02:00
parent 8a3ce90959
commit d328b07b39
31 changed files with 123 additions and 35 deletions

View file

@ -62,6 +62,7 @@ where
},
content_layout,
cursor_position,
&bounds,
);
(

View file

@ -8,8 +8,8 @@
//! [`Frame`]: struct.Frame.html
use crate::{Backend, Defaults, Primitive, Renderer};
use iced_native::{
layout, mouse, Clipboard, Element, Hasher, Layout, Length, Point, Size,
Vector, Widget,
layout, mouse, Clipboard, Element, Hasher, Layout, Length, Point,
Rectangle, Size, Vector, Widget,
};
use std::hash::Hash;
use std::marker::PhantomData;
@ -196,6 +196,7 @@ where
_defaults: &Defaults,
layout: Layout<'_>,
cursor_position: Point,
_viewport: &Rectangle,
) -> (Primitive, mouse::Interaction) {
let bounds = layout.bounds();
let translation = Vector::new(bounds.x, bounds.y);

View file

@ -1,7 +1,7 @@
use crate::{Backend, Primitive, Renderer};
use iced_native::column;
use iced_native::mouse;
use iced_native::{Element, Layout, Point};
use iced_native::{Element, Layout, Point, Rectangle};
/// A container that distributes its contents vertically.
pub type Column<'a, Message, Backend> =
@ -17,6 +17,7 @@ where
content: &[Element<'_, Message, Self>],
layout: Layout<'_>,
cursor_position: Point,
viewport: &Rectangle,
) -> Self::Output {
let mut mouse_interaction = mouse::Interaction::default();
@ -26,8 +27,13 @@ where
.iter()
.zip(layout.children())
.map(|(child, layout)| {
let (primitive, new_mouse_interaction) =
child.draw(self, defaults, layout, cursor_position);
let (primitive, new_mouse_interaction) = child.draw(
self,
defaults,
layout,
cursor_position,
viewport,
);
if new_mouse_interaction > mouse_interaction {
mouse_interaction = new_mouse_interaction;

View file

@ -24,6 +24,7 @@ where
defaults: &Defaults,
bounds: Rectangle,
cursor_position: Point,
viewport: &Rectangle,
style_sheet: &Self::Style,
content: &Element<'_, Message, Self>,
content_layout: Layout<'_>,
@ -36,8 +37,13 @@ where
},
};
let (content, mouse_interaction) =
content.draw(self, &defaults, content_layout, cursor_position);
let (content, mouse_interaction) = content.draw(
self,
&defaults,
content_layout,
cursor_position,
viewport,
);
if let Some(background) = background(bounds, &style) {
(

View file

@ -137,7 +137,7 @@ where
let (body, body_layout) = body;
let (body_primitive, body_interaction) =
body.draw(self, defaults, body_layout, cursor_position);
body.draw(self, defaults, body_layout, cursor_position, &bounds);
let background = crate::widget::container::background(bounds, &style);
@ -224,6 +224,7 @@ where
&defaults,
controls_layout,
cursor_position,
&bounds,
);
(

View file

@ -1,7 +1,7 @@
use crate::{Backend, Primitive, Renderer};
use iced_native::mouse;
use iced_native::row;
use iced_native::{Element, Layout, Point};
use iced_native::{Element, Layout, Point, Rectangle};
/// A container that distributes its contents horizontally.
pub type Row<'a, Message, Backend> =
@ -17,6 +17,7 @@ where
content: &[Element<'_, Message, Self>],
layout: Layout<'_>,
cursor_position: Point,
viewport: &Rectangle,
) -> Self::Output {
let mut mouse_interaction = mouse::Interaction::default();
@ -26,8 +27,13 @@ where
.iter()
.zip(layout.children())
.map(|(child, layout)| {
let (primitive, new_mouse_interaction) =
child.draw(self, defaults, layout, cursor_position);
let (primitive, new_mouse_interaction) = child.draw(
self,
defaults,
layout,
cursor_position,
viewport,
);
if new_mouse_interaction > mouse_interaction {
mouse_interaction = new_mouse_interaction;