britzl / defold-richtext

Defold-RichText is a system to create styled text based on an HTML inspired markup language
MIT License
75 stars 12 forks source link

Make it easy to inject color lists #59

Closed subsoap closed 4 years ago

subsoap commented 4 years ago

I want to be able to insert a list of colors by name and then be able to easily use them in text. Color names like "abyssal_green" or "lotus_red" with associated color codes.

What I am doing currently is

local richtext_color = require "richtext.color"

local function richtext_insert_colors()
    richtext_color.COLORS["abyssal_green"] = richtext_color.parse_hex("#05f0bc") -- #14ffb9
    richtext_color.COLORS["lotus_red"] = richtext_color.parse_hex("#ff0946")
end

Maybe make it a richtext main function to add a color to the list by name.

richtext.add_color("name", "code") 

Where code is auto detected to be RGB/RGBA/hex/hexa, and if the color already existed it would silently replace it.