Making a button in druid change it's color

Hi,
I am just starting to learn Rust and wanted to create a simple gui with a button that changes it's background color if I click on it.
Aaaand I am already getting errors over errors, so I gave up on the color changing part and set my goal to just change the text and not even this works. I am completely lost and searched for a solution for hours now. Can anyone help?

Here is my Code:

use druid::widget::{Align, BackgroundBrush, Button, Container, Flex, Label, TextBox};
use druid::{AppLauncher, Color, Data, Lens, LocalizedString, PlatformError, TextAlignment, UnitPoint, Widget, WidgetExt, WindowDesc};
use std::string::String;



const WINDOW_TITLE: LocalizedString<HelloState> = LocalizedString::new("Nandu");
const YELLOW: Color = Color::rgb8(0, 233, 233);

#[derive(Clone, Data, Lens)]
struct HelloState {
    name: String,
}
fn main() -> Result<(), PlatformError> {
    let main_window = WindowDesc::new(ui_builder())
        .title(WINDOW_TITLE);
    let data = "".into();
    AppLauncher::with_window(main_window)
        .log_to_console()
        .launch(data)
}

fn ui_builder() -> impl Widget<str> {
    let txt_s1 = Label::new("Source 1").with_text_color(Color::YELLOW).align_vertical(UnitPoint::TOP).padding(20.0);
    let btn_off_s1 = Button::new("Off").background(BackgroundBrush::Color(Color::rgb8(255, 100, 100))).on_click(|ctx,data: String, env|
        {
            if ctx.is_active(){
                *data = "Off".into()
            }else{
                *data = "On".into()
            }

    });





    let layout = Flex::column().with_child(txt_s1).with_child(btn_off_s1).align_horizontal(UnitPoint::TOP);

    layout

}

The Error I am getting would be this one:

error[E0282]: type annotations needed
  --> src/main.rs:25:114
   |
25 |     let btn_off_s1 = Button::new("Off").background(BackgroundBrush::Color(Color::rgb8(255, 100, 100))).on_click(|ctx,data: String, env|
   |                                                                                                                  ^^^
26 |         {
27 |             if ctx.is_active(){
   |                --- type must be known at this point
   |
help: consider giving this closure parameter an explicit type
   |
25 |     let btn_off_s1 = Button::new("Off").background(BackgroundBrush::Color(Color::rgb8(255, 100, 100))).on_click(|ctx: /* Type */,data: String, env|

Just to be clear, I know it's kinda a mess of Code, but I didn't quite clean up after every attempt and there are some leftovers in the input section..
It would be a huge help if anyone could tell me how to change the text or the color or both in the on_click method of the button.

Thanks to everyone in advance

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.