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