Re: GTKD - overrideBackgroundColor of Button doesn't work

2019-05-19 Thread Ron Tarrant via Digitalmars-d-learn

On Wednesday, 22 June 2016 at 07:57:01 UTC, TheDGuy wrote:
I am wondering if it is possible to get the name of the current 
CSS-class the button is asigned to?


Very late to this party, but:

getName() does the job.


Re: GTKD - overrideBackgroundColor of Button doesn't work

2016-06-22 Thread TheDGuy via Digitalmars-d-learn
I am wondering if it is possible to get the name of the current 
CSS-class the button is asigned to?


Re: GTKD - overrideBackgroundColor of Button doesn't work

2016-06-16 Thread TheDGuy via Digitalmars-d-learn

On Thursday, 16 June 2016 at 13:12:12 UTC, Gerald wrote:


It can be done fine with on the fly changes, i.e. random 
colors, it's somewhat more work then just calling a simple 
function call but CSS gives you a lot more power as well. I do 
this in Terminix where for certain themes I want to set the 
scrollbar background to be the same color as the terminal 
background.


Essentially, add a class to the widget and then construct the 
CSS for the class with your random background color as a 
string. Create a CSSProvider and use loadFromData, same as 
captaindet's example, to load the CSS in the string. Finally, 
use the widget's style context to add the CSS provider which 
you just constructed. If you want to change the color, remove 
that provider and add a new one.


Ahhh. Thas possible for sure, thanks alot!

I finally found the solution for my background-color problem: we 
have to remove the image first, so this works for me now:


#CssName{
background-image: none;
background-color:green;
color:green;
}


Re: GTKD - overrideBackgroundColor of Button doesn't work

2016-06-16 Thread Gerald via Digitalmars-d-learn

On Thursday, 16 June 2016 at 07:58:56 UTC, TheDGuy wrote:

On Wednesday, 15 June 2016 at 22:34:05 UTC, Gerald wrote:

snip...

The text color is green but the button background color is 
still default-gray!


I don't see an obvious issue with your code, I usually use CSS 
classes personally and I know that works fine because I use 
this technique all over terminix. I would suggest using the 
GTK Inspector to debug the CSS issue, it's an awesome tool for 
figuring out GTK CSS issues as it let's you change CSS on the 
fly, see what CSS is being applied to an object, etc. You can 
see how to use it at the link below:


https://wiki.gnome.org/Projects/GTK%2B/Inspector



Do you know if this works on windows?


No idea, I don't use Windows.




Personally I just add and remove classes as needed:

getStyleContext().addClass()
getStyleContext().removeClass()


So you basically have to create 2 classes? And what would you 
do if you would have to change the color randomly (for a simon 
says game)? I still think it is a bad idea to claim the way 
with function calls as deprecated but introducing a new system 
which is not as flexible (but maybe more powerfull).

C# with Visual Studio does it, PyQT does it: Function calls.


It can be done fine with on the fly changes, i.e. random colors, 
it's somewhat more work then just calling a simple function call 
but CSS gives you a lot more power as well. I do this in Terminix 
where for certain themes I want to set the scrollbar background 
to be the same color as the terminal background.


Essentially, add a class to the widget and then construct the CSS 
for the class with your random background color as a string. 
Create a CSSProvider and use loadFromData, same as captaindet's 
example, to load the CSS in the string. Finally, use the widget's 
style context to add the CSS provider which you just constructed. 
If you want to change the color, remove that provider and add a 
new one.


Re: GTKD - overrideBackgroundColor of Button doesn't work

2016-06-16 Thread TheDGuy via Digitalmars-d-learn

On Wednesday, 15 June 2016 at 22:34:05 UTC, Gerald wrote:

snip...

The text color is green but the button background color is 
still default-gray!


I don't see an obvious issue with your code, I usually use CSS 
classes personally and I know that works fine because I use 
this technique all over terminix. I would suggest using the GTK 
Inspector to debug the CSS issue, it's an awesome tool for 
figuring out GTK CSS issues as it let's you change CSS on the 
fly, see what CSS is being applied to an object, etc. You can 
see how to use it at the link below:


https://wiki.gnome.org/Projects/GTK%2B/Inspector



Do you know if this works on windows?


Personally I just add and remove classes as needed:

getStyleContext().addClass()
getStyleContext().removeClass()


So you basically have to create 2 classes? And what would you do 
if you would have to change the color randomly (for a simon says 
game)? I still think it is a bad idea to claim the way with 
function calls as deprecated but introducing a new system which 
is not as flexible (but maybe more powerfull).

C# with Visual Studio does it, PyQT does it: Function calls.



Re: GTKD - overrideBackgroundColor of Button doesn't work

2016-06-15 Thread Gerald via Digitalmars-d-learn

On Wednesday, 15 June 2016 at 21:39:37 UTC, TheDGuy wrote:

On Wednesday, 15 June 2016 at 20:49:02 UTC, Gerald wrote:

On Wednesday, 15 June 2016 at 09:03:45 UTC, TheDGuy wrote:

Hello,
why does this code not work?

RGBA rgb = new RGBA(1,0.5,0.5,1.0);
Button btn_1 = new Button("Start");
btn_1.overrideBackgroundColor(StateFlags.NORMAL, rgb);

The color of btn_1 just doesn't change.


https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-override-background-color




snip...

The text color is green but the button background color is 
still default-gray!


I don't see an obvious issue with your code, I usually use CSS 
classes personally and I know that works fine because I use this 
technique all over terminix. I would suggest using the GTK 
Inspector to debug the CSS issue, it's an awesome tool for 
figuring out GTK CSS issues as it let's you change CSS on the 
fly, see what CSS is being applied to an object, etc. You can see 
how to use it at the link below:


https://wiki.gnome.org/Projects/GTK%2B/Inspector


I am also wondering how it is possible to change the button 
color at runtime? In my opinion i don't think that CSS-based 
style has alot of advantages over the commonly used object 
functions.


Personally I just add and remove classes as needed:

getStyleContext().addClass()
getStyleContext().removeClass()


Re: GTKD - overrideBackgroundColor of Button doesn't work

2016-06-15 Thread captaindet via Digitalmars-d-learn

 string cssPath = "test.css";

 CssProvider provider = new CssProvider();
 provider.loadFromPath(cssPath);


unfortunately i don't know anything about yr specific problem.

but i just wanted to mention (in case you are not aware of it) that the 
CSS can be embedded into the D source. this is what i did to fix GTKs 
terrible design mistake for the background of Notebook:


```
enum myCSS = q{
GtkNotebook {
background-color: #e9e9e9;
}
GtkNotebook tab {
background-color: #d6d6d6;
}
};
...
int main(string[] args){
...
import gtk.CssProvider;
auto styleProvider = new CssProvider;
styleProvider.loadFromData(myCSS);
import gdk.Screen;
import gtk.StyleContext;
StyleContext.addProviderForScreen( Screen.getDefault(), 
styleProvider, 800);

```


Re: GTKD - overrideBackgroundColor of Button doesn't work

2016-06-15 Thread TheDGuy via Digitalmars-d-learn

On Wednesday, 15 June 2016 at 20:49:02 UTC, Gerald wrote:

On Wednesday, 15 June 2016 at 09:03:45 UTC, TheDGuy wrote:

Hello,
why does this code not work?

RGBA rgb = new RGBA(1,0.5,0.5,1.0);
Button btn_1 = new Button("Start");
btn_1.overrideBackgroundColor(StateFlags.NORMAL, rgb);

The color of btn_1 just doesn't change.


https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-override-background-color


Thanks for your reply, i now tried to use CSS instead:

import std.stdio;
import std.file;
import gtk.Main;
import gtk.MainWindow;
import gtk.CssProvider;
import gtk.Button;
import gdk.Display;
import gdk.Screen;
import gtk.StyleContext;

class Window : MainWindow{
this(int width, int height, string title){
super(title);
setDefaultSize(width, height);
Button btn = new Button("Test");
btn.setName("CssName");

string cssPath = "test.css";

CssProvider provider = new CssProvider();
provider.loadFromPath(cssPath);

Display display = Display.getDefault();
Screen screen = display.getDefaultScreen();
StyleContext.addProviderForScreen(screen, provider, 
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);


add(btn);
showAll();
}
}

void main(string[] args){
writeln(getcwd());
Main.init(args);
auto win = new Window(250,250,"Tutorial");
Main.run();
}

This is my CSS:
GtkWindow{
background-color:blue;
}
#CssName{
-GtkWidget-focus-line-width:0;
background-color:green;
color:green;
}

The text color is green but the button background color is still 
default-gray!
I am also wondering how it is possible to change the button color 
at runtime? In my opinion i don't think that CSS-based style has 
alot of advantages over the commonly used object functions.


Re: GTKD - overrideBackgroundColor of Button doesn't work

2016-06-15 Thread Gerald via Digitalmars-d-learn

On Wednesday, 15 June 2016 at 09:03:45 UTC, TheDGuy wrote:

Hello,
why does this code not work?

RGBA rgb = new RGBA(1,0.5,0.5,1.0);
Button btn_1 = new Button("Start");
btn_1.overrideBackgroundColor(StateFlags.NORMAL, rgb);

The color of btn_1 just doesn't change.


https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-override-background-color


GTKD - overrideBackgroundColor of Button doesn't work

2016-06-15 Thread TheDGuy via Digitalmars-d-learn

Hello,
why does this code not work?

RGBA rgb = new RGBA(1,0.5,0.5,1.0);
Button btn_1 = new Button("Start");
btn_1.overrideBackgroundColor(StateFlags.NORMAL, rgb);

The color of btn_1 just doesn't change.