Using CSS Data from Within My Code
Ron Tarrant
rontarrant at gmail.com
Thu Sep 12 11:40:33 UTC 2019
On Thursday, 12 September 2019 at 11:35:04 UTC, Ron Tarrant wrote:
> On Thursday, 12 September 2019 at 10:09:06 UTC, Andrea Fontana
> wrote:
>> On Thursday, 12 September 2019 at 09:54:35 UTC, Ron Tarrant
>> wrote:
>>> I found this presented as a solution in a 2016 post:
>>>
>>> On Wednesday, 15 June 2016 at 22:05:37 UTC, captaindet wrote:
>>>
>>>> enum myCSS = q{
>>>> GtkNotebook {
>>>> background-color: #e9e9e9;
>>>> }
>>>> GtkNotebook tab {
>>>> background-color: #d6d6d6;
>>>> }
>>>> };
>>>
>>> But when I try to use it, I get the following errors:
>>>
>>> Warning: C preprocessor directive #e9e9e9 is not supported
>>> Warning: C preprocessor directive #d6d6d6 is not supported
>>>
>>> I thought it was odd having 'q' in front of the opening curly
>>> brace... is this a typo? Shorthand for "string quote"?
>>> Something like that?
>>>
>>> Or do I need to escape these somehow?
>>
>> They are named "token string" and contained code must be a
>> valid d code. See https://dlang.org/spec/lex.html#token_strings
>
> Thanks, Andrea and Max.
>
> Turns out there's a simpler way to inject CSS into D code. In
> case anyone else comes looking, I found that instead of an
> enum, a string will do. Here's the solution I came up with to
> make visible tabs in a Notebook:
>
That should have been:
class CSS // GTK4 compliant
{
CssProvider provider;
string myCSS = "tab { background-color: #f2f2f2; }";
this(StyleContext styleContext)
{
provider = new CssProvider();
provider.loadFromData(myCSS);
styleContext.addProvider(provider,
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
} // this()
} // class CSS
The CSS path/file name isn't needed.
More information about the Digitalmars-d-learn
mailing list