summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-12-29 12:29:47 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-12-29 12:29:47 +0100
commitf74ab463d44dd0bb025b0cea466d2861576253dd (patch)
treeaa500cbe6577a6084e08f3409e406c4a7e7385e4
parentc7b170da6d180f80e539910cccb543720fa3713c (diff)
downloadiced-f74ab463d44dd0bb025b0cea466d2861576253dd.tar.gz
iced-f74ab463d44dd0bb025b0cea466d2861576253dd.tar.bz2
iced-f74ab463d44dd0bb025b0cea466d2861576253dd.zip
Add `background_color` to `Settings`
-rw-r--r--native/src/renderer.rs7
-rw-r--r--native/src/renderer/windowed.rs3
-rw-r--r--src/settings.rs18
-rw-r--r--wgpu/src/renderer.rs18
-rw-r--r--winit/src/application.rs8
-rw-r--r--winit/src/settings/mod.rs15
6 files changed, 55 insertions, 14 deletions
diff --git a/native/src/renderer.rs b/native/src/renderer.rs
index 7a68ada4..023dd42b 100644
--- a/native/src/renderer.rs
+++ b/native/src/renderer.rs
@@ -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};
diff --git a/native/src/renderer/windowed.rs b/native/src/renderer/windowed.rs
index 813a03f2..89f80bbe 100644
--- a/native/src/renderer/windowed.rs
+++ b/native/src/renderer/windowed.rs
@@ -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,
diff --git a/src/settings.rs b/src/settings.rs
index 62a1a614..8da8948c 100644
--- a/src/settings.rs
+++ b/src/settings.rs
@@ -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,
}
}
}
diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs
index 4984d4fe..47b258ed 100644
--- a/wgpu/src/renderer.rs
+++ b/wgpu/src/renderer.rs
@@ -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)
}
}
diff --git a/winit/src/application.rs b/winit/src/application.rs
index a8612b1a..50060b11 100644
--- a/winit/src/application.rs
+++ b/winit/src/application.rs
@@ -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();
diff --git a/winit/src/settings/mod.rs b/winit/src/settings/mod.rs
index 58e3d879..1f9f1502 100644
--- a/winit/src/settings/mod.rs
+++ b/winit/src/settings/mod.rs
@@ -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.