pub struct Split<T> { /* private fields */ }
Expand description
A container containing two other widgets, splitting the area either horizontally or vertically.
Implementations§
source§impl<T> Split<T>
impl<T> Split<T>
sourcepub fn columns(
left_child: impl Widget<T> + 'static,
right_child: impl Widget<T> + 'static
) -> Self
pub fn columns( left_child: impl Widget<T> + 'static, right_child: impl Widget<T> + 'static ) -> Self
Create a new split panel, with the horizontal axis split in two by a vertical bar.
Examples found in repository?
More examples
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
fn build_root_widget() -> impl Widget<AppState> {
let label = Scroll::new(
RawLabel::new()
.with_text_color(Color::BLACK)
.with_line_break_mode(LineBreaking::WordWrap)
.lens(AppState::rendered)
.expand_width()
.padding((SPACER_SIZE * 4.0, SPACER_SIZE)),
)
.vertical()
.background(Color::grey8(222))
.expand();
let textbox = TextBox::multiline()
.lens(AppState::raw)
.controller(RichTextRebuilder)
.expand()
.padding(5.0);
Split::columns(label, textbox)
}
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
fn build_app() -> impl Widget<u32> {
let fixed_cols = Padding::new(
10.0,
Container::new(
Split::columns(
Align::centered(Label::new("Left Split")),
Align::centered(Label::new("Right Split")),
)
.split_point(0.5),
)
.border(Color::WHITE, 1.0),
);
let fixed_rows = Padding::new(
10.0,
Container::new(
Split::rows(
Align::centered(Label::new("Top Split")),
Align::centered(Label::new("Bottom Split")),
)
.split_point(0.4)
.bar_size(3.0),
)
.border(Color::WHITE, 1.0),
);
let draggable_cols = Padding::new(
10.0,
Container::new(
Split::columns(
Align::centered(Label::new("Split A")),
Align::centered(Label::new("Split B")),
)
.split_point(0.5)
.draggable(true)
.solid_bar(true)
.min_size(60.0, 60.0),
)
.border(Color::WHITE, 1.0),
);
Padding::new(
10.0,
Container::new(
Split::rows(
Split::rows(fixed_cols, fixed_rows)
.split_point(0.33)
.bar_size(3.0)
.min_bar_area(3.0)
.draggable(true),
draggable_cols,
)
.split_point(0.75)
.bar_size(5.0)
.min_bar_area(11.0)
.draggable(true),
)
.border(Color::WHITE, 1.0),
)
}
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
fn make_ui() -> impl Widget<AppState> {
let mut switcher_column = Flex::column();
switcher_column.add_child(
Label::new(|data: &u32, _env: &Env| format!("Current view: {data}"))
.lens(AppState::current_view),
);
for i in 0..6 {
switcher_column.add_spacer(80.);
switcher_column.add_child(
Button::new(format!("View {i}"))
.on_click(move |_event, data: &mut u32, _env| {
*data = i;
})
.lens(AppState::current_view),
);
}
let view_switcher = ViewSwitcher::new(
|data: &AppState, _env| data.current_view,
|selector, _data, _env| match selector {
0 => Box::new(Label::new("Simple Label").center()),
1 => Box::new(
Button::new("Simple Button").on_click(|_event, _data, _env| {
println!("Simple button clicked!");
}),
),
2 => Box::new(
Button::new("Another Simple Button").on_click(|_event, _data, _env| {
println!("Another simple button clicked!");
}),
),
3 => Box::new(
Flex::column()
.with_flex_child(Label::new("Here is a label").center(), 1.0)
.with_flex_child(
Button::new("Button").on_click(|_event, _data, _env| {
println!("Complex button clicked!");
}),
1.0,
)
.with_flex_child(TextBox::new().lens(AppState::current_text), 1.0)
.with_flex_child(
Label::new(|data: &String, _env: &Env| format!("Value entered: {data}"))
.lens(AppState::current_text),
1.0,
),
),
4 => Box::new(
Split::columns(
Label::new("Left split").center(),
Label::new("Right split").center(),
)
.draggable(true),
),
_ => Box::new(Label::new("Unknown").center()),
},
);
Flex::row()
.with_child(switcher_column)
.with_flex_child(view_switcher, 1.0)
}
sourcepub fn rows(
upper_child: impl Widget<T> + 'static,
lower_child: impl Widget<T> + 'static
) -> Self
pub fn rows( upper_child: impl Widget<T> + 'static, lower_child: impl Widget<T> + 'static ) -> Self
Create a new split panel, with the vertical axis split in two by a horizontal bar.
Examples found in repository?
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
fn build_tab_widget(tab_config: &TabConfig) -> impl Widget<AppState> {
let dyn_tabs = Tabs::for_policy(NumberedTabs)
.with_axis(tab_config.axis)
.with_edge(tab_config.edge)
.with_transition(tab_config.transition)
.lens(AppState::advanced);
let control_dynamic = Flex::column()
.cross_axis_alignment(CrossAxisAlignment::Start)
.with_child(Label::new("Control dynamic tabs"))
.with_child(Button::new("Add a tab").on_click(|_c, d: &mut DynamicTabData, _e| d.add_tab()))
.with_child(Label::new(|adv: &DynamicTabData, _e: &Env| {
format!("Highest tab number is {}", adv.highest_tab)
}))
.with_spacer(20.)
.lens(AppState::advanced);
let first_static_tab = Flex::row()
.with_child(Label::new("Rename tab:"))
.with_child(TextBox::new().lens(AppState::first_tab_name));
let main_tabs = Tabs::new()
.with_axis(tab_config.axis)
.with_edge(tab_config.edge)
.with_transition(tab_config.transition)
.with_tab(
|app_state: &AppState, _: &Env| app_state.first_tab_name.to_string(),
first_static_tab,
)
.with_tab("Dynamic", control_dynamic)
.with_tab("Page 3", Label::new("Page 3 content"))
.with_tab("Page 4", Label::new("Page 4 content"))
.with_tab("Page 5", Label::new("Page 5 content"))
.with_tab("Page 6", Label::new("Page 6 content"))
.with_tab_index(1);
Split::rows(main_tabs, dyn_tabs).draggable(true)
}
More examples
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
fn build_app() -> impl Widget<u32> {
let fixed_cols = Padding::new(
10.0,
Container::new(
Split::columns(
Align::centered(Label::new("Left Split")),
Align::centered(Label::new("Right Split")),
)
.split_point(0.5),
)
.border(Color::WHITE, 1.0),
);
let fixed_rows = Padding::new(
10.0,
Container::new(
Split::rows(
Align::centered(Label::new("Top Split")),
Align::centered(Label::new("Bottom Split")),
)
.split_point(0.4)
.bar_size(3.0),
)
.border(Color::WHITE, 1.0),
);
let draggable_cols = Padding::new(
10.0,
Container::new(
Split::columns(
Align::centered(Label::new("Split A")),
Align::centered(Label::new("Split B")),
)
.split_point(0.5)
.draggable(true)
.solid_bar(true)
.min_size(60.0, 60.0),
)
.border(Color::WHITE, 1.0),
);
Padding::new(
10.0,
Container::new(
Split::rows(
Split::rows(fixed_cols, fixed_rows)
.split_point(0.33)
.bar_size(3.0)
.min_bar_area(3.0)
.draggable(true),
draggable_cols,
)
.split_point(0.75)
.bar_size(5.0)
.min_bar_area(11.0)
.draggable(true),
)
.border(Color::WHITE, 1.0),
)
}
sourcepub fn split_point(self, split_point: f64) -> Self
pub fn split_point(self, split_point: f64) -> Self
Builder-style method to set the split point as a fraction of the split axis.
The value must be between 0.0
and 1.0
, inclusive.
The default split point is 0.5
.
Examples found in repository?
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
fn build_app() -> impl Widget<u32> {
let fixed_cols = Padding::new(
10.0,
Container::new(
Split::columns(
Align::centered(Label::new("Left Split")),
Align::centered(Label::new("Right Split")),
)
.split_point(0.5),
)
.border(Color::WHITE, 1.0),
);
let fixed_rows = Padding::new(
10.0,
Container::new(
Split::rows(
Align::centered(Label::new("Top Split")),
Align::centered(Label::new("Bottom Split")),
)
.split_point(0.4)
.bar_size(3.0),
)
.border(Color::WHITE, 1.0),
);
let draggable_cols = Padding::new(
10.0,
Container::new(
Split::columns(
Align::centered(Label::new("Split A")),
Align::centered(Label::new("Split B")),
)
.split_point(0.5)
.draggable(true)
.solid_bar(true)
.min_size(60.0, 60.0),
)
.border(Color::WHITE, 1.0),
);
Padding::new(
10.0,
Container::new(
Split::rows(
Split::rows(fixed_cols, fixed_rows)
.split_point(0.33)
.bar_size(3.0)
.min_bar_area(3.0)
.draggable(true),
draggable_cols,
)
.split_point(0.75)
.bar_size(5.0)
.min_bar_area(11.0)
.draggable(true),
)
.border(Color::WHITE, 1.0),
)
}
sourcepub fn min_size(self, first: f64, second: f64) -> Self
pub fn min_size(self, first: f64, second: f64) -> Self
Builder-style method to set the minimum size for both sides of the split axis.
The value must be greater than or equal to 0.0
.
The value will be rounded up to the nearest integer.
Examples found in repository?
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
fn build_app() -> impl Widget<u32> {
let fixed_cols = Padding::new(
10.0,
Container::new(
Split::columns(
Align::centered(Label::new("Left Split")),
Align::centered(Label::new("Right Split")),
)
.split_point(0.5),
)
.border(Color::WHITE, 1.0),
);
let fixed_rows = Padding::new(
10.0,
Container::new(
Split::rows(
Align::centered(Label::new("Top Split")),
Align::centered(Label::new("Bottom Split")),
)
.split_point(0.4)
.bar_size(3.0),
)
.border(Color::WHITE, 1.0),
);
let draggable_cols = Padding::new(
10.0,
Container::new(
Split::columns(
Align::centered(Label::new("Split A")),
Align::centered(Label::new("Split B")),
)
.split_point(0.5)
.draggable(true)
.solid_bar(true)
.min_size(60.0, 60.0),
)
.border(Color::WHITE, 1.0),
);
Padding::new(
10.0,
Container::new(
Split::rows(
Split::rows(fixed_cols, fixed_rows)
.split_point(0.33)
.bar_size(3.0)
.min_bar_area(3.0)
.draggable(true),
draggable_cols,
)
.split_point(0.75)
.bar_size(5.0)
.min_bar_area(11.0)
.draggable(true),
)
.border(Color::WHITE, 1.0),
)
}
sourcepub fn bar_size(self, bar_size: f64) -> Self
pub fn bar_size(self, bar_size: f64) -> Self
Builder-style method to set the size of the splitter bar.
The value must be positive or zero.
The value will be rounded up to the nearest integer.
The default splitter bar size is 6.0
.
Examples found in repository?
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
fn build_app() -> impl Widget<u32> {
let fixed_cols = Padding::new(
10.0,
Container::new(
Split::columns(
Align::centered(Label::new("Left Split")),
Align::centered(Label::new("Right Split")),
)
.split_point(0.5),
)
.border(Color::WHITE, 1.0),
);
let fixed_rows = Padding::new(
10.0,
Container::new(
Split::rows(
Align::centered(Label::new("Top Split")),
Align::centered(Label::new("Bottom Split")),
)
.split_point(0.4)
.bar_size(3.0),
)
.border(Color::WHITE, 1.0),
);
let draggable_cols = Padding::new(
10.0,
Container::new(
Split::columns(
Align::centered(Label::new("Split A")),
Align::centered(Label::new("Split B")),
)
.split_point(0.5)
.draggable(true)
.solid_bar(true)
.min_size(60.0, 60.0),
)
.border(Color::WHITE, 1.0),
);
Padding::new(
10.0,
Container::new(
Split::rows(
Split::rows(fixed_cols, fixed_rows)
.split_point(0.33)
.bar_size(3.0)
.min_bar_area(3.0)
.draggable(true),
draggable_cols,
)
.split_point(0.75)
.bar_size(5.0)
.min_bar_area(11.0)
.draggable(true),
)
.border(Color::WHITE, 1.0),
)
}
sourcepub fn min_bar_area(self, min_bar_area: f64) -> Self
pub fn min_bar_area(self, min_bar_area: f64) -> Self
Builder-style method to set the minimum size of the splitter bar area.
The minimum splitter bar area defines the minimum size of the area where mouse hit detection is done for the splitter bar. The final area is either this or the splitter bar size, whichever is greater.
This can be useful when you want to use a very narrow visual splitter bar, but don’t want to sacrifice user experience by making it hard to click on.
The value must be positive or zero.
The value will be rounded up to the nearest integer.
The default minimum splitter bar area is 6.0
.
Examples found in repository?
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
fn build_app() -> impl Widget<u32> {
let fixed_cols = Padding::new(
10.0,
Container::new(
Split::columns(
Align::centered(Label::new("Left Split")),
Align::centered(Label::new("Right Split")),
)
.split_point(0.5),
)
.border(Color::WHITE, 1.0),
);
let fixed_rows = Padding::new(
10.0,
Container::new(
Split::rows(
Align::centered(Label::new("Top Split")),
Align::centered(Label::new("Bottom Split")),
)
.split_point(0.4)
.bar_size(3.0),
)
.border(Color::WHITE, 1.0),
);
let draggable_cols = Padding::new(
10.0,
Container::new(
Split::columns(
Align::centered(Label::new("Split A")),
Align::centered(Label::new("Split B")),
)
.split_point(0.5)
.draggable(true)
.solid_bar(true)
.min_size(60.0, 60.0),
)
.border(Color::WHITE, 1.0),
);
Padding::new(
10.0,
Container::new(
Split::rows(
Split::rows(fixed_cols, fixed_rows)
.split_point(0.33)
.bar_size(3.0)
.min_bar_area(3.0)
.draggable(true),
draggable_cols,
)
.split_point(0.75)
.bar_size(5.0)
.min_bar_area(11.0)
.draggable(true),
)
.border(Color::WHITE, 1.0),
)
}
sourcepub fn draggable(self, draggable: bool) -> Self
pub fn draggable(self, draggable: bool) -> Self
Builder-style method to set whether the split point can be changed by dragging.
Examples found in repository?
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
fn build_tab_widget(tab_config: &TabConfig) -> impl Widget<AppState> {
let dyn_tabs = Tabs::for_policy(NumberedTabs)
.with_axis(tab_config.axis)
.with_edge(tab_config.edge)
.with_transition(tab_config.transition)
.lens(AppState::advanced);
let control_dynamic = Flex::column()
.cross_axis_alignment(CrossAxisAlignment::Start)
.with_child(Label::new("Control dynamic tabs"))
.with_child(Button::new("Add a tab").on_click(|_c, d: &mut DynamicTabData, _e| d.add_tab()))
.with_child(Label::new(|adv: &DynamicTabData, _e: &Env| {
format!("Highest tab number is {}", adv.highest_tab)
}))
.with_spacer(20.)
.lens(AppState::advanced);
let first_static_tab = Flex::row()
.with_child(Label::new("Rename tab:"))
.with_child(TextBox::new().lens(AppState::first_tab_name));
let main_tabs = Tabs::new()
.with_axis(tab_config.axis)
.with_edge(tab_config.edge)
.with_transition(tab_config.transition)
.with_tab(
|app_state: &AppState, _: &Env| app_state.first_tab_name.to_string(),
first_static_tab,
)
.with_tab("Dynamic", control_dynamic)
.with_tab("Page 3", Label::new("Page 3 content"))
.with_tab("Page 4", Label::new("Page 4 content"))
.with_tab("Page 5", Label::new("Page 5 content"))
.with_tab("Page 6", Label::new("Page 6 content"))
.with_tab_index(1);
Split::rows(main_tabs, dyn_tabs).draggable(true)
}
More examples
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
fn build_app() -> impl Widget<u32> {
let fixed_cols = Padding::new(
10.0,
Container::new(
Split::columns(
Align::centered(Label::new("Left Split")),
Align::centered(Label::new("Right Split")),
)
.split_point(0.5),
)
.border(Color::WHITE, 1.0),
);
let fixed_rows = Padding::new(
10.0,
Container::new(
Split::rows(
Align::centered(Label::new("Top Split")),
Align::centered(Label::new("Bottom Split")),
)
.split_point(0.4)
.bar_size(3.0),
)
.border(Color::WHITE, 1.0),
);
let draggable_cols = Padding::new(
10.0,
Container::new(
Split::columns(
Align::centered(Label::new("Split A")),
Align::centered(Label::new("Split B")),
)
.split_point(0.5)
.draggable(true)
.solid_bar(true)
.min_size(60.0, 60.0),
)
.border(Color::WHITE, 1.0),
);
Padding::new(
10.0,
Container::new(
Split::rows(
Split::rows(fixed_cols, fixed_rows)
.split_point(0.33)
.bar_size(3.0)
.min_bar_area(3.0)
.draggable(true),
draggable_cols,
)
.split_point(0.75)
.bar_size(5.0)
.min_bar_area(11.0)
.draggable(true),
)
.border(Color::WHITE, 1.0),
)
}
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
fn make_ui() -> impl Widget<AppState> {
let mut switcher_column = Flex::column();
switcher_column.add_child(
Label::new(|data: &u32, _env: &Env| format!("Current view: {data}"))
.lens(AppState::current_view),
);
for i in 0..6 {
switcher_column.add_spacer(80.);
switcher_column.add_child(
Button::new(format!("View {i}"))
.on_click(move |_event, data: &mut u32, _env| {
*data = i;
})
.lens(AppState::current_view),
);
}
let view_switcher = ViewSwitcher::new(
|data: &AppState, _env| data.current_view,
|selector, _data, _env| match selector {
0 => Box::new(Label::new("Simple Label").center()),
1 => Box::new(
Button::new("Simple Button").on_click(|_event, _data, _env| {
println!("Simple button clicked!");
}),
),
2 => Box::new(
Button::new("Another Simple Button").on_click(|_event, _data, _env| {
println!("Another simple button clicked!");
}),
),
3 => Box::new(
Flex::column()
.with_flex_child(Label::new("Here is a label").center(), 1.0)
.with_flex_child(
Button::new("Button").on_click(|_event, _data, _env| {
println!("Complex button clicked!");
}),
1.0,
)
.with_flex_child(TextBox::new().lens(AppState::current_text), 1.0)
.with_flex_child(
Label::new(|data: &String, _env: &Env| format!("Value entered: {data}"))
.lens(AppState::current_text),
1.0,
),
),
4 => Box::new(
Split::columns(
Label::new("Left split").center(),
Label::new("Right split").center(),
)
.draggable(true),
),
_ => Box::new(Label::new("Unknown").center()),
},
);
Flex::row()
.with_child(switcher_column)
.with_flex_child(view_switcher, 1.0)
}
sourcepub fn solid_bar(self, solid: bool) -> Self
pub fn solid_bar(self, solid: bool) -> Self
Builder-style method to set whether the splitter bar is drawn as a solid rectangle.
If this is false
(the default), the bar will be drawn as two parallel lines.
Examples found in repository?
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
fn build_app() -> impl Widget<u32> {
let fixed_cols = Padding::new(
10.0,
Container::new(
Split::columns(
Align::centered(Label::new("Left Split")),
Align::centered(Label::new("Right Split")),
)
.split_point(0.5),
)
.border(Color::WHITE, 1.0),
);
let fixed_rows = Padding::new(
10.0,
Container::new(
Split::rows(
Align::centered(Label::new("Top Split")),
Align::centered(Label::new("Bottom Split")),
)
.split_point(0.4)
.bar_size(3.0),
)
.border(Color::WHITE, 1.0),
);
let draggable_cols = Padding::new(
10.0,
Container::new(
Split::columns(
Align::centered(Label::new("Split A")),
Align::centered(Label::new("Split B")),
)
.split_point(0.5)
.draggable(true)
.solid_bar(true)
.min_size(60.0, 60.0),
)
.border(Color::WHITE, 1.0),
);
Padding::new(
10.0,
Container::new(
Split::rows(
Split::rows(fixed_cols, fixed_rows)
.split_point(0.33)
.bar_size(3.0)
.min_bar_area(3.0)
.draggable(true),
draggable_cols,
)
.split_point(0.75)
.bar_size(5.0)
.min_bar_area(11.0)
.draggable(true),
)
.border(Color::WHITE, 1.0),
)
}