added styles to TextElement

This commit is contained in:
Djeeberjr 2023-07-11 13:17:33 +02:00
parent 8683eaf17a
commit dfaabea00d
4 changed files with 19 additions and 9 deletions

View File

@ -41,11 +41,11 @@ class PFClient implements Process {
var childre: Array<UIElement> = [
new TextElement('Acc: ${acc}'),
new TextElement('Pos: X:${pos.x} Y:${pos.y} Z:${pos.z}'),
new TextElement('UPDATE', { onClick: () -> {
new TextElement('UPDATE', { style: {bgColor: Gray}, uiEvents: {onClick: () -> {
kernel.gps.GPS.instance.locate().handle((pos) ->{
this.requestRender();
});
}}),
}}}),
];
this.root.setChildren(childre);

View File

@ -154,18 +154,18 @@ class HomeContext {
workspaceIDs.sort((a, b) -> a - b);
var children:Array<UIElement> = [
for (i in workspaceIDs) new TextElement('Switch to ${i + 1}', {onClick: this.handleSelectContext.bind(i)})
for (i in workspaceIDs) new TextElement('Switch to ${i + 1}', {uiEvents: {onClick: this.handleSelectContext.bind(i)}})
];
for (i in 0...listedApps.length) {
children.push(new TextElement(
'Add ${BinStore.instance.getNameByAlias(listedApps[i])}',
{onClick: this.spawnPs.bind(listedApps[i])}
{uiEvents: {onClick: this.spawnPs.bind(listedApps[i])}}
));
}
children.push(new TextElement('Output: ${selectedOutput}', {onClick: this.cycleOutput}));
children.push(new TextElement('Exit', {onClick: KernelEvents.instance.shutdown}));
children.push(new TextElement('Output: ${selectedOutput}',{ uiEvents:{ onClick: this.cycleOutput}}));
children.push(new TextElement('Exit', {style: {bgColor: Red}, uiEvents: {onClick: KernelEvents.instance.shutdown}}));
renderer.setChildren(children);

8
src/lib/ui/Style.hx Normal file
View File

@ -0,0 +1,8 @@
package lib.ui;
import lib.Color;
typedef Style = {
public var ?fgColor: Color;
public var ?bgColor: Color;
}

View File

@ -6,10 +6,12 @@ class TextElement implements UIElement {
public var text:String;
private final uiEvents:UIEvents;
private final style:Style;
public function new(text:String, ?uiEvents:UIEvents) {
public function new(text:String, ?props: {?style:Style, ?uiEvents:UIEvents}) {
this.text = text;
this.uiEvents = uiEvents;
this.uiEvents = props?.uiEvents;
this.style = props?.style ?? {fgColor: White, bgColor: Black};
}
public function set(text:String) {
@ -28,7 +30,7 @@ class TextElement implements UIElement {
var canvas = new Canvas();
for (i in 0...this.text.length) {
var c = this.text.charAt(i);
canvas.set({x: i, y: 0}, {bg: Black, textColor: White, char: c});
canvas.set({x: i, y: 0}, {bg: style.bgColor ?? Black, textColor: style.fgColor ?? White, char: c});
}
return canvas;