From 8a31ad57b377a17e7b28760a5c6f2d0e24effc72 Mon Sep 17 00:00:00 2001 From: totsteps Date: Tue, 15 Sep 2020 03:23:55 +0200 Subject: [PATCH] Create default env with Env::default() --- druid/src/app.rs | 6 ++---- druid/src/core.rs | 2 +- druid/src/env.rs | 6 ++++-- druid/src/tests/harness.rs | 2 +- druid/src/theme.rs | 11 ++++++++--- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/druid/src/app.rs b/druid/src/app.rs index 8d78a2dbba..c85e41db5d 100644 --- a/druid/src/app.rs +++ b/druid/src/app.rs @@ -20,9 +20,7 @@ use crate::shell::{Application, Error as PlatformError, WindowBuilder, WindowHan use crate::widget::LabelText; use crate::win_handler::{AppHandler, AppState}; use crate::window::WindowId; -use crate::{ - theme, AppDelegate, Data, DruidHandler, Env, LocalizedString, MenuDesc, Widget, WidgetExt, -}; +use crate::{AppDelegate, Data, DruidHandler, Env, LocalizedString, MenuDesc, Widget, WidgetExt}; use druid_shell::WindowState; @@ -118,7 +116,7 @@ impl AppLauncher { pub fn launch(mut self, data: T) -> Result<(), PlatformError> { let app = Application::new()?; - let mut env = theme::init(); + let mut env = Env::default(); if let Some(f) = self.env_setup.take() { f(&mut env, &data); } diff --git a/druid/src/core.rs b/druid/src/core.rs index 0681629ffe..84176ccf3e 100644 --- a/druid/src/core.rs +++ b/druid/src/core.rs @@ -999,7 +999,7 @@ mod tests { state: &mut state, }; - let env = crate::theme::init(); + let env = Env::default(); widget.lifecycle(&mut ctx, &LifeCycle::WidgetAdded, &None, &env); assert!(ctx.widget_state.children.may_contain(&ID_1)); diff --git a/druid/src/env.rs b/druid/src/env.rs index c01042fe75..f39cc37736 100644 --- a/druid/src/env.rs +++ b/druid/src/env.rs @@ -499,10 +499,12 @@ impl Default for Env { debug_colors, }; - Env(Arc::new(inner)) + let env = Env(Arc::new(inner)) .adding(Env::DEBUG_PAINT, false) .adding(Env::DEBUG_WIDGET_ID, false) - .adding(Env::DEBUG_WIDGET, false) + .adding(Env::DEBUG_WIDGET, false); + + crate::theme::add_to_env(env) } } diff --git a/druid/src/tests/harness.rs b/druid/src/tests/harness.rs index 7f7469da08..f9e5114d85 100644 --- a/druid/src/tests/harness.rs +++ b/druid/src/tests/harness.rs @@ -149,7 +149,7 @@ impl Harness<'_, T> { let inner = Inner { data, - env: theme::init(), + env: Env::default(), window, cmds: Default::default(), }; diff --git a/druid/src/theme.rs b/druid/src/theme.rs index 9309eebb12..87ed99802d 100644 --- a/druid/src/theme.rs +++ b/druid/src/theme.rs @@ -15,6 +15,7 @@ //! Theme keys and initial values. #![allow(missing_docs)] + use crate::piet::Color; use crate::{Env, FontDescriptor, FontFamily, Key}; @@ -85,9 +86,8 @@ pub const SCROLLBAR_EDGE_WIDTH: Key = Key::new("org.linebender.druid.theme.scrollbar_edge_width"); /// An initial theme. -pub fn init() -> Env { - Env::default() - .adding(WINDOW_BACKGROUND_COLOR, Color::rgb8(0x29, 0x29, 0x29)) +pub(crate) fn add_to_env(env: Env) -> Env { + env.adding(WINDOW_BACKGROUND_COLOR, Color::rgb8(0x29, 0x29, 0x29)) .adding(LABEL_COLOR, Color::rgb8(0xf0, 0xf0, 0xea)) .adding(PLACEHOLDER_COLOR, Color::rgb8(0x80, 0x80, 0x80)) .adding(PRIMARY_LIGHT, Color::rgb8(0x5c, 0xc4, 0xff)) @@ -128,3 +128,8 @@ pub fn init() -> Env { FontDescriptor::new(FontFamily::SYSTEM_UI).with_size(15.0), ) } + +#[deprecated(since = "0.7.0", note = "use Env::default() instead")] +pub fn init() -> Env { + Env::default() +}