Using CSS Data from Within My Code
Ron Tarrant
rontarrant at gmail.com
Thu Sep 12 11:35:04 UTC 2019
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:
class CSS // GTK4 compliant
{
CssProvider provider;
string cssPath = "./css/visible_tabs.css";
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
And in the class that will use it, this line does it:
css = new CSS(getStyleContext());
More information about the Digitalmars-d-learn
mailing list