diff options
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/Cargo.toml | 1 | ||||
-rw-r--r-- | graphics/src/error.rs | 7 | ||||
-rw-r--r-- | graphics/src/lib.rs | 2 | ||||
-rw-r--r-- | graphics/src/widget/radio.rs | 20 | ||||
-rw-r--r-- | graphics/src/window/compositor.rs | 4 | ||||
-rw-r--r-- | graphics/src/window/gl_compositor.rs | 4 |
6 files changed, 24 insertions, 14 deletions
diff --git a/graphics/Cargo.toml b/graphics/Cargo.toml index 723b9232..dec24c59 100644 --- a/graphics/Cargo.toml +++ b/graphics/Cargo.toml @@ -15,6 +15,7 @@ opengl = [] bytemuck = "1.2" glam = "0.9" raw-window-handle = "0.3" +thiserror = "1.0" [dependencies.iced_native] version = "0.2" diff --git a/graphics/src/error.rs b/graphics/src/error.rs new file mode 100644 index 00000000..c86e326a --- /dev/null +++ b/graphics/src/error.rs @@ -0,0 +1,7 @@ +/// A graphical error that occurred while running an application. +#[derive(Debug, thiserror::Error)] +pub enum Error { + /// A suitable graphics adapter or device could not be found + #[error("a suitable graphics adapter or device could not be found")] + AdapterNotFound, +} diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs index d03f3b48..a3bd5364 100644 --- a/graphics/src/lib.rs +++ b/graphics/src/lib.rs @@ -9,6 +9,7 @@ #![forbid(rust_2018_idioms)] #![cfg_attr(docsrs, feature(doc_cfg))] mod antialiasing; +mod error; mod primitive; mod renderer; mod transformation; @@ -29,6 +30,7 @@ pub use widget::*; pub use antialiasing::Antialiasing; pub use backend::Backend; pub use defaults::Defaults; +pub use error::Error; pub use layer::Layer; pub use primitive::Primitive; pub use renderer::Renderer; diff --git a/graphics/src/widget/radio.rs b/graphics/src/widget/radio.rs index dd8b5f17..da41ac47 100644 --- a/graphics/src/widget/radio.rs +++ b/graphics/src/widget/radio.rs @@ -13,16 +13,13 @@ pub use iced_style::radio::{Style, StyleSheet}; pub type Radio<Message, Backend> = iced_native::Radio<Message, Renderer<Backend>>; -const SIZE: f32 = 28.0; -const DOT_SIZE: f32 = SIZE / 2.0; - impl<B> radio::Renderer for Renderer<B> where B: Backend, { type Style = Box<dyn StyleSheet>; - const DEFAULT_SIZE: u16 = SIZE as u16; + const DEFAULT_SIZE: u16 = 28; const DEFAULT_SPACING: u16 = 15; fn draw( @@ -39,10 +36,13 @@ where style_sheet.active() }; + let size = bounds.width; + let dot_size = size / 2.0; + let radio = Primitive::Quad { bounds, background: style.background, - border_radius: (SIZE / 2.0) as u16, + border_radius: (size / 2.0) as u16, border_width: style.border_width, border_color: style.border_color, }; @@ -52,13 +52,13 @@ where primitives: if is_selected { let radio_circle = Primitive::Quad { bounds: Rectangle { - x: bounds.x + DOT_SIZE / 2.0, - y: bounds.y + DOT_SIZE / 2.0, - width: bounds.width - DOT_SIZE, - height: bounds.height - DOT_SIZE, + x: bounds.x + dot_size / 2.0, + y: bounds.y + dot_size / 2.0, + width: bounds.width - dot_size, + height: bounds.height - dot_size, }, background: Background::Color(style.dot_color), - border_radius: (DOT_SIZE / 2.0) as u16, + border_radius: (dot_size / 2.0) as u16, border_width: 0, border_color: Color::TRANSPARENT, }; diff --git a/graphics/src/window/compositor.rs b/graphics/src/window/compositor.rs index aa625f43..7674f227 100644 --- a/graphics/src/window/compositor.rs +++ b/graphics/src/window/compositor.rs @@ -1,4 +1,4 @@ -use crate::{Color, Viewport}; +use crate::{Color, Error, Viewport}; use iced_native::mouse; use raw_window_handle::HasRawWindowHandle; @@ -19,7 +19,7 @@ pub trait Compositor: Sized { /// Creates a new [`Backend`]. /// /// [`Backend`]: trait.Backend.html - fn new(settings: Self::Settings) -> (Self, Self::Renderer); + fn new(settings: Self::Settings) -> Result<(Self, Self::Renderer), Error>; /// Crates a new [`Surface`] for the given window. /// diff --git a/graphics/src/window/gl_compositor.rs b/graphics/src/window/gl_compositor.rs index 2ba39d6e..1f37642e 100644 --- a/graphics/src/window/gl_compositor.rs +++ b/graphics/src/window/gl_compositor.rs @@ -1,4 +1,4 @@ -use crate::{Color, Size, Viewport}; +use crate::{Color, Error, Size, Viewport}; use iced_native::mouse; use core::ffi::c_void; @@ -41,7 +41,7 @@ pub trait GLCompositor: Sized { unsafe fn new( settings: Self::Settings, loader_function: impl FnMut(&str) -> *const c_void, - ) -> (Self, Self::Renderer); + ) -> Result<(Self, Self::Renderer), Error>; /// Returns the amount of samples that should be used when configuring /// an OpenGL context for this [`Compositor`]. |