split_demo/
split_demo.rs

1// Copyright 2019 The Druid Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! This example demonstrates the `Split` widget
16
17// On Windows platform, don't show a console when opening the app.
18#![windows_subsystem = "windows"]
19
20use druid::piet::Color;
21use druid::widget::{Align, Container, Label, Padding, Split};
22use druid::{AppLauncher, LocalizedString, Widget, WindowDesc};
23
24fn build_app() -> impl Widget<u32> {
25    let fixed_cols = Padding::new(
26        10.0,
27        Container::new(
28            Split::columns(
29                Align::centered(Label::new("Left Split")),
30                Align::centered(Label::new("Right Split")),
31            )
32            .split_point(0.5),
33        )
34        .border(Color::WHITE, 1.0),
35    );
36    let fixed_rows = Padding::new(
37        10.0,
38        Container::new(
39            Split::rows(
40                Align::centered(Label::new("Top Split")),
41                Align::centered(Label::new("Bottom Split")),
42            )
43            .split_point(0.4)
44            .bar_size(3.0),
45        )
46        .border(Color::WHITE, 1.0),
47    );
48    let draggable_cols = Padding::new(
49        10.0,
50        Container::new(
51            Split::columns(
52                Align::centered(Label::new("Split A")),
53                Align::centered(Label::new("Split B")),
54            )
55            .split_point(0.5)
56            .draggable(true)
57            .solid_bar(true)
58            .min_size(60.0, 60.0),
59        )
60        .border(Color::WHITE, 1.0),
61    );
62    Padding::new(
63        10.0,
64        Container::new(
65            Split::rows(
66                Split::rows(fixed_cols, fixed_rows)
67                    .split_point(0.33)
68                    .bar_size(3.0)
69                    .min_bar_area(3.0)
70                    .draggable(true),
71                draggable_cols,
72            )
73            .split_point(0.75)
74            .bar_size(5.0)
75            .min_bar_area(11.0)
76            .draggable(true),
77        )
78        .border(Color::WHITE, 1.0),
79    )
80}
81
82pub fn main() {
83    let window = WindowDesc::new(build_app())
84        .title(LocalizedString::new("split-demo-window-title").with_placeholder("Split Demo"));
85    AppLauncher::with_window(window)
86        .log_to_console()
87        .launch(0u32)
88        .expect("launch failed");
89}