Move winit logic from iced to iced_winit
- Added new `renderer::Windowed` trait. This shoud allow users to easily try different renderers by simply changing one line. - Renamed `UserInterface` traits to `Application`, as the `run` method takes total control of the current thread. - Moved `MouseCursor` back to `iced_native`. The new `renderer::Windowed` trait returns one on `draw`. - Split `iced_native` renderer in multiple modules, for consistency.
This commit is contained in:
parent
1a93f0ef4a
commit
a92a0b73ed
13 changed files with 245 additions and 155 deletions
|
|
@ -1,4 +1,3 @@
|
|||
mod mouse_cursor;
|
||||
mod primitive;
|
||||
mod quad;
|
||||
mod renderer;
|
||||
|
|
@ -7,6 +6,5 @@ mod transformation;
|
|||
pub(crate) use quad::Quad;
|
||||
pub(crate) use transformation::Transformation;
|
||||
|
||||
pub use mouse_cursor::MouseCursor;
|
||||
pub use primitive::Primitive;
|
||||
pub use renderer::{Renderer, Target};
|
||||
|
|
|
|||
|
|
@ -1,35 +0,0 @@
|
|||
/// The state of the mouse cursor.
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Copy)]
|
||||
pub enum MouseCursor {
|
||||
/// The cursor is out of the bounds of the user interface.
|
||||
OutOfBounds,
|
||||
|
||||
/// The cursor is over a non-interactive widget.
|
||||
Idle,
|
||||
|
||||
/// The cursor is over a clickable widget.
|
||||
Pointer,
|
||||
|
||||
/// The cursor is over a busy widget.
|
||||
Working,
|
||||
|
||||
/// The cursor is over a grabbable widget.
|
||||
Grab,
|
||||
|
||||
/// The cursor is grabbing a widget.
|
||||
Grabbing,
|
||||
}
|
||||
|
||||
#[cfg(feature = "winit")]
|
||||
impl From<MouseCursor> for winit::window::CursorIcon {
|
||||
fn from(mouse_cursor: MouseCursor) -> winit::window::CursorIcon {
|
||||
match mouse_cursor {
|
||||
MouseCursor::OutOfBounds => winit::window::CursorIcon::Default,
|
||||
MouseCursor::Idle => winit::window::CursorIcon::Default,
|
||||
MouseCursor::Pointer => winit::window::CursorIcon::Hand,
|
||||
MouseCursor::Working => winit::window::CursorIcon::Progress,
|
||||
MouseCursor::Grab => winit::window::CursorIcon::Grab,
|
||||
MouseCursor::Grabbing => winit::window::CursorIcon::Grabbing,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
use crate::{quad, Primitive, Quad, Transformation};
|
||||
use iced_native::{
|
||||
renderer::Debugger, Background, Color, Layout, Point, Widget,
|
||||
renderer::Debugger, renderer::Windowed, Background, Color, Layout,
|
||||
MouseCursor, Point, Widget,
|
||||
};
|
||||
|
||||
use raw_window_handle::HasRawWindowHandle;
|
||||
|
|
@ -41,7 +42,7 @@ pub struct Target {
|
|||
}
|
||||
|
||||
impl Renderer {
|
||||
pub fn new<W: HasRawWindowHandle>(window: &W) -> Self {
|
||||
fn new<W: HasRawWindowHandle>(window: &W) -> Self {
|
||||
let adapter = Adapter::request(&RequestAdapterOptions {
|
||||
power_preference: PowerPreference::LowPower,
|
||||
backends: BackendBit::all(),
|
||||
|
|
@ -79,7 +80,7 @@ impl Renderer {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn target(&self, width: u16, height: u16) -> Target {
|
||||
fn target(&self, width: u16, height: u16) -> Target {
|
||||
Target {
|
||||
width,
|
||||
height,
|
||||
|
|
@ -97,7 +98,11 @@ impl Renderer {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn draw(&mut self, target: &mut Target, primitive: &Primitive) {
|
||||
fn draw(
|
||||
&mut self,
|
||||
target: &mut Target,
|
||||
primitive: &Primitive,
|
||||
) -> MouseCursor {
|
||||
log::debug!("Drawing");
|
||||
|
||||
let frame = target.swap_chain.get_next_texture();
|
||||
|
|
@ -146,8 +151,9 @@ impl Renderer {
|
|||
.expect("Draw text");
|
||||
|
||||
self.queue.submit(&[encoder.finish()]);
|
||||
}
|
||||
|
||||
MouseCursor::OutOfBounds
|
||||
}
|
||||
fn draw_primitive(&mut self, primitive: &Primitive) {
|
||||
match primitive {
|
||||
Primitive::None => {}
|
||||
|
|
@ -240,6 +246,26 @@ impl iced_native::Renderer for Renderer {
|
|||
type Primitive = Primitive;
|
||||
}
|
||||
|
||||
impl Windowed for Renderer {
|
||||
type Target = Target;
|
||||
|
||||
fn new<W: HasRawWindowHandle>(window: &W) -> Self {
|
||||
Self::new(window)
|
||||
}
|
||||
|
||||
fn target(&self, width: u16, height: u16) -> Target {
|
||||
self.target(width, height)
|
||||
}
|
||||
|
||||
fn draw(
|
||||
&mut self,
|
||||
target: &mut Target,
|
||||
primitive: &Primitive,
|
||||
) -> MouseCursor {
|
||||
self.draw(target, primitive)
|
||||
}
|
||||
}
|
||||
|
||||
impl Debugger for Renderer {
|
||||
fn explain<Message>(
|
||||
&mut self,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue