Generate layout structures

This commit is contained in:
Ben V. Brown
2023-06-29 20:53:22 +10:00
parent c31fb5725b
commit 7a0308dbf4
3 changed files with 154 additions and 51 deletions

1
.gitignore vendored
View File

@@ -178,3 +178,4 @@ CoreCompileInputs.cache
.vscode/settings.json .vscode/settings.json
source/compile_commands.json source/compile_commands.json
.idea/ .idea/
source/UI/layout_96x16.cpp

78
source/UI/generate_ui.py Executable file
View File

@@ -0,0 +1,78 @@
#!/usr/bin/env python3
"""
Read in the yaml config files in this folder
For each config file, generate a cpp file defining each layout
"""
import yaml
from string import Template
def element_to_str(element) -> str:
template = Template(
"""
{
.elementType = ElementTypes_t::$type,
.elementSettings={
.position ={
.x=$x,
.y=$y,
},
.size ={
.w=$w,
.h=$h,
}
},
},
"""
)
return template.substitute(
x=element["position"]["x"],
y=element["position"]["y"],
w=element["size"]["w"],
h=element["size"]["h"],
type=element["type"],
)
def layout_to_str(layout):
inner_elements = "".join(element_to_str(x) for x in layout["elements"])
template = Template(
"""{
.elements =
{
$elements
},
},
"""
)
return template.substitute(elements=inner_elements)
def layouts_to_cpp(layout_file_path, output_file_path):
with open(layout_file_path, "r") as file:
with open(output_file_path, "w") as output:
layout_defs = yaml.safe_load(file)
header = """
#include "UI.h"
#include "UI_Elements.h"
const ScreenLayoutRecord_t screenLayouts[] = {
"""
output.write(header)
for layout_name in layout_defs["layouts"]:
layout = layout_defs["layouts"][layout_name]
# Now we convert this layout into a structure definition
element_entry = layout_to_str(layout)
output.write(element_entry)
footer = """
};
"""
output.write(footer)
layouts_to_cpp("layout_96x16.yaml", "layout_96x16.cpp")

View File

@@ -2,21 +2,21 @@ layouts:
SimplifiedHome: SimplifiedHome:
mirrorOnRotate: true mirrorOnRotate: true
elements: elements:
- type: image - type: Image
position: position:
x: 0 x: 0
y: 0 y: 0
size: size:
w: 42 w: 42
h: 16 h: 16
- type: image - type: Image
position: position:
x: 0 x: 0
y: 0 y: 0
size: size:
w: 42 w: 42
h: 16 h: 16
- type: powerSource - type: PowerSource
position: position:
x: 84 x: 84
y: 0 y: 0
@@ -27,21 +27,21 @@ layouts:
simplifiedHomeWarning: simplifiedHomeWarning:
mirrorOnRotate: true mirrorOnRotate: true
elements: elements:
- type: text - type: Text
position: position:
x: 0 x: 0
y: 0 y: 0
size: size:
w: 42 w: 42
h: 16 h: 16
- type: image - type: Image
position: position:
x: 0 x: 0
y: 0 y: 0
size: size:
w: 42 w: 42
h: 16 h: 16
- type: powerSource - type: PowerSource
position: position:
x: 84 x: 84
y: 0 y: 0
@@ -50,21 +50,21 @@ layouts:
h: 16 h: 16
detailedHome: detailedHome:
elements: elements:
- type: temperature - type: Temperature
position: position:
x: 0 x: 0
y: 0 y: 0
size: size:
w: 48 w: 48
h: 16 h: 16
- type: temperature - type: Temperature
position: position:
x: 48 x: 48
y: 0 y: 0
size: size:
w: 32 w: 32
h: 8 h: 8
- type: inputVoltage - type: InputVoltage
position: position:
x: 48 x: 48
y: 0 y: 0
@@ -73,14 +73,14 @@ layouts:
h: 8 h: 8
detailedHomeWarning: detailedHomeWarning:
elements: elements:
- type: temperature - type: Temperature
position: position:
x: 0 x: 0
y: 0 y: 0
size: size:
w: 48 w: 48
h: 16 h: 16
- type: inputVoltage - type: InputVoltage
position: position:
x: 48 x: 48
y: 0 y: 0
@@ -90,21 +90,21 @@ layouts:
SebugMenu: SebugMenu:
elements: elements:
- type: text - type: Text
position: position:
x: 0 x: 0
y: 0 y: 0
size: size:
w: 96 w: 96
h: 8 h: 8
- type: text - type: Text
position: position:
x: 0 x: 0
y: 8 y: 8
size: size:
w: 48 w: 48
h: 8 h: 8
- type: number - type: Number
position: position:
x: 48 x: 48
y: 8 y: 8
@@ -113,134 +113,158 @@ layouts:
h: 8 h: 8
SettingsCategory: SettingsCategory:
elements: elements:
- type: text - type: Text
position: position:
x: 0 x: 0
y: 0 y: 0
size: size:
w: 78 w: 78
h: 16 h: 16
- type: image - type: Image
position: position:
x: 79 x: 79
y: 0 y: 0
size: size:
w: 16 w: 16
h: 16 h: 16
- type: scrollBar - type: ScrollBar
x: 95 position:
h: 16 x: 95
y: 0
size:
w: 1
h: 16
SettingsEntryBool: SettingsEntryBool:
elements: elements:
- type: text - type: Text
position: position:
x: 0 x: 0
y: 0 y: 0
size: size:
w: 78 w: 78
h: 16 h: 16
- type: checkbox - type: CheckBox
position: position:
x: 79 x: 79
y: 0 y: 0
size: size:
w: 16 w: 16
h: 16 h: 16
- type: scrollBar - type: ScrollBar
x: 95 position:
h: 16 x: 95
y: 0
size:
w: 1
h: 16
SettingsEntry3Number: SettingsEntry3Number:
elements: elements:
- type: text - type: Text
position: position:
x: 0 x: 0
y: 0 y: 0
size: size:
w: 78 w: 78
h: 16 h: 16
- type: number - type: Number
position: position:
x: 79 x: 79
y: 0 y: 0
size: size:
w: 36 w: 36
h: 16 h: 16
- type: scrollBar - type: ScrollBar
x: 95 position:
h: 16 x: 95
y: 0
size:
w: 1
h: 16
SettingsEntry2Number: SettingsEntry2Number:
elements: elements:
- type: text - type: Text
position: position:
x: 0 x: 0
y: 0 y: 0
size: size:
w: 78 w: 78
h: 16 h: 16
- type: number - type: Number
position: position:
x: 79 x: 79
y: 0 y: 0
size: size:
w: 36 w: 36
h: 16 h: 16
- type: scrollBar - type: ScrollBar
x: 95 position:
h: 16 x: 95
y: 0
size:
w: 1
h: 16
SettingsEntry1Number: SettingsEntry1Number:
elements: elements:
- type: text - type: Text
position: position:
x: 0 x: 0
y: 0 y: 0
size: size:
w: 78 w: 78
h: 16 h: 16
- type: number - type: Number
position: position:
x: 79 x: 79
y: 0 y: 0
size: size:
w: 36 w: 36
h: 16 h: 16
- type: scrollBar - type: ScrollBar
x: 95 position:
h: 16 x: 95
y: 0
size:
w: 1
h: 16
SettingsEntry1Text: SettingsEntry1Text:
elements: elements:
- type: text - type: Text
position: position:
x: 0 x: 0
y: 0 y: 0
size: size:
w: 78 w: 78
h: 16 h: 16
- type: number - type: Number
position: position:
x: 79 x: 79
y: 0 y: 0
size: size:
w: 36 w: 36
h: 16 h: 16
- type: scrollBar - type: ScrollBar
x: 95 position:
h: 16 x: 95
y: 0
size:
w: 1
h: 16
ScrollingText: ScrollingText:
elements: elements:
- type: textScroller - type: TextScroller
position: position:
x: 0 x: 0
y: 0 y: 0
size: size:
w: 96 w: 96
h: 16 h: 16
SolderingMode: # SolderingMode:
elements: # elements:
DetailedSolderingMode: # DetailedSolderingMode:
elements: # elements:
NumberAdjust: # NumberAdjust:
elements: # elements: