Plugin to easily set colors

I made this plugin awhile ago, and it’s now free on the Solar2D directory. Hope you guys enjoy it.

Here’s some examples

-- setup
local materialColors = require "plugin.materialcolors"
materialColors.initHooks()

-- Hex
local circle = display.newCircle( 100, 100, 50 )
circle:setFillColor( "#FF0000" )
circle.stroke = 5
circle:setStrokeColor( "#00FF00" )

-- Hex with alpha
local circle = display.newCircle( 100, 100, 50 )
circle:setFillColor( "#FF00007F" ) -- about 50% alpha because of the 7F appended at the end
circle.stroke = 5
circle:setStrokeColor( "#00FF0000" ) -- 0% alpha because of the 00 appended at the end

-- Material Color
local circle = display.newCircle( 100, 100, 50 )
circle:setFillColor( "red350" )
circle.stroke = 5
circle:setStrokeColor( "green500" )

-- Material Color with alpha
local circle = display.newCircle( 100, 100, 50 )
circle:setFillColor( "red350-50" ) -- 50% alpha because of the -50 appended at the end
circle.stroke = 5
circle:setStrokeColor( "green500-0" ) -- 0% alpha because of the -0 appended at the end

Include it in your project now like this

{
    plugins = {
        ["plugin.materialcolors"] = {
            publisherId = "io.joehinkle",
        },
    },
}

GitHub repo: https://github.com/solar2d/io.joehinkle-plugin.materialcolors/

Enjoy!

6 Likes

Hi @joecoronasdk

This is a really cool plugin! Thank you for sharing!

However, I’m not 100% sure how this works so I’m having trouble using it for buttons. For the newButton Widget, after creating the button, I can use
buttonName:setFillColor( buttonColor )
To set the color of the button. It works almost exactly how I want it to work!

The only thing missing, is I don’t know how to set the select color. (the color the button will be when it is pressed or selected.) For reference, before using this, I would set the fill color while defining the button by passing a table with 2 color values with this line:
fillColor = { default={ 0.25882352941176,0.24313725490196,0.15686274509804 }, over={ 0.25882352941176,0.24313725490196,0.15686274509804 } },

How can I set the over color using this plugin?

Thank you so much!

-Todd

I don’t think it supports “over” fill colors, but to be honest I don’t remember.