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

Container doesnot request_paint when env value is changed #1880

Closed
maan2003 opened this issue Jul 20, 2021 · 0 comments · Fixed by #1881
Closed

Container doesnot request_paint when env value is changed #1880

maan2003 opened this issue Jul 20, 2021 · 0 comments · Fixed by #1881
Labels
widget concerns a particular widget

Comments

@maan2003
Copy link
Collaborator

example:

// Copyright 2021 The Druid Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use druid::widget::prelude::*;
use druid::widget::{Flex, SizedBox, Switch};
use druid::{AppLauncher, Color, Key, WidgetExt, WindowDesc};

pub fn main() {
    let main_window = WindowDesc::new(build_root_widget());

    AppLauncher::with_window(main_window)
        .log_to_console()
        .launch(true)
        .expect("Failed to launch application");
}

fn build_root_widget() -> impl Widget<bool> {
    Flex::column()
        .with_child(Switch::new())
        .with_default_spacer()
        .with_child(changing_bg())
}

fn changing_bg() -> druid::widget::EnvScope<bool, druid::widget::Container<bool>> {
    const BG: Key<Color> = Key::new("druid-test.bg-color");
    SizedBox::empty()
        .width(500.)
        .height(500.)
        .background(BG)
        .env_scope(|env, data| env.set(BG, if *data { Color::RED } else { Color::BLUE }))
}
@maan2003 maan2003 added the widget concerns a particular widget label Jul 20, 2021
maan2003 added a commit to maan2003/druid that referenced this issue Jul 20, 2021
maan2003 added a commit that referenced this issue Jul 27, 2021
Fixes #1880 

Co-authored-by: Colin Rofls <colin@cmyr.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
widget concerns a particular widget
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant