Skip to content

Commit

Permalink
Remove layout method from core::Renderer trait
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Jun 29, 2023
1 parent 0ae1baa commit 2128472
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 32 deletions.
15 changes: 1 addition & 14 deletions core/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,13 @@ mod null;
#[cfg(debug_assertions)]
pub use null::Null;

use crate::layout;
use crate::{Background, BorderRadius, Color, Element, Rectangle, Vector};
use crate::{Background, BorderRadius, Color, Rectangle, Vector};

/// A component that can be used by widgets to draw themselves on a screen.
pub trait Renderer: Sized {
/// The supported theme of the [`Renderer`].
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.
///
/// The layer will clip its contents to the provided `bounds`.
Expand Down
13 changes: 1 addition & 12 deletions graphics/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ use crate::backend::{self, Backend};
use crate::Primitive;

use iced_core::image;
use iced_core::layout;
use iced_core::renderer;
use iced_core::svg;
use iced_core::text::{self, Text};
use iced_core::{
Background, Color, Element, Font, Point, Rectangle, Size, Vector,
};
use iced_core::{Background, Color, Font, Point, Rectangle, Size, Vector};

use std::borrow::Cow;
use std::marker::PhantomData;
Expand Down Expand Up @@ -84,14 +81,6 @@ impl<B: Backend, T> Renderer<B, T> {
impl<B: Backend, T> iced_core::Renderer for Renderer<B, 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)) {
let current = self.start_layer();

Expand Down
13 changes: 7 additions & 6 deletions runtime/src/user_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ where
let Cache { mut state } = cache;
state.diff(root.as_widget());

let base =
renderer.layout(&root, &layout::Limits::new(Size::ZERO, bounds));
let base = root
.as_widget()
.layout(renderer, &layout::Limits::new(Size::ZERO, bounds));

UserInterface {
root,
Expand Down Expand Up @@ -226,8 +227,8 @@ where
if shell.is_layout_invalid() {
let _ = ManuallyDrop::into_inner(manual_overlay);

self.base = renderer.layout(
&self.root,
self.base = self.root.as_widget().layout(
renderer,
&layout::Limits::new(Size::ZERO, self.bounds),
);

Expand Down Expand Up @@ -322,8 +323,8 @@ where
}

shell.revalidate_layout(|| {
self.base = renderer.layout(
&self.root,
self.base = self.root.as_widget().layout(
renderer,
&layout::Limits::new(Size::ZERO, self.bounds),
);

Expand Down

0 comments on commit 2128472

Please sign in to comment.