Add background_color to Settings

This commit is contained in:
Héctor Ramón Jiménez 2019-12-29 12:29:47 +01:00
parent c7b170da6d
commit f74ab463d4
6 changed files with 55 additions and 14 deletions

View File

@ -21,14 +21,15 @@
//! [`checkbox::Renderer`]: ../widget/checkbox/trait.Renderer.html
mod debugger;
#[cfg(debug_assertions)]
mod null;
mod windowed;
pub use debugger::Debugger;
pub use windowed::{Target, Windowed};
#[cfg(debug_assertions)]
mod null;
#[cfg(debug_assertions)]
pub use null::Null;
pub use windowed::{Target, Windowed};
use crate::{layout, Element};

View File

@ -1,4 +1,4 @@
use crate::MouseCursor;
use crate::{Color, MouseCursor};
use raw_window_handle::HasRawWindowHandle;
@ -19,6 +19,7 @@ pub trait Windowed: super::Renderer + Sized {
/// top of the GUI on most scenarios.
fn draw<T: AsRef<str>>(
&mut self,
clear_color: Color,
output: &Self::Output,
overlay: &[T],
target: &mut Self::Target,

View File

@ -1,7 +1,8 @@
//! Configure your application.
use crate::Color;
/// The settings of an application.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Settings {
/// The [`Window`] settings.
///
@ -9,6 +10,20 @@ pub struct Settings {
///
/// [`Window`]: struct.Window.html
pub window: Window,
/// The default background [`Color`] of the application
///
/// [`Color`]: ../struct.Color.html
pub background_color: Color,
}
impl Default for Settings {
fn default() -> Settings {
Settings {
window: Window::default(),
background_color: Color::WHITE,
}
}
}
/// The window settings of an application.
@ -44,6 +59,7 @@ impl From<Settings> for iced_winit::Settings {
decorations: settings.window.decorations,
platform_specific: Default::default(),
},
background_color: settings.background_color,
}
}
}

View File

@ -76,6 +76,7 @@ impl Renderer {
fn draw<T: AsRef<str>>(
&mut self,
clear_color: Color,
(primitive, mouse_cursor): &(Primitive, MouseCursor),
overlay: &[T],
target: &mut Target,
@ -97,11 +98,15 @@ impl Renderer {
resolve_target: None,
load_op: wgpu::LoadOp::Clear,
store_op: wgpu::StoreOp::Store,
clear_color: wgpu::Color {
r: 1.0,
g: 1.0,
b: 1.0,
a: 1.0,
clear_color: {
let [r, g, b, a] = clear_color.into_linear();
wgpu::Color {
r: f64::from(r),
g: f64::from(g),
b: f64::from(b),
a: f64::from(a),
}
},
}],
depth_stencil_attachment: None,
@ -428,11 +433,12 @@ impl Windowed for Renderer {
fn draw<T: AsRef<str>>(
&mut self,
clear_color: Color,
output: &Self::Output,
overlay: &[T],
target: &mut Target,
) -> MouseCursor {
self.draw(output, overlay, target)
self.draw(clear_color, output, overlay, target)
}
}

View File

@ -279,8 +279,12 @@ pub trait Application: Sized {
resized = false;
}
let new_mouse_cursor =
renderer.draw(&primitive, &debug.overlay(), &mut target);
let new_mouse_cursor = renderer.draw(
settings.background_color,
&primitive,
&debug.overlay(),
&mut target,
);
debug.render_finished();

View File

@ -1,4 +1,5 @@
//! Configure your application.
use crate::Color;
#[cfg(target_os = "windows")]
#[path = "windows.rs"]
@ -10,12 +11,24 @@ mod platform;
pub use platform::PlatformSpecific;
/// The settings of an application.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Settings {
/// The [`Window`] settings
///
/// [`Window`]: struct.Window.html
pub window: Window,
/// The default background color of the application
pub background_color: Color,
}
impl Default for Settings {
fn default() -> Settings {
Settings {
window: Window::default(),
background_color: Color::WHITE,
}
}
}
/// The window settings of an application.