use druid::widget::{EnvScope, Flex, Label, Padding, TextBox};
use druid::{theme, AppLauncher, Color, Data, LocalizedString, MenuDesc, Widget, WindowDesc};
fn main() {
let window = WindowDesc::new(build_widget).menu(make_main_menu());
AppLauncher::with_window(window)
.configure_env(|env| {
env.set(theme::SELECTION_COLOR, Color::rgb8(0xA6, 0xCC, 0xFF));
env.set(theme::WINDOW_BACKGROUND_COLOR, Color::WHITE);
env.set(theme::LABEL_COLOR, Color::BLACK);
env.set(theme::CURSOR_COLOR, Color::BLACK);
env.set(theme::BACKGROUND_LIGHT, Color::rgb8(230, 230, 230));
})
.use_simple_logger()
.launch("typing is fun!".to_string())
.expect("launch failed");
}
fn build_widget() -> impl Widget<String> {
let textbox = TextBox::new();
let textbox_2 = EnvScope::new(
|env| {
env.set(theme::BACKGROUND_LIGHT, Color::rgb8(50, 50, 50));
env.set(theme::LABEL_COLOR, Color::WHITE);
env.set(theme::CURSOR_COLOR, Color::WHITE);
env.set(theme::SELECTION_COLOR, Color::rgb8(100, 100, 100));
},
TextBox::with_placeholder("placeholder"),
);
let label = Label::new(|data: &String, _env: &_| format!("value: {}", data));
Flex::column()
.with_child(Padding::new(5.0, textbox), 1.0)
.with_child(Padding::new(5.0, textbox_2), 1.0)
.with_child(Padding::new(5.0, label), 1.0)
}
fn make_main_menu<T: Data>() -> MenuDesc<T> {
let edit_menu = MenuDesc::new(LocalizedString::new("common-menu-edit-menu"))
.append(druid::platform_menus::common::cut())
.append(druid::platform_menus::common::copy())
.append(druid::platform_menus::common::paste());
MenuDesc::platform_default()
.unwrap_or(MenuDesc::empty())
.append(edit_menu)
}