Re: Using CSS Data from Within My Code
On Thursday, 12 September 2019 at 19:14:26 UTC, Ali Çehreli wrote: On 09/12/2019 02:54 AM, Ron Tarrant wrote: > I thought it was odd having 'q' in front of the opening curly brace... I think my index can be useful in such searches. Both q"" and q{} are there: http://ddili.org/ders/d.en/ix.html Ali Thanks, Ali. I suppose I should be looking in your book first when I have a question... as I so often do.
Re: Using CSS Data from Within My Code
On 09/12/2019 02:54 AM, Ron Tarrant wrote: > I thought it was odd having 'q' in front of the opening curly brace... I think my index can be useful in such searches. Both q"" and q{} are there: http://ddili.org/ders/d.en/ix.html Ali
Re: Using CSS Data from Within My Code
On Thursday, 12 September 2019 at 13:09:16 UTC, Mike Parker wrote: On Thursday, 12 September 2019 at 11:40:33 UTC, Ron Tarrant wrote: string myCSS = "tab { background-color: #f2f2f2; }"; enum will work just as well here and without the need for the variable: enum myCSS = "tab { background-color: #f2f2f2; }"; The original error was because q strings have to be valid D, not because of the enum. Ah! Thanks for clearing that up, Mike. My D knowledge is still rather sparse, so this fills in another blank for me.
Re: Using CSS Data from Within My Code
On Thursday, 12 September 2019 at 11:40:33 UTC, Ron Tarrant wrote: string myCSS = "tab { background-color: #f2f2f2; }"; enum will work just as well here and without the need for the variable: enum myCSS = "tab { background-color: #f2f2f2; }"; The original error was because q strings have to be valid D, not because of the enum.
Re: Using CSS Data from Within My Code
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.
Re: Using CSS Data from Within My Code
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());
Re: Using CSS Data from Within My Code
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
Re: Using CSS Data from Within My Code
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? q{} is a string that must only contain valid D tokens. D lexer does not like C directives. https://dlang.org/spec/lex.html#token_strings
Using CSS Data from Within My Code
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?