Package: rpi-inky-layout
RPi Inky Layout ManagerThis is a layout manager I wrote to help me break up the display of a
Pimoroni Inky-pHAT into seperate drawable areas.You might find other uses for it - let me know if it's handy!The outline process is:Use theLayoutclass to create a top-level Layout object.Next, add new layers to aLayout- it automatically resizes the otherLayouts at the same level.Take each added sublayerLayout, and use itssizeto define a new PILImageto draw on.Draw on the image, Set theImageon the appropriateLayout.Invoke the top-levelLayout'sdraw()method to merge them all together, drawing borders as necessary.And you end up with a nicely-spaced regions.How it worksCreate a new Layout:layout = Layout( size, packingMode, border)where:sizeis a 2-part tuple of the form(width, height).packingModeis the packing direction: currently eitherh(horizontal) orv(vertical).borderis either a) the width of border (colour defaults to2) or b) a 2-tuple containing(width, colour).Next, add multiple sub-layouts tolayoutsublayout1 = layout.addLayer()
sublayout2 = layout.addLayer()Then, for leach sublayout, usesublayout.sizeas the size of the image to draw on.im1 = Image.new(mode, sublayout1.size, bgColour)
...Draw on the image; Set it back on the sublayout:sublayout1.setImage(im1)
...And finally, draw the top level layout and write to file:layout.draw()
layout.write(filename)You can then do what you want with the file, e.g., load it onto anInky display usingsetImageDetailed usage exampleHere's a detailed example.PrerequisitesYou will definitely need some sort of image manipulation library, such aspillowfrom PIL import Image, ImageDrawAnd, since this is built initially for use withInky displays, you should probably import that, too:from inky.auto import autoCreate new LayersCreate the top-levelLayout:toplevel = Level( (400,100), packingMode='h', border=(1,2))Or, if you're using your inky:board = auto()
toplevel = Level (board.resolution, 'h', (0,0) )Add as many new layers as you want:sublayout1 = layout.addLayer()
sublayout2 = layout.addLayer()
sublayout3 = layout.AddLayer()
sublayout31 = sublayout3.addLayer()
sublayout32 = sublayout3.addLayer()Use the sub-layouts to create images:mode = "P"
bgColour = 0
image31 = Image.new(mode, sublayout31.size, bgColour)
draw = ImageDraw.Draw(image31)
draw.text(tuple(s/2 for s in sublayout31.size), "Hello",1)
sublayout31.setImage(image31)

image32 = Image.new(mode, sublayout32.size, bgColour)
draw = ImageDraw.Draw(image32)
draw.text(tuple(s/2 for s in sublayout32.size), "World!",1)
sublayout32.setImage(image32)

layout.draw()
layout.write("hello-world.png")If you're using the Inky, you can load the image up:inky_image = Image.open("hello-world.png")
board.set_image(inky_image)And you're done!Advanced FeaturesRotationIf you want to render the Layout in a rotated orientation, you can set the
Rotation parameter. It takes the values:UP - normal, no rotation;LEFT - rotation by -90 or 270 degreesRIGHT - rotation by +90 degreesDOWN - rotated 180 degrees (up side down)see underlibrary/test/expected-images/test-rotated*.pngfor some examples.Packing BiasWhen adding a layer, you can specify packing bias:layout = new Layout()
sublayout1 = layout.addLayer(packingBias=2)
sublayout2 = layout.addLayer()  # default packingBias=1In this example,sublayout1will take up 2/3rds of the space (2/(1+2)),
whilesublayout2will be left with the remaining 1/3rd.