86 lines
2.8 KiB
Rust
86 lines
2.8 KiB
Rust
// Stiletto
|
|
// Copyright (C) 2020 Stiletto Authors
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Affero General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
//use log::{info, warn};
|
|
|
|
use druid::im::{vector, Vector};
|
|
use druid::widget::prelude::*;
|
|
use druid::{AppLauncher, Color, Data, LocalizedString, WindowDesc, Lens};
|
|
|
|
#[derive(Clone, Data, Lens)]
|
|
struct AppState {
|
|
numbers: Vector<u32>,
|
|
}
|
|
|
|
fn build_ui() -> impl Widget<AppState> {
|
|
use druid::UnitPoint;
|
|
use druid::widget::{Align, Label, Button, CrossAxisAlignment, Flex, List, ListGrowDirection, WidgetExt, SizedBox};
|
|
|
|
let list_buttons = Flex::row()
|
|
.cross_axis_alignment(CrossAxisAlignment::Center)
|
|
.with_child(Button::new("Add"))
|
|
.with_child(Button::new("Remove"));
|
|
|
|
let number_list = Flex::row()
|
|
.cross_axis_alignment(CrossAxisAlignment::Center)
|
|
.with_flex_child(
|
|
List::new(|| {
|
|
SizedBox::new(
|
|
Label::new(|item: &u32, _env: &_| format!("{}", item))
|
|
.align_horizontal(UnitPoint::CENTER)
|
|
.background(Color::rgb(0.5, 0.5, 0.5))
|
|
.fix_width(100.0)
|
|
.fix_height(100.0)
|
|
)
|
|
.padding((10.0, 0.0))
|
|
})
|
|
.grow(ListGrowDirection::Right)
|
|
.lens(AppState::numbers)
|
|
, 1.0);
|
|
|
|
let toolbar = Flex::row()
|
|
.cross_axis_alignment(CrossAxisAlignment::Center)
|
|
.with_spacer(30.0)
|
|
.with_child(Align::left(list_buttons))
|
|
.with_spacer(30.0)
|
|
.with_flex_child(Align::left(number_list), 1.0);
|
|
|
|
Flex::column()
|
|
.cross_axis_alignment(CrossAxisAlignment::Center)
|
|
.with_child(
|
|
SizedBox::new(toolbar)
|
|
.height(100.0)
|
|
.expand_width()
|
|
.align_horizontal(UnitPoint::TOP)
|
|
)
|
|
}
|
|
|
|
pub fn main() {
|
|
let window = WindowDesc::new(build_ui)
|
|
.window_size((1000.0, 400.00))
|
|
.title(
|
|
LocalizedString::new("custom-widget-demo-window-title").with_placeholder("Tools"),
|
|
);
|
|
let app_state = AppState {
|
|
numbers: vector![1,2],
|
|
};
|
|
|
|
AppLauncher::with_window(window)
|
|
.use_simple_logger()
|
|
.launch(app_state)
|
|
.expect("launch failed");
|
|
}
|