Better Disabled buttons support. Mammal theme fixes. Implemented proper
context-aware `mod` argument - now checks lightness of "variant" color. needs retesting tho
This commit is contained in:
parent
e46bb94226
commit
611da13a4b
7 changed files with 89 additions and 34 deletions
|
@ -85,6 +85,8 @@ export const SLOT_INHERITANCE = {
|
|||
},
|
||||
text: {
|
||||
depends: [],
|
||||
layer: 'bg',
|
||||
opacity: null,
|
||||
priority: 1
|
||||
},
|
||||
underlay: {
|
||||
|
@ -422,6 +424,7 @@ export const SLOT_INHERITANCE = {
|
|||
// Buttons
|
||||
btn: {
|
||||
depends: ['fg'],
|
||||
variant: 'btn',
|
||||
opacity: 'btn'
|
||||
},
|
||||
btnText: {
|
||||
|
@ -430,20 +433,23 @@ export const SLOT_INHERITANCE = {
|
|||
textColor: true
|
||||
},
|
||||
btnPanelText: {
|
||||
depends: ['panelText'],
|
||||
depends: ['btnText'],
|
||||
layer: 'btnPanel',
|
||||
variant: 'btn',
|
||||
textColor: true
|
||||
},
|
||||
btnTopBarText: {
|
||||
depends: ['topBarText'],
|
||||
depends: ['btnText'],
|
||||
layer: 'btnTopBar',
|
||||
variant: 'btn',
|
||||
textColor: true
|
||||
},
|
||||
|
||||
// Buttons: pressed
|
||||
btnPressed: '--btn',
|
||||
btnPressed: {
|
||||
depends: ['btn'],
|
||||
layer: 'btn'
|
||||
},
|
||||
btnPressedText: {
|
||||
depends: ['btnText'],
|
||||
layer: 'btn',
|
||||
|
@ -451,7 +457,8 @@ export const SLOT_INHERITANCE = {
|
|||
textColor: true
|
||||
},
|
||||
btnPressedPanel: {
|
||||
depends: ['btnPressed']
|
||||
depends: ['btnPressed'],
|
||||
layer: 'btn'
|
||||
},
|
||||
btnPressedPanelText: {
|
||||
depends: ['btnPanelText'],
|
||||
|
@ -469,6 +476,7 @@ export const SLOT_INHERITANCE = {
|
|||
// Buttons: toggled
|
||||
btnToggled: {
|
||||
depends: ['btn'],
|
||||
layer: 'btn',
|
||||
color: (mod, btn) => brightness(mod * 20, btn).rgb
|
||||
},
|
||||
btnToggledText: {
|
||||
|
@ -496,25 +504,22 @@ export const SLOT_INHERITANCE = {
|
|||
color: (mod, btn, bg) => alphaBlend(btn, 0.5, bg)
|
||||
},
|
||||
btnDisabledText: {
|
||||
depends: ['btnText'],
|
||||
depends: ['btnText', 'btnDisabled'],
|
||||
layer: 'btn',
|
||||
variant: 'btnDisabled',
|
||||
textColor: true,
|
||||
color: (mod, text) => brightness(mod * -60, text).rgb
|
||||
color: (mod, text, btn) => alphaBlend(text, 0.5, btn)
|
||||
},
|
||||
btnDisabledPanelText: {
|
||||
depends: ['btnPanelText'],
|
||||
depends: ['btnPanelText', 'btnDisabled'],
|
||||
layer: 'btnPanel',
|
||||
variant: 'btnDisabled',
|
||||
textColor: true,
|
||||
color: (mod, text) => brightness(mod * -60, text).rgb
|
||||
color: (mod, text, btn) => alphaBlend(text, 0.5, btn)
|
||||
},
|
||||
btnDisabledTopBarText: {
|
||||
depends: ['btnTopBarText'],
|
||||
depends: ['btnTopBarText', 'btnDisabled'],
|
||||
layer: 'btnTopBar',
|
||||
variant: 'btnDisabled',
|
||||
textColor: true,
|
||||
color: (mod, text) => brightness(mod * -60, text).rgb
|
||||
color: (mod, text, btn) => alphaBlend(text, 0.5, btn)
|
||||
},
|
||||
|
||||
// Input fields
|
||||
|
|
|
@ -255,14 +255,17 @@ export const computeDynamicColor = (sourceColor, getColor, mod) => {
|
|||
}
|
||||
|
||||
/**
|
||||
* THE function you want to use. Takes provided colors and opacities, mod
|
||||
* THE function you want to use. Takes provided colors and opacities
|
||||
* value and uses inheritance data to figure out color needed for the slot.
|
||||
*/
|
||||
export const getColors = (sourceColors, sourceOpacity, mod) => SLOT_ORDERED.reduce(({ colors, opacity }, key) => {
|
||||
export const getColors = (sourceColors, sourceOpacity) => SLOT_ORDERED.reduce(({ colors, opacity }, key) => {
|
||||
const value = SLOT_INHERITANCE[key]
|
||||
const isObject = typeof value === 'object'
|
||||
const isString = typeof value === 'string'
|
||||
const sourceColor = sourceColors[key]
|
||||
const variant = value.variant || value.layer || 'bg'
|
||||
const isLightOnDark = relativeLuminance(colors[variant] || sourceColors[variant]) < 0.5
|
||||
const mod = isLightOnDark ? 1 : -1
|
||||
let outputColor = null
|
||||
if (sourceColor) {
|
||||
// Color is defined in source color
|
||||
|
@ -318,7 +321,7 @@ export const getColors = (sourceColors, sourceOpacity, mod) => SLOT_ORDERED.redu
|
|||
opacity
|
||||
)
|
||||
)
|
||||
const isLightOnDark = relativeLuminance(bg) > 127
|
||||
const isLightOnDark = relativeLuminance(bg) > 0.5
|
||||
const mod = isLightOnDark ? 1 : -1
|
||||
|
||||
if (value.textColor === 'bw') {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue