better randomize option

master
kkayam 2025-02-11 15:54:17 +03:00
parent 70e9668be6
commit a983fce5ab
1 changed files with 25 additions and 14 deletions

View File

@ -151,20 +151,21 @@
return { return {
fg: cl("#000"), // black for readability fg: cl("#000"), // black for readability
bg: bgColor, bg: bgColor,
fg2: cl("#666"), // gray for contrast fg2: randomColor(), // random secondary foreground
bg2: randomColor(), bg2: randomColor(), // random secondary background
fgH: cl("#FFF"), // white for highlights fgH: cl("#FFF"), // white for highlights
bgH: randomColor(), bgH: randomColor(), // random highlight background
dark: false dark: false
}; };
}; };
// Create array of theme entries for the scroller // Create array of theme entries for the scroller
const themeEntries = Object.keys(THEMES).map(name => [name, THEMES[name]]); const themeEntries = Object.keys(THEMES).map(name => [name, THEMES[name]]);
let randomTheme = null; // Store the current random theme
themeEntries.push(['Randomize', null]); themeEntries.push(['Randomize', null]);
const ITEM_HEIGHT = 50; // Height for each theme item const ITEM_HEIGHT = 50; // Height for each theme item
E.showScroller({ let scroller = E.showScroller({
h: ITEM_HEIGHT, h: ITEM_HEIGHT,
c: themeEntries.length, c: themeEntries.length,
draw: (idx, rect) => { draw: (idx, rect) => {
@ -172,12 +173,18 @@
var name = entry[0]; var name = entry[0];
var theme = entry[1]; var theme = entry[1];
// Fill background with theme color // For Randomize option, use the stored random theme if available
if (theme) { if (name === 'Randomize') {
g.setColor(theme.bg); if (!randomTheme) {
g.fillRect(rect.x, rect.y, rect.x + rect.w, rect.y + rect.h); randomTheme = createRandomTheme();
}
theme = randomTheme;
} }
// Fill background with theme color
g.setColor(theme ? theme.bg : g.theme.bg);
g.fillRect(rect.x, rect.y, rect.x + rect.w, rect.y + rect.h);
// Draw theme name with theme's foreground color // Draw theme name with theme's foreground color
g.setColor(theme ? theme.fg : g.theme.fg); g.setColor(theme ? theme.fg : g.theme.fg);
g.setFontAlign(-1, -1, 0); g.setFontAlign(-1, -1, 0);
@ -187,19 +194,19 @@
// Draw color preview bars // Draw color preview bars
const barWidth = 16; const barWidth = 16;
const barHeight = 20; const barHeight = 20;
const colors = theme ? [ const colors = [
theme.fg2, // Secondary Foreground theme.fg2, // Secondary Foreground
theme.bg2, // Secondary Background theme.bg2, // Secondary Background
theme.fgH, // Highlight Foreground theme.fgH, // Highlight Foreground
theme.bgH // Highlight Background theme.bgH // Highlight Background
] : ['#F00', '#FF0', '#0F0', '#0FF', '#00F', '#F0F']; ];
const totalWidth = barWidth * colors.length; const totalWidth = barWidth * colors.length;
const startX = rect.x + rect.w - totalWidth - 10; const startX = rect.x + rect.w - totalWidth - 10;
const startY = rect.y + (rect.h - barHeight) / 2; const startY = rect.y + (rect.h - barHeight) / 2;
colors.forEach((color, i) => { colors.forEach((color, i) => {
g.setColor(theme ? color : cl(color)); g.setColor(color);
g.fillRect( g.fillRect(
startX + (i * barWidth), startX + (i * barWidth),
startY, startY,
@ -210,10 +217,14 @@
}, },
select: (idx) => { select: (idx) => {
var name = themeEntries[idx][0]; var name = themeEntries[idx][0];
setTheme(name === 'Randomize' ? createRandomTheme() : name); if (name === 'Randomize') {
randomTheme = createRandomTheme();
setTheme(randomTheme);
} else {
setTheme(name);
}
// Force a redraw to update all theme colors // Force a redraw to update all theme colors
g.clear(); scroller.draw();
E.showScroller();
} }
}); });
} }