promenu: factor out `drawLine()`
parent
4d8c46ba51
commit
8aa839be26
|
|
@ -39,6 +39,49 @@ E.showMenu = (items?: Menu): MenuInstance => {
|
||||||
scroll: selected,
|
scroll: selected,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const drawLine = (
|
||||||
|
name: string,
|
||||||
|
v: string,
|
||||||
|
item: ActualMenuItem,
|
||||||
|
idx: number,
|
||||||
|
x: number,
|
||||||
|
y: number,
|
||||||
|
) => {
|
||||||
|
const hl = (idx === selected && !selectEdit);
|
||||||
|
if(g.theme.dark){
|
||||||
|
fillRectRnd(x, y, x2, y + fontHeight - 3, 7, hl ? g.theme.bgH : g.theme.bg + 40);
|
||||||
|
}else{
|
||||||
|
fillRectRnd(x, y, x2, y + fontHeight - 3, 7, hl ? g.theme.bgH : g.theme.bg - 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
g.setFont12x20()
|
||||||
|
.setColor(hl ? g.theme.fgH : g.theme.fg)
|
||||||
|
.setFontAlign(-1, -1);
|
||||||
|
|
||||||
|
const vplain = v.indexOf("\0") < 0;
|
||||||
|
if(vplain && name.length >= 17 - v.length && typeof item === "object"){
|
||||||
|
g.drawString(name.substring(0, 12 - v.length) + "...", x + 3.7, y + 2.7);
|
||||||
|
}else if(vplain && name.length >= 15){
|
||||||
|
g.drawString(name.substring(0, 15) + "...", x + 3.7, y + 2.7);
|
||||||
|
}else{
|
||||||
|
g.drawString(name, x + 3.7, y + 2.7);
|
||||||
|
}
|
||||||
|
|
||||||
|
let xo = x2;
|
||||||
|
if (selectEdit && idx === selected) {
|
||||||
|
xo -= 24 + 1;
|
||||||
|
g.setColor(g.theme.fgH)
|
||||||
|
.drawImage(
|
||||||
|
"\x0c\x05\x81\x00 \x07\x00\xF9\xF0\x0E\x00@",
|
||||||
|
xo,
|
||||||
|
y + (fontHeight - 10) / 2,
|
||||||
|
{scale:2},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
g.setFontAlign(1, -1);
|
||||||
|
g.drawString(v, xo - 2, y + 1);
|
||||||
|
};
|
||||||
|
|
||||||
const l = {
|
const l = {
|
||||||
draw: (rowmin?: number, rowmax?: number) => {
|
draw: (rowmin?: number, rowmax?: number) => {
|
||||||
let rows = 0|Math.min((y2 - y) / fontHeight, menuItems.length);
|
let rows = 0|Math.min((y2 - y) / fontHeight, menuItems.length);
|
||||||
|
|
@ -66,17 +109,7 @@ E.showMenu = (items?: Menu): MenuInstance => {
|
||||||
const name = menuItems[idx];
|
const name = menuItems[idx];
|
||||||
const item = items![name]! as ActualMenuItem;
|
const item = items![name]! as ActualMenuItem;
|
||||||
|
|
||||||
const hl = (idx === selected && !selectEdit);
|
let v: string;
|
||||||
if(g.theme.dark){
|
|
||||||
fillRectRnd(x, iy, x2, iy + fontHeight - 3, 7, hl ? g.theme.bgH : g.theme.bg + 40);
|
|
||||||
}else{
|
|
||||||
fillRectRnd(x, iy, x2, iy + fontHeight - 3, 7, hl ? g.theme.bgH : g.theme.bg - 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
g.setColor(hl ? g.theme.fgH : g.theme.fg);
|
|
||||||
g.setFontAlign( - 1, -1);
|
|
||||||
|
|
||||||
let v;
|
|
||||||
if (typeof item === "object") {
|
if (typeof item === "object") {
|
||||||
v = "format" in item
|
v = "format" in item
|
||||||
? (item.format as any)(item.value) // <T>format(), value: T
|
? (item.format as any)(item.value) // <T>format(), value: T
|
||||||
|
|
@ -86,30 +119,7 @@ E.showMenu = (items?: Menu): MenuInstance => {
|
||||||
v = "";
|
v = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/*???*/{
|
drawLine(name, v, item, idx, x, iy);
|
||||||
const vplain = v.indexOf("\0") < 0;
|
|
||||||
if(vplain && name.length >= 17 - v.length && typeof item === "object"){
|
|
||||||
g.drawString(name.substring(0, 12 - v.length) + "...", x + 3.7, iy + 2.7);
|
|
||||||
}else if(vplain && name.length >= 15){
|
|
||||||
g.drawString(name.substring(0, 15) + "...", x + 3.7, iy + 2.7);
|
|
||||||
}else{
|
|
||||||
g.drawString(name, x + 3.7, iy + 2.7);
|
|
||||||
}
|
|
||||||
|
|
||||||
let xo = x2;
|
|
||||||
if (selectEdit && idx === selected) {
|
|
||||||
xo -= 24 + 1;
|
|
||||||
g.setColor(g.theme.fgH)
|
|
||||||
.drawImage(
|
|
||||||
"\x0c\x05\x81\x00 \x07\x00\xF9\xF0\x0E\x00@",
|
|
||||||
xo,
|
|
||||||
iy + (fontHeight - 10) / 2,
|
|
||||||
{scale:2},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
g.setFontAlign(1, -1);
|
|
||||||
g.drawString(v, xo - 2, iy + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
g.setColor(g.theme.fg);
|
g.setColor(g.theme.fg);
|
||||||
iy += fontHeight;
|
iy += fontHeight;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue