From 66d493b1ddff8939543c3e30e103e3da4b194d3d Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sun, 1 Oct 2023 23:24:32 +0200 Subject: [PATCH] refactor: rework tool color in extruder panel Signed-off-by: Stefan Dej --- .../Extruder/ExtruderControlPanelTools.vue | 23 +++++++- .../ExtruderControlPanelToolsItem.vue | 55 +++++++++++++++++-- 2 files changed, 69 insertions(+), 9 deletions(-) diff --git a/src/components/panels/Extruder/ExtruderControlPanelTools.vue b/src/components/panels/Extruder/ExtruderControlPanelTools.vue index 0d675ee0f..e5d395e66 100644 --- a/src/components/panels/Extruder/ExtruderControlPanelTools.vue +++ b/src/components/panels/Extruder/ExtruderControlPanelTools.vue @@ -1,7 +1,13 @@ diff --git a/src/components/panels/Extruder/ExtruderControlPanelToolsItem.vue b/src/components/panels/Extruder/ExtruderControlPanelToolsItem.vue index 937b7ae89..707a2cd68 100644 --- a/src/components/panels/Extruder/ExtruderControlPanelToolsItem.vue +++ b/src/components/panels/Extruder/ExtruderControlPanelToolsItem.vue @@ -1,11 +1,11 @@ @@ -27,19 +27,62 @@ export default class ExtruderControlPanel extends Mixins(BaseMixin, ControlMixin } get color() { - return this.macro.variables.color ?? this.macro.variables.colour ?? null + const color = this.macro.variables.color ?? this.macro.variables.colour ?? null + if (color === '' || color === 'undefined') return null + + return color } - get buttonClass() { - return { - 'primary--text': this.active, + get primaryColor(): string { + return this.$store.state.gui.uiSettings.primary + } + + get primaryTextColor(): string { + let splits = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(this.primaryColor) + if (splits) { + const r = parseInt(splits[1], 16) * 0.2126 + const g = parseInt(splits[2], 16) * 0.7152 + const b = parseInt(splits[3], 16) * 0.0722 + const perceivedLightness = (r + g + b) / 255 + + return perceivedLightness > 0.7 ? '#222' : '#fff' } + + return '#ffffff' + } + + get warningColor(): string { + return this.$vuetify?.theme?.currentTheme?.warning?.toString() ?? '#ff8300' } get buttonStyle() { + let backgroundColor = '' + if (this.active) { + backgroundColor = this.homedAxes.includes('xyz') ? this.primaryColor : this.warningColor + } + + const textColor = this.active ? this.primaryTextColor : '' + return { + color: textColor, + 'background-color': backgroundColor, + } + } + + get dotStyle() { + return { + 'border-color': this.active ? this.primaryTextColor : '', 'background-color': '#' + this.color, } } } + +