Brian Dunning's FileMaker Custom Functions

ContrastText ( foregroundText ; bgRedPercent ; bgGreenPercent ; bgBluePercen

Colors foregroundText black or white as appropriate for the specified background color.

  Average rating: 4.0 (34 votes) Log in to vote

Joe Rovang   Joe Rovang - Show more from this author

Share on Facebook Share on Twitter

  Sample input:
ContrastText ( "Text" ; 0 ; 0 ; .5 )
  Sample output:
Text
{{colored white}}

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

Parameters:
foregroundText
bgRedPercent
bgGreenPercent
bgBluePercent

This function will color foregroundText black or white, depending on the background color specified using the respective percentage parameters. (Color percentages must be specified as values between 0 and 1.)

This could come in handy if you have a background color generated dynamically (in my solution, I did this using a TextColor-based calculation field set to output a block character at a very large font size). If your colors are generated by HSB (hue/saturation/brightness, also known as HSV/HSL), try my HSBtoRGB() function to convert those values to RGB percentages as input parameters for this function.

Feel free to adjust the luminance values embedded in the function, especially if your color perception or monitor settings are atypical!

 

Comments

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: