diff --git a/src/js/control-view.js b/src/js/control-view.js index 7fa1134..b5c67f5 100644 --- a/src/js/control-view.js +++ b/src/js/control-view.js @@ -186,6 +186,33 @@ module.exports = { return [weight, color].join(";"); }, + // Should the macro row render a colored left stripe for this + // macro? Only when the user has explicitly picked a color. The + // controller seeds new macros with default placeholders like + // "#ffffff" or "#dedede"; treat anything that close to white as + // "no color". + has_macro_color(macros) { + if (!macros || typeof macros.color !== "string") return false; + const c = macros.color.trim().toLowerCase(); + if (!c) return false; + const defaults = [ + "#fff", "#ffffff", "#fefefe", "#fdfdfd", "#fcfcfc", + "#dedede", "#dddddd", "#cccccc", + ]; + if (defaults.indexOf(c) !== -1) return false; + // Fallback: if the color is very close to white (sum of RGB + // > 690), suppress the stripe. + const m = c.match(/^#([0-9a-f]{6})$/); + if (m) { + const v = parseInt(m[1], 16); + const r = (v >> 16) & 0xff; + const g = (v >> 8) & 0xff; + const b = v & 0xff; + if (r + g + b > 690) return false; + } + return true; + }, + jog_fn: function (x_jog, y_jog, z_jog, a_jog) { const amount = this.jog_incr_amounts[this.display_units][this.jog_incr]; diff --git a/src/pug/templates/control-view.pug b/src/pug/templates/control-view.pug index e7a6df3..d4ed305 100644 --- a/src/pug/templates/control-view.pug +++ b/src/pug/templates/control-view.pug @@ -246,13 +246,16 @@ script#control-view-template(type="text/x-template") .stat-sub(v-else) Line · ETA -- // ----- Macro row (slice 0..7); full list lives in Settings → Macros ----- + // The colored left stripe (.has-color) is suppressed for white, + // near-white and other default placeholder colors so unconfigured + // macros render as clean slate tiles instead of looking lopsided. .macro-row(v-if="state.macros && state.macros.length") button.macro-btn(v-for="(index, macros) in state.macros.slice(0, 8)", title="Click to run macro", @click="run_macro(index)", :disabled="!is_ready", - :class="{'has-color': macros.color && macros.color !== '#ffffff' && macros.color !== '#fff'}", - :style="macros.color && macros.color !== '#ffffff' && macros.color !== '#fff' ? {borderLeftColor: macros.color} : {}") + :class="{'has-color': has_macro_color(macros)}", + :style="has_macro_color(macros) ? {borderLeftColor: macros.color} : {}") span.mnum {{index + 1}} span.mname {{macros.name || ('Macro ' + (index + 1))}}