diff --git a/.gitignore b/.gitignore index c7892f41..de0bfaf3 100644 --- a/.gitignore +++ b/.gitignore @@ -178,3 +178,4 @@ CoreCompileInputs.cache .vscode/settings.json source/compile_commands.json .idea/ +source/UI/layout_96x16.cpp diff --git a/source/UI/generate_ui.py b/source/UI/generate_ui.py new file mode 100755 index 00000000..111cd0d4 --- /dev/null +++ b/source/UI/generate_ui.py @@ -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") diff --git a/source/UI/layout_96x16.yaml b/source/UI/layout_96x16.yaml index 379eca55..78fbec18 100644 --- a/source/UI/layout_96x16.yaml +++ b/source/UI/layout_96x16.yaml @@ -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 - x: 95 - h: 16 + - 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 - x: 95 - h: 16 + - 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 - x: 95 - h: 16 + - 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 - x: 95 - h: 16 + - 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 - x: 95 - h: 16 + - 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 - x: 95 - h: 16 + - 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: