Exemple #1
0
def test_widget_layout_without_window_or_children(root):
    parent = Widget(None)

    layout = parent.layout(parent.children)

    assert layout == []
    assert parent.window is None

    widget = Widget(root)

    layout = widget.layout(widget.children)

    assert layout == []
    assert widget.children == []
Exemple #2
0
def test_widget_layout_weight(root):
    parent = Widget(root)

    child_a = Widget(parent).span(2, 2)
    child_b = Widget(parent).grid(1, 2).span(2).weight(col=2)
    child_c = Widget(parent).grid(3, 4).span(col=2).weight(2)

    parent.render()

    layout = parent.layout(parent.children)

    assert isinstance(layout, list)
    assert layout[0][0] == child_a
    assert layout[0][1] == {'y': 0, 'x': 0, 'height': 9, 'width': 68}
    assert layout[1][0] == child_b
    assert layout[1][1] == {'y': 5, 'x': 23, 'height': 13, 'width': 45}
    assert layout[2][0] == child_c
    assert layout[2][1] == {'y': 10, 'x': 68, 'height': 8, 'width': 22}
Exemple #3
0
def test_widget_layout_span(root):
    parent = Widget(root)

    child_a = Widget(parent).span(2, 2)
    child_b = Widget(parent).grid(1, 2).span(2)
    child_c = Widget(parent).grid(3, 4).span(col=2)

    parent.render()

    layout = parent.layout(parent.children)

    assert isinstance(layout, list)
    assert layout[0][0] == child_a
    assert layout[0][1] == {'y': 0, 'x': 0, 'height': 12, 'width': 60}
    assert layout[1][0] == child_b
    assert layout[1][1] == {'y': 6, 'x': 30, 'height': 12, 'width': 30}
    assert layout[2][0] == child_c
    assert layout[2][1] == {'y': 12, 'x': 60, 'height': 6, 'width': 30}
Exemple #4
0
def test_widget_layout_with_border(root):
    parent = Widget(root)
    parent.styling.border = [0]

    child_a = Widget(parent).span(2, 2)
    child_b = Widget(parent).grid(1, 2).span(2).weight(col=2)
    child_c = Widget(parent).grid(3, 4).span(col=2).weight(2)

    parent.render()

    layout = parent.layout(parent.children)

    assert isinstance(layout, list)
    assert layout[0][0] == child_a
    assert layout[0][1] == {'y': 1, 'x': 1, 'height': 8, 'width': 66}
    assert layout[1][0] == child_b
    assert layout[1][1] == {'y': 5, 'x': 23, 'height': 12, 'width': 44}
    assert layout[2][0] == child_c
    assert layout[2][1] == {'y': 9, 'x': 67, 'height': 8, 'width': 22}
Exemple #5
0
def test_widget_layout_mode(root):
    parent = Widget(root, mode='compact')

    child_a = Widget(parent)
    child_b = Widget(parent).grid(1)
    child_c = Widget(parent).grid(2)
    child_d = Widget(parent).grid(3)

    parent.render()

    layout = parent.layout(parent.children)

    assert isinstance(layout, list)
    assert layout[0][0] == child_a
    assert layout[0][1] == {'y': 0, 'x': 0, 'height': 4, 'width': 90}
    assert layout[1][0] == child_b
    assert layout[1][1] == {'y': 4, 'x': 0, 'height': 4, 'width': 90}
    assert layout[2][0] == child_c
    assert layout[2][1] == {'y': 8, 'x': 0, 'height': 4, 'width': 90}
    assert layout[3][0] == child_d
    assert layout[3][1] == {'y': 12, 'x': 0, 'height': 4, 'width': 90}