Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create default env with Env::default() #1237

Merged
merged 1 commit into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions druid/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -118,7 +116,7 @@ impl<T: Data> AppLauncher<T> {
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);
}
Expand Down
2 changes: 1 addition & 1 deletion druid/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
6 changes: 4 additions & 2 deletions druid/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion druid/src/tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl<T: Data> Harness<'_, T> {

let inner = Inner {
data,
env: theme::init(),
env: Env::default(),
window,
cmds: Default::default(),
};
Expand Down
11 changes: 8 additions & 3 deletions druid/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//! Theme keys and initial values.

#![allow(missing_docs)]

use crate::piet::Color;

use crate::{Env, FontDescriptor, FontFamily, Key};
Expand Down Expand Up @@ -85,9 +86,8 @@ pub const SCROLLBAR_EDGE_WIDTH: Key<f64> =
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))
Expand Down Expand Up @@ -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()
}