diff options
author | 2021-10-14 16:07:22 +0700 | |
---|---|---|
committer | 2021-10-14 16:07:22 +0700 | |
commit | 03b34931383e701c39c653a7662a616fe21a0947 (patch) | |
tree | 8c0773d50b615dbc62210db8919ecb97ca912bd9 /examples | |
parent | 3aae45c1913e6a6f60b009f19d00d10add7ad11e (diff) | |
download | iced-03b34931383e701c39c653a7662a616fe21a0947.tar.gz iced-03b34931383e701c39c653a7662a616fe21a0947.tar.bz2 iced-03b34931383e701c39c653a7662a616fe21a0947.zip |
Remove trait-specific draw logic in `iced_native`
Diffstat (limited to 'examples')
-rw-r--r-- | examples/custom_widget/src/main.rs | 27 | ||||
-rw-r--r-- | examples/geometry/src/main.rs | 183 | ||||
-rw-r--r-- | examples/integration_opengl/src/main.rs | 26 | ||||
-rw-r--r-- | examples/integration_wgpu/src/main.rs | 30 |
4 files changed, 136 insertions, 130 deletions
diff --git a/examples/custom_widget/src/main.rs b/examples/custom_widget/src/main.rs index c9ad1905..648e7295 100644 --- a/examples/custom_widget/src/main.rs +++ b/examples/custom_widget/src/main.rs @@ -11,8 +11,7 @@ mod circle { // implemented by `iced_wgpu` and other renderers. use iced_graphics::{Backend, Defaults, Primitive, Renderer}; use iced_native::{ - layout, mouse, Background, Color, Element, Hasher, Layout, Length, - Point, Rectangle, Size, Widget, + layout, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget, }; pub struct Circle { @@ -55,20 +54,20 @@ mod circle { &self, _renderer: &mut Renderer<B>, _defaults: &Defaults, - layout: Layout<'_>, + _layout: Layout<'_>, _cursor_position: Point, _viewport: &Rectangle, - ) -> (Primitive, mouse::Interaction) { - ( - Primitive::Quad { - bounds: layout.bounds(), - background: Background::Color(Color::BLACK), - border_radius: self.radius, - border_width: 0.0, - border_color: Color::TRANSPARENT, - }, - mouse::Interaction::default(), - ) + ) { + // ( + // Primitive::Quad { + // bounds: layout.bounds(), + // background: Background::Color(Color::BLACK), + // border_radius: self.radius, + // border_width: 0.0, + // border_color: Color::TRANSPARENT, + // }, + // mouse::Interaction::default(), + // ) } } diff --git a/examples/geometry/src/main.rs b/examples/geometry/src/main.rs index e5115493..0745739a 100644 --- a/examples/geometry/src/main.rs +++ b/examples/geometry/src/main.rs @@ -55,98 +55,99 @@ mod rainbow { &self, _renderer: &mut Renderer<B>, _defaults: &Defaults, - layout: Layout<'_>, - cursor_position: Point, + _layout: Layout<'_>, + _cursor_position: Point, _viewport: &Rectangle, - ) -> (Primitive, mouse::Interaction) { - let b = layout.bounds(); - - // R O Y G B I V - let color_r = [1.0, 0.0, 0.0, 1.0]; - let color_o = [1.0, 0.5, 0.0, 1.0]; - let color_y = [1.0, 1.0, 0.0, 1.0]; - let color_g = [0.0, 1.0, 0.0, 1.0]; - let color_gb = [0.0, 1.0, 0.5, 1.0]; - let color_b = [0.0, 0.2, 1.0, 1.0]; - let color_i = [0.5, 0.0, 1.0, 1.0]; - let color_v = [0.75, 0.0, 0.5, 1.0]; - - let posn_center = { - if b.contains(cursor_position) { - [cursor_position.x - b.x, cursor_position.y - b.y] - } else { - [b.width / 2.0, b.height / 2.0] - } - }; - - let posn_tl = [0.0, 0.0]; - let posn_t = [b.width / 2.0, 0.0]; - let posn_tr = [b.width, 0.0]; - let posn_r = [b.width, b.height / 2.0]; - let posn_br = [b.width, b.height]; - let posn_b = [(b.width / 2.0), b.height]; - 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 - ], - }, - }), - }, - mouse::Interaction::default(), - ) + ) { + // let b = layout.bounds(); + + // // R O Y G B I V + // let color_r = [1.0, 0.0, 0.0, 1.0]; + // let color_o = [1.0, 0.5, 0.0, 1.0]; + // let color_y = [1.0, 1.0, 0.0, 1.0]; + // let color_g = [0.0, 1.0, 0.0, 1.0]; + // let color_gb = [0.0, 1.0, 0.5, 1.0]; + // let color_b = [0.0, 0.2, 1.0, 1.0]; + // let color_i = [0.5, 0.0, 1.0, 1.0]; + // let color_v = [0.75, 0.0, 0.5, 1.0]; + + // let posn_center = { + // if b.contains(cursor_position) { + // [cursor_position.x - b.x, cursor_position.y - b.y] + // } else { + // [b.width / 2.0, b.height / 2.0] + // } + // }; + + // let posn_tl = [0.0, 0.0]; + // let posn_t = [b.width / 2.0, 0.0]; + // let posn_tr = [b.width, 0.0]; + // let posn_r = [b.width, b.height / 2.0]; + // let posn_br = [b.width, b.height]; + // let posn_b = [(b.width / 2.0), b.height]; + // 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 + // ], + // }, + // }), + // }, + // mouse::Interaction::default(), + // ) + // TODO } } diff --git a/examples/integration_opengl/src/main.rs b/examples/integration_opengl/src/main.rs index f80915d2..bab6331e 100644 --- a/examples/integration_opengl/src/main.rs +++ b/examples/integration_opengl/src/main.rs @@ -160,18 +160,22 @@ pub fn main() { } // And then iced on top - let mouse_interaction = renderer.backend_mut().draw( - &gl, - &viewport, - state.primitive(), - &debug.overlay(), - ); + renderer.present(|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, - ), - ); + // TODO + // windowed_context.window().set_cursor_icon( + // iced_winit::conversion::mouse_interaction( + // mouse_interaction, + // ), + // ); windowed_context.swap_buffers().unwrap(); } diff --git a/examples/integration_wgpu/src/main.rs b/examples/integration_wgpu/src/main.rs index 7ef148bc..9980acc2 100644 --- a/examples/integration_wgpu/src/main.rs +++ b/examples/integration_wgpu/src/main.rs @@ -195,26 +195,28 @@ 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.present(|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())); // Update the mouse cursor - window.set_cursor_icon( - iced_winit::conversion::mouse_interaction( - mouse_interaction, - ), - ); + // window.set_cursor_icon( + // iced_winit::conversion::mouse_interaction( + // mouse_interaction, + // ), + // ); // And recall staging buffers local_pool |