Move Defaults from iced_graphics to iced_native

This commit is contained in:
Héctor Ramón Jiménez 2021-10-18 15:19:04 +07:00
parent 54a9a232f8
commit edea093350
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
39 changed files with 166 additions and 192 deletions

View file

@ -1,32 +0,0 @@
//! Use default styling attributes to inherit styles.
use iced_native::Color;
/// Some default styling attributes.
#[derive(Debug, Clone, Copy)]
pub struct Defaults {
/// Text styling
pub text: Text,
}
impl Default for Defaults {
fn default() -> Defaults {
Defaults {
text: Text::default(),
}
}
}
/// Some default text styling attributes.
#[derive(Debug, Clone, Copy)]
pub struct Text {
/// The default color of text
pub color: Color,
}
impl Default for Text {
fn default() -> Text {
Text {
color: Color::BLACK,
}
}
}

View file

@ -13,15 +13,14 @@
mod antialiasing;
mod error;
mod primitive;
mod renderer;
mod transformation;
mod viewport;
pub mod backend;
pub mod defaults;
pub mod font;
pub mod layer;
pub mod overlay;
pub mod renderer;
pub mod triangle;
pub mod widget;
pub mod window;
@ -31,7 +30,6 @@ 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;

View file

@ -1,8 +1,10 @@
use crate::backend::{self, Backend};
use crate::{Defaults, Primitive, Vector};
use crate::{Primitive, Vector};
use iced_native::layout;
use iced_native::renderer;
use iced_native::{Color, Element, Font, Rectangle};
use iced_native::{Element, Font, Rectangle};
pub use iced_native::renderer::Style;
/// A backend-agnostic renderer that supports all the built-in widgets.
#[derive(Debug)]
@ -33,8 +35,6 @@ impl<B> iced_native::Renderer for Renderer<B>
where
B: Backend,
{
type Defaults = Defaults;
fn layout<'a, Message>(
&mut self,
element: &Element<'a, Message, Self>,
@ -97,8 +97,8 @@ where
self.primitives.push(Primitive::Text {
content: text.content.to_string(),
bounds: text.bounds,
size: text.size.unwrap_or(f32::from(self.backend.default_size())),
color: text.color.unwrap_or(Color::BLACK),
size: text.size,
color: text.color,
font: text.font,
horizontal_alignment: text.horizontal_alignment,
vertical_alignment: text.vertical_alignment,

View file

@ -3,7 +3,9 @@
//! A [`Canvas`] widget can be used to draw different kinds of 2D shapes in a
//! [`Frame`]. It can be used for animation, data visualization, game graphics,
//! and more!
use crate::{Backend, Defaults, Renderer};
use crate::renderer::{self, Renderer};
use crate::Backend;
use iced_native::layout;
use iced_native::{
Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget,
@ -187,7 +189,7 @@ where
fn draw(
&self,
_renderer: &mut Renderer<B>,
_defaults: &Defaults,
_style: &renderer::Style,
_layout: Layout<'_>,
_cursor_position: Point,
_viewport: &Rectangle,

View file

@ -1,10 +1,11 @@
//! Encode and display information in a QR code.
use crate::canvas;
use crate::{Backend, Defaults, Renderer};
use crate::renderer::{self, Renderer};
use crate::Backend;
use iced_native::layout;
use iced_native::{
layout, Color, Element, Hasher, Layout, Length, Point, Rectangle, Size,
Widget,
Color, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget,
};
use thiserror::Error;
@ -81,7 +82,7 @@ where
fn draw(
&self,
_renderer: &mut Renderer<B>,
_defaults: &Defaults,
_style: &renderer::Style,
_layout: Layout<'_>,
_cursor_position: Point,
_viewport: &Rectangle,