Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Split accuracy. #738

Merged
merged 3 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions druid/examples/split_demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,60 +19,62 @@ use druid::widget::{Align, Container, Label, Padding, Split};
use druid::{AppLauncher, LocalizedString, Widget, WindowDesc};

fn build_app() -> impl Widget<u32> {
let fixed_vertical = Padding::new(
let fixed_cols = Padding::new(
10.0,
Container::new(
Split::vertical(
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_horizontal = Padding::new(
let fixed_rows = Padding::new(
10.0,
Container::new(
Split::horizontal(
Split::rows(
Align::centered(Label::new("Top Split")),
Align::centered(Label::new("Bottom Split")),
)
.split_point(0.4)
.splitter_size(7.0),
.bar_size(3.0),
)
.border(Color::WHITE, 1.0),
);
let draggable_vertical = Padding::new(
let draggable_cols = Padding::new(
10.0,
Container::new(
Split::vertical(
Split::columns(
Align::centered(Label::new("Split A")),
Align::centered(Label::new("Split B")),
)
.split_point(0.5)
.draggable(true)
.fill_splitter_handle(true)
.solid_bar(true)
.min_size(60.0),
)
.border(Color::WHITE, 1.0),
);
let draggable_horizontal = Padding::new(
let draggable_rows = Padding::new(
10.0,
Container::new(
Split::horizontal(
Split::horizontal(fixed_vertical, fixed_horizontal)
Split::rows(
Split::rows(fixed_cols, fixed_rows)
.split_point(0.33)
.splitter_size(5.0)
.bar_size(3.0)
.min_bar_area(3.0)
.draggable(true),
draggable_vertical,
draggable_cols,
)
.split_point(0.75)
.splitter_size(5.0)
.bar_size(5.0)
.min_bar_area(11.0)
.draggable(true),
)
.border(Color::WHITE, 1.0),
);
draggable_horizontal
draggable_rows
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion druid/examples/view_switcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn make_ui() -> impl Widget<AppState> {
),
),
4 => Box::new(
Split::vertical(
Split::columns(
Label::new("Left split").center(),
Label::new("Right split").center(),
)
Expand Down
2 changes: 1 addition & 1 deletion druid/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ mod tests {
#[test]
fn register_children() {
fn make_widgets() -> impl Widget<Option<u32>> {
Split::vertical(
Split::columns(
Flex::<Option<u32>>::row()
.with_child(TextBox::new().with_id(ID_1).parse())
.with_child(TextBox::new().with_id(ID_2).parse())
Expand Down
2 changes: 1 addition & 1 deletion druid/src/tests/layout_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn simple_layout() {

let id_1 = WidgetId::next();

let widget = Split::vertical(Label::new("hi"), Label::new("there"))
let widget = Split::columns(Label::new("hi"), Label::new("there"))
.fix_size(BOX_WIDTH, BOX_WIDTH)
.padding(10.0)
.with_id(id_1)
Expand Down
18 changes: 9 additions & 9 deletions druid/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn propogate_hot() {
let padding_rec = Recording::default();
let button_rec = Recording::default();

let widget = Split::vertical(
let widget = Split::columns(
SizedBox::empty().with_id(empty),
Button::new("hot")
.record(&button_rec)
Expand Down Expand Up @@ -150,7 +150,7 @@ fn take_focus() {

let left = make_focus_taker(left_focus.clone()).with_id(id_1);
let right = make_focus_taker(right_focus.clone()).with_id(id_2);
let app = Split::vertical(left, right).padding(5.0);
let app = Split::columns(left, right).padding(5.0);
let data = true;

Harness::create(data, app, |harness| {
Expand Down Expand Up @@ -195,10 +195,10 @@ fn adding_child_lifecycle() {
let record_new_child2 = record_new_child.clone();

let replacer = ReplaceChild::new(TextBox::new(), move || {
Split::vertical(TextBox::new(), TextBox::new().record(&record_new_child2))
Split::columns(TextBox::new(), TextBox::new().record(&record_new_child2))
});

let widget = Split::vertical(Label::new("hi").record(&record), replacer);
let widget = Split::columns(Label::new("hi").record(&record), replacer);

Harness::create(String::new(), widget, |harness| {
harness.send_initial_events();
Expand All @@ -225,10 +225,10 @@ fn participate_in_autofocus() {
// this widget starts with a single child, and will replace them with a split
// when we send it a command.
let replacer = ReplaceChild::new(TextBox::new().with_id(id_4), move || {
Split::vertical(TextBox::new().with_id(id_5), TextBox::new().with_id(id_6))
Split::columns(TextBox::new().with_id(id_5), TextBox::new().with_id(id_6))
});

let widget = Split::vertical(
let widget = Split::columns(
Flex::row()
.with_flex_child(TextBox::new().with_id(id_1), 1.0)
.with_flex_child(TextBox::new().with_id(id_2), 1.0)
Expand Down Expand Up @@ -263,7 +263,7 @@ fn participate_in_autofocus() {
fn child_tracking() {
let (id_1, id_2, id_3, id_4) = widget_id4();

let widget = Split::vertical(
let widget = Split::columns(
SizedBox::empty().with_id(id_1),
SizedBox::empty().with_id(id_2),
)
Expand Down Expand Up @@ -293,11 +293,11 @@ fn register_after_adding_child() {
let id_7 = WidgetId::next();

let replacer = ReplaceChild::new(TextBox::new().with_id(id_1), move || {
Split::vertical(TextBox::new().with_id(id_2), TextBox::new().with_id(id_3)).with_id(id_7)
Split::columns(TextBox::new().with_id(id_2), TextBox::new().with_id(id_3)).with_id(id_7)
})
.with_id(id_6);

let widget = Split::vertical(Label::new("hi").with_id(id_4), replacer).with_id(id_5);
let widget = Split::columns(Label::new("hi").with_id(id_4), replacer).with_id(id_5);

Harness::create(String::new(), widget, |harness| {
harness.send_initial_events();
Expand Down
Loading