Revert "Remove layout method from core::Renderer trait"
This reverts commit 2128472c2a.
This commit is contained in:
parent
98febd9a42
commit
cdce03cf7f
3 changed files with 32 additions and 9 deletions
|
|
@ -5,13 +5,26 @@ mod null;
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
pub use null::Null;
|
pub use null::Null;
|
||||||
|
|
||||||
use crate::{Background, BorderRadius, Color, Rectangle, Vector};
|
use crate::layout;
|
||||||
|
use crate::{Background, BorderRadius, Color, Element, Rectangle, Vector};
|
||||||
|
|
||||||
/// A component that can be used by widgets to draw themselves on a screen.
|
/// A component that can be used by widgets to draw themselves on a screen.
|
||||||
pub trait Renderer: Sized {
|
pub trait Renderer: Sized {
|
||||||
/// The supported theme of the [`Renderer`].
|
/// The supported theme of the [`Renderer`].
|
||||||
type Theme;
|
type Theme;
|
||||||
|
|
||||||
|
/// Lays out the elements of a user interface.
|
||||||
|
///
|
||||||
|
/// You should override this if you need to perform any operations before or
|
||||||
|
/// after layouting. For instance, trimming the measurements cache.
|
||||||
|
fn layout<Message>(
|
||||||
|
&mut self,
|
||||||
|
element: &Element<'_, Message, Self>,
|
||||||
|
limits: &layout::Limits,
|
||||||
|
) -> layout::Node {
|
||||||
|
element.as_widget().layout(self, limits)
|
||||||
|
}
|
||||||
|
|
||||||
/// Draws the primitives recorded in the given closure in a new layer.
|
/// Draws the primitives recorded in the given closure in a new layer.
|
||||||
///
|
///
|
||||||
/// The layer will clip its contents to the provided `bounds`.
|
/// The layer will clip its contents to the provided `bounds`.
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,13 @@ use crate::backend::{self, Backend};
|
||||||
use crate::Primitive;
|
use crate::Primitive;
|
||||||
|
|
||||||
use iced_core::image;
|
use iced_core::image;
|
||||||
|
use iced_core::layout;
|
||||||
use iced_core::renderer;
|
use iced_core::renderer;
|
||||||
use iced_core::svg;
|
use iced_core::svg;
|
||||||
use iced_core::text::{self, Text};
|
use iced_core::text::{self, Text};
|
||||||
use iced_core::{Background, Color, Font, Point, Rectangle, Size, Vector};
|
use iced_core::{
|
||||||
|
Background, Color, Element, Font, Point, Rectangle, Size, Vector,
|
||||||
|
};
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
@ -85,6 +88,14 @@ impl<B: Backend, T> Renderer<B, T> {
|
||||||
impl<B: Backend, T> iced_core::Renderer for Renderer<B, T> {
|
impl<B: Backend, T> iced_core::Renderer for Renderer<B, T> {
|
||||||
type Theme = T;
|
type Theme = T;
|
||||||
|
|
||||||
|
fn layout<Message>(
|
||||||
|
&mut self,
|
||||||
|
element: &Element<'_, Message, Self>,
|
||||||
|
limits: &layout::Limits,
|
||||||
|
) -> layout::Node {
|
||||||
|
element.as_widget().layout(self, limits)
|
||||||
|
}
|
||||||
|
|
||||||
fn with_layer(&mut self, bounds: Rectangle, f: impl FnOnce(&mut Self)) {
|
fn with_layer(&mut self, bounds: Rectangle, f: impl FnOnce(&mut Self)) {
|
||||||
let current = self.start_layer();
|
let current = self.start_layer();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -95,9 +95,8 @@ where
|
||||||
let Cache { mut state } = cache;
|
let Cache { mut state } = cache;
|
||||||
state.diff(root.as_widget());
|
state.diff(root.as_widget());
|
||||||
|
|
||||||
let base = root
|
let base =
|
||||||
.as_widget()
|
renderer.layout(&root, &layout::Limits::new(Size::ZERO, bounds));
|
||||||
.layout(renderer, &layout::Limits::new(Size::ZERO, bounds));
|
|
||||||
|
|
||||||
UserInterface {
|
UserInterface {
|
||||||
root,
|
root,
|
||||||
|
|
@ -227,8 +226,8 @@ where
|
||||||
if shell.is_layout_invalid() {
|
if shell.is_layout_invalid() {
|
||||||
let _ = ManuallyDrop::into_inner(manual_overlay);
|
let _ = ManuallyDrop::into_inner(manual_overlay);
|
||||||
|
|
||||||
self.base = self.root.as_widget().layout(
|
self.base = renderer.layout(
|
||||||
renderer,
|
&self.root,
|
||||||
&layout::Limits::new(Size::ZERO, self.bounds),
|
&layout::Limits::new(Size::ZERO, self.bounds),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -323,8 +322,8 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
shell.revalidate_layout(|| {
|
shell.revalidate_layout(|| {
|
||||||
self.base = self.root.as_widget().layout(
|
self.base = renderer.layout(
|
||||||
renderer,
|
&self.root,
|
||||||
&layout::Limits::new(Size::ZERO, self.bounds),
|
&layout::Limits::new(Size::ZERO, self.bounds),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue