Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hiContrastColor (e.g. black or white) depending on color brightness - for overlying text #6

Open
stam66 opened this issue Mar 7, 2022 · 0 comments

Comments

@stam66
Copy link
Contributor

stam66 commented Mar 7, 2022

I often need the textColor of buttons, fields or widgets to change based on background colour (eg on highlight), and need this to be black or white (or at least a defined dark and light colour, rather than a random opposing colour) to provide a consistent interface.

I may have missed it, but can't see such a function in the library, although it's simple enough.
If i understood the mostReadable function correctly it determines what the most readable colour is, but not necessarily what i want for my interface; and defaults to black or white only when the 'most readable' isn't readable.

While this is useful, i prefer a simpler, more straightforward methods such as:

// Dichotomous color (eg. black or white) defined by brightness of given color 
// intended for text color for max contrast with underlying colour
function hiContrastForColor pColor, colorForLight, colorForDark
    if colorForLight is empty then put "black" into colorForLight //i.e. defaults to black for light colours
    if colorForDark is empty then put "white" into colorForDark //i.e. defaults to white for dark colours
    if isDark(pColor) then
        return colorForDark
    else
        return colorForLight
    end if
end hiContrastForColor

would it be possible to consider this or something like this for an addition to the library?
Of if it's already present please do point this out.
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant