Skip to content

FoamyGuy/circuitpython_display_layouts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Warning

This library is in the very early stages of development. Pretty much all aspects of it are subject to change at any time right now. And there are still very likely things not working properly.

What it does

This library attempts to simplify the process of making Circuit Python projects that use displayio based visual interfaces.

The two primary ways we aim to do this are:

  • Provide a JSON based layout config system. Layouts can be stored seperately from the logic of the application and rendered with minimal python code.
  • Provide a few Layout objects that will use some pre-defined techniques for positioning their sub_views

This library will take a JSON layout file like this:

{
 "view_type": "AbsoluteLayout",
 "sub_views": [
   {
     "view_type": "Label",
     "id":"main_lbl",
     "attributes":{
       "anchored_position": ["DISPLAY_WIDTH/2", "DISPLAY_HEIGHT/8"],
       "color": "0xFF00FF",
       "anchor_point": [0.5, 0.0],
       "text": "1",
       "max_glyphs": 60,
       "background_color": "0x0000FF",
       "line_spacing": 1.8
     }
   },
   {
     "view_type": "Image",
     "id":"main_img",
     "attributes":{
       "image_file": "images/2bit.bmp",
       "x": "DISPLAY_WIDTH/2-WIDTH/2",
       "y":85,
       "padding": 16,
       "background_color": "0x777777"
     }
   },
   {
     "view_type": "OnDiskBitmap",
     "id":"main_img",
     "attributes":{
       "image_file": "images/4bit.bmp",
       "x": "DISPLAY_WIDTH-WIDTH",
       "y":70,
       "padding": 16,
       "background_color": "0x777777"
     }
   }
 ]
}

And allow you to render it to the screen with some python code like this:

import board
import displayio
from display_layouts.absolute_layout import AbsoluteLayout

f = open("layouts/simpletest.json", "r")
layout_str = f.read()
f.close()
main_layout = AbsoluteLayout(board.DISPLAY, layout_str)

board.DISPLAY.show(main_layout.view)

#main_layout.sub_view_by_index(0).label.text = "Changed Text\nBy Index"
main_layout.sub_view_by_id("main_lbl").label.text = "Changed\nText By Id"

while True:
   pass

The layout above would look like this:

simpletest_screenshot

For more examples see the examples directory in the repo.

If you have any feedback about the project please get in touch I am curious to get input :)

Release Notes:

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages