mate64 mate64 - 4 months ago 10
CSS Question

GTK+ CSS shade script function

What is the purpose of the

shade
function? Unfortunately the function is not documented. Does it affect the saturation, grayscale, opacity or hue of a color property?

shade(hex:string, value:double)


Example

body {
background: shade(#000, 0.15);
}

h1 {
color: shade(#ddd, 22.6875);
}

Answer

It seems to multiply luminance of RGB in hex by given value with some custom weighs.

gtk-widgets.css

button {
    background-color: shade(rgb(160,120,100), 0.5);
}

cssshade.cpp

#include <gtkmm.h>

#include <iostream>
#include <string>

int main(int argc, char* argv[])
{
    auto app = Gtk::Application::create();;

    std::string gladeFile = argv[1];
    auto gladeBuilder = Gtk::Builder::create();
    gladeBuilder->add_from_file(gladeFile);
    app->signal_startup().connect([&]
    {
         for(auto& object: gladeBuilder->get_objects())
         {
            auto widget = Glib::RefPtr<Gtk::Widget>::cast_dynamic(object);
            if(!widget)
                continue;
            auto style = widget->get_style_context();
            auto color = style->get_background_color();
            std::cout<<widget->get_name()<<" "<<color.to_string()<<std::endl;
        }
    });
    app->run();
  return 0;
}

output:

gtkmm__GtkButton rgb(73,62,57)

That is why all channels are changed to different values.

Comments