Skip to content

Commit

Permalink
Merge pull request #1110 from iced-rs/remove-renderer-traits
Browse files Browse the repository at this point in the history
Reduce the surface of the `Renderer` APIs
  • Loading branch information
hecrj authored Nov 7, 2021
2 parents 61c747b + 07b5097 commit eafad00
Show file tree
Hide file tree
Showing 142 changed files with 3,316 additions and 4,560 deletions.
1 change: 0 additions & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
pub mod alignment;
pub mod keyboard;
pub mod mouse;
pub mod text;

mod background;
mod color;
Expand Down
29 changes: 0 additions & 29 deletions core/src/text.rs

This file was deleted.

1 change: 0 additions & 1 deletion examples/custom_widget/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ publish = false
[dependencies]
iced = { path = "../.." }
iced_native = { path = "../../native" }
iced_graphics = { path = "../../graphics" }
33 changes: 16 additions & 17 deletions examples/custom_widget/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ mod circle {
// Of course, you can choose to make the implementation renderer-agnostic,
// if you wish to, by creating your own `Renderer` trait, which could be
// implemented by `iced_wgpu` and other renderers.
use iced_graphics::{Backend, Defaults, Primitive, Renderer};
use iced_native::layout::{self, Layout};
use iced_native::renderer;
use iced_native::{
layout, mouse, Background, Color, Element, Hasher, Layout, Length,
Point, Rectangle, Size, Widget,
Color, Element, Hasher, Length, Point, Rectangle, Size, Widget,
};

pub struct Circle {
Expand All @@ -25,9 +25,9 @@ mod circle {
}
}

impl<Message, B> Widget<Message, Renderer<B>> for Circle
impl<Message, Renderer> Widget<Message, Renderer> for Circle
where
B: Backend,
Renderer: renderer::Renderer,
{
fn width(&self) -> Length {
Length::Shrink
Expand All @@ -39,7 +39,7 @@ mod circle {

fn layout(
&self,
_renderer: &Renderer<B>,
_renderer: &Renderer,
_limits: &layout::Limits,
) -> layout::Node {
layout::Node::new(Size::new(self.radius * 2.0, self.radius * 2.0))
Expand All @@ -53,30 +53,29 @@ mod circle {

fn draw(
&self,
_renderer: &mut Renderer<B>,
_defaults: &Defaults,
renderer: &mut Renderer,
_style: &renderer::Style,
layout: Layout<'_>,
_cursor_position: Point,
_viewport: &Rectangle,
) -> (Primitive, mouse::Interaction) {
(
Primitive::Quad {
) {
renderer.fill_quad(
renderer::Quad {
bounds: layout.bounds(),
background: Background::Color(Color::BLACK),
border_radius: self.radius,
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
mouse::Interaction::default(),
)
Color::BLACK,
);
}
}

impl<'a, Message, B> Into<Element<'a, Message, Renderer<B>>> for Circle
impl<'a, Message, Renderer> Into<Element<'a, Message, Renderer>> for Circle
where
B: Backend,
Renderer: renderer::Renderer,
{
fn into(self) -> Element<'a, Message, Renderer<B>> {
fn into(self) -> Element<'a, Message, Renderer> {
Element::new(self)
}
}
Expand Down
130 changes: 65 additions & 65 deletions examples/geometry/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ mod rainbow {
// Of course, you can choose to make the implementation renderer-agnostic,
// if you wish to, by creating your own `Renderer` trait, which could be
// implemented by `iced_wgpu` and other renderers.
use iced_graphics::{
triangle::{Mesh2D, Vertex2D},
Backend, Defaults, Primitive, Renderer,
};
use iced_graphics::renderer::{self, Renderer};
use iced_graphics::{Backend, Primitive};

use iced_native::{
layout, mouse, Element, Hasher, Layout, Length, Point, Rectangle, Size,
layout, Element, Hasher, Layout, Length, Point, Rectangle, Size,
Vector, Widget,
};

Expand Down Expand Up @@ -53,12 +52,15 @@ mod rainbow {

fn draw(
&self,
_renderer: &mut Renderer<B>,
_defaults: &Defaults,
renderer: &mut Renderer<B>,
_style: &renderer::Style,
layout: Layout<'_>,
cursor_position: Point,
_viewport: &Rectangle,
) -> (Primitive, mouse::Interaction) {
) {
use iced_graphics::triangle::{Mesh2D, Vertex2D};
use iced_native::Renderer as _;

let b = layout.bounds();

// R O Y G B I V
Expand Down Expand Up @@ -88,65 +90,63 @@ mod rainbow {
let posn_bl = [0.0, b.height];
let posn_l = [0.0, b.height / 2.0];

(
Primitive::Translate {
translation: Vector::new(b.x, b.y),
content: Box::new(Primitive::Mesh2D {
size: b.size(),
buffers: Mesh2D {
vertices: vec![
Vertex2D {
position: posn_center,
color: [1.0, 1.0, 1.0, 1.0],
},
Vertex2D {
position: posn_tl,
color: color_r,
},
Vertex2D {
position: posn_t,
color: color_o,
},
Vertex2D {
position: posn_tr,
color: color_y,
},
Vertex2D {
position: posn_r,
color: color_g,
},
Vertex2D {
position: posn_br,
color: color_gb,
},
Vertex2D {
position: posn_b,
color: color_b,
},
Vertex2D {
position: posn_bl,
color: color_i,
},
Vertex2D {
position: posn_l,
color: color_v,
},
],
indices: vec![
0, 1, 2, // TL
0, 2, 3, // T
0, 3, 4, // TR
0, 4, 5, // R
0, 5, 6, // BR
0, 6, 7, // B
0, 7, 8, // BL
0, 8, 1, // L
],
let mesh = Primitive::Mesh2D {
size: b.size(),
buffers: Mesh2D {
vertices: vec![
Vertex2D {
position: posn_center,
color: [1.0, 1.0, 1.0, 1.0],
},
Vertex2D {
position: posn_tl,
color: color_r,
},
Vertex2D {
position: posn_t,
color: color_o,
},
Vertex2D {
position: posn_tr,
color: color_y,
},
Vertex2D {
position: posn_r,
color: color_g,
},
}),
Vertex2D {
position: posn_br,
color: color_gb,
},
Vertex2D {
position: posn_b,
color: color_b,
},
Vertex2D {
position: posn_bl,
color: color_i,
},
Vertex2D {
position: posn_l,
color: color_v,
},
],
indices: vec![
0, 1, 2, // TL
0, 2, 3, // T
0, 3, 4, // TR
0, 4, 5, // R
0, 5, 6, // BR
0, 6, 7, // B
0, 7, 8, // BL
0, 8, 1, // L
],
},
mouse::Interaction::default(),
)
};

renderer.with_translation(Vector::new(b.x, b.y), |renderer| {
renderer.draw_primitive(mesh);
});
}
}

Expand Down
8 changes: 3 additions & 5 deletions examples/integration_opengl/src/controls.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use iced_glow::Renderer;
use iced_glutin::slider;
use iced_glutin::{
Alignment, Color, Column, Command, Element, Length, Program, Row, Slider,
Text,
};
use iced_glutin::widget::slider::{self, Slider};
use iced_glutin::widget::{Column, Row, Text};
use iced_glutin::{Alignment, Color, Command, Element, Length, Program};

pub struct Controls {
background_color: Color,
Expand Down
18 changes: 10 additions & 8 deletions examples/integration_opengl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ pub fn main() {
let mut state = program::State::new(
controls,
viewport.logical_size(),
conversion::cursor_position(cursor_position, viewport.scale_factor()),
&mut renderer,
&mut debug,
);
Expand Down Expand Up @@ -160,16 +159,19 @@ pub fn main() {
}

// And then iced on top
let mouse_interaction = renderer.backend_mut().draw(
&gl,
&viewport,
state.primitive(),
&debug.overlay(),
);
renderer.with_primitives(|backend, primitive| {
backend.present(
&gl,
primitive,
&viewport,
&debug.overlay(),
);
});

// Update the mouse cursor
windowed_context.window().set_cursor_icon(
iced_winit::conversion::mouse_interaction(
mouse_interaction,
state.mouse_interaction(),
),
);

Expand Down
7 changes: 3 additions & 4 deletions examples/integration_wgpu/src/controls.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use iced_wgpu::Renderer;
use iced_winit::{
slider, Alignment, Color, Column, Command, Element, Length, Program, Row,
Slider, Text,
};
use iced_winit::widget::slider::{self, Slider};
use iced_winit::widget::{Column, Row, Text};
use iced_winit::{Alignment, Color, Command, Element, Length, Program};

pub struct Controls {
background_color: Color,
Expand Down
31 changes: 16 additions & 15 deletions examples/integration_wgpu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ pub fn main() {
let mut state = program::State::new(
controls,
viewport.logical_size(),
conversion::cursor_position(cursor_position, viewport.scale_factor()),
&mut renderer,
&mut debug,
);
Expand Down Expand Up @@ -196,27 +195,29 @@ pub fn main() {
}

// And then iced on top
let mouse_interaction = renderer.backend_mut().draw(
&mut device,
&mut staging_belt,
&mut encoder,
&view,
&viewport,
state.primitive(),
&debug.overlay(),
);
renderer.with_primitives(|backend, primitive| {
backend.present(
&mut device,
&mut staging_belt,
&mut encoder,
&view,
primitive,
&viewport,
&debug.overlay(),
);
});

// Then we submit the work
staging_belt.finish();
queue.submit(Some(encoder.finish()));
frame.present();

// Update the mouse cursor
window.set_cursor_icon(
iced_winit::conversion::mouse_interaction(
mouse_interaction,
),
);
window.set_cursor_icon(
iced_winit::conversion::mouse_interaction(
state.mouse_interaction(),
),
);

// And recall staging buffers
local_pool
Expand Down
Loading

0 comments on commit eafad00

Please sign in to comment.