GTKD - CSS class color "flash" delay

Mike Wey via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 25 04:45:40 PDT 2016


On 06/24/2016 10:03 PM, TheDGuy wrote:
> On Friday, 24 June 2016 at 16:44:59 UTC, Gerald wrote:
>> Other then the obvious multi-threaded, using glib.Timeout to trigger
>> the reversion of the color change could be an option.
>>
>> http://api.gtkd.org/src/glib/Timeout.html
>
> Thanks! I tried this so far:
>     private void letButtonsFlash(){
>         foreach(Button btn;bArr){
>             btn.setSensitive(false);
>         }
>         for(int i = 0; i < level; i++){
>             Button currentButton = bArr[rndButtonBlink[i]];
>             ListG list = currentButton.getStyleContext().listClasses();
>             string CSSClassName = to!string(cast(char*)list.next().data);
>             currentButton.getStyleContext().addClass(CSSClassName ~
> "-flash");
>             writeln(CSSClassName);
>             Timeout t = new Timeout(&timeout_delay,1,true);
>             currentButton.getStyleContext().removeClass(CSSClassName ~
> "-flash");
>
>         }
>         foreach(Button btn;bArr){
>             btn.setSensitive(true);
>         }
>     }
>     bool timeout_delay(){
>         Thread.sleep(dur!("seconds")(5));
>         return false;
>     }
>
> and it is "working" to the extend that at least the CSSClassName gets
> written in the console but the UI again just pops up after 5 sec. Could
> you give me a tip?


You should change the css class in the timeout_delay function.

It's called by the GTK main loop every time the amount of seconds passed 
to the constructor has passed. And return true if you want to continue 
to flash the button, and false to stop.

Also don't sleep in the timeout function, the main loop should take care 
of that, currently you are blocking the main thread for 5 seconds.

-- 
Mike Wey


More information about the Digitalmars-d-learn mailing list