Skip to content

Commit

Permalink
.box(prepend=...) added
Browse files Browse the repository at this point in the history
  • Loading branch information
spirali committed Oct 1, 2019
1 parent 007f4ae commit 7a8c80f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
12 changes: 8 additions & 4 deletions elsie/box.py
Expand Up @@ -140,7 +140,8 @@ def box(self,
p_y=None, # vertical padding (sets p_top & p_bottom)
padding=None, # sets the same padding to all directions
horizontal=False,
z_level=None):
z_level=None,
prepend=False):
""" Create a new child box """

def set_padding(a, b):
Expand Down Expand Up @@ -174,7 +175,7 @@ def set_padding(a, b):
p_bottom,
horizontal,
z_level)
self.add_child(box)
self.add_child(box, prepend)
return box

def overlay(self, **kwargs):
Expand Down Expand Up @@ -649,10 +650,13 @@ def mid_point(self):
""" Create a point in the center of the box """
return self.p("50%", "50%")

def add_child(self, obj):
def add_child(self, obj, prepend=False):
""" Semi-internal function, you can add your child if you know
what you are doing. """
self.childs.append(obj)
if prepend:
self.childs.insert(0, obj)
else:
self.childs.append(obj)

def _min_child_size(self):
managed_childs = self._managed_childs
Expand Down
1 change: 1 addition & 0 deletions tests/data/checks/prepend-0.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions tests/test_layout.py
Expand Up @@ -29,6 +29,14 @@ def test_full_box(test_env):
test_env.check("fullbox")


def test_prepend(test_env):
slide = test_env.slide
slide.box().text("A")
slide.box(prepend=True).text("B")
slide.box(prepend=True).text("C")
slide.box().text("D")
test_env.check("prepend")

def test_vbox_nofill(test_env):
slide = test_env.slide
slide.box(width=20, height=40).rect(bg_color="green")
Expand Down

0 comments on commit 7a8c80f

Please sign in to comment.