GTKD - CSS class color "flash" delay

Mike Wey via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 25 13:39:53 PDT 2016


On 06/25/2016 05:26 PM, TheDGuy wrote:
> On Saturday, 25 June 2016 at 13:01:09 UTC, TheDGuy wrote:
>> Thanks for your answer.
>> I have to pass the Button object to my timeout function to change the
>> CSS class. But how do i do that within the Timeout constructor?
>
> I mean:
>
> I have to pass my function and delay time to the constructor, but i
> can't pass any data to the function here, also only functions are
> allowed (at least it looks like that to me) who don't have parameters.
>
> If i want to add a new function i have to use the function .add(), with
> this function i can pass 'userData' (so my button for example). But why
> am i unable to do that in the constructor? Do i have 2 different
> functions for the same thing, one with the other one without parameter?
>
> My current approach:
>
>     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,5,false); //error
> appears here
>             t.add(5,&timeout_delay,currentButton);
>         }
>         foreach(Button btn;bArr){
>             btn.setSensitive(true);
>         }
>     }
>     bool timeout_delay(Button currentButton){
>         ListG list = currentButton.getStyleContext().listClasses();
>         string CSSClassName = to!string(cast(char*)list.next().data);
>         currentButton.getStyleContext().removeClass(CSSClassName ~
> "-flash");
>         return false;
>     }
>
> But i get the error:
> Error: none of the overloads of '__ctor' are callable using argument
> types (bool delegate(void* userData), int, bool), candidates are:
> glib.Timeout.Timeout.this(uint interval, bool delegate() dlg, bool
> fireNow = false)
> glib.Timeout.Timeout.this(uint interval, bool delegate() dlg, GPriority
> priority, bool fireNow = false)
> glib.Timeout.Timeout.this(bool delegate() dlg, uint seconds, bool
> fireNow = false)
> glib.Timeout.Timeout.this(bool delegate() dlg, uint seconds, GPriority
> priority, bool fireNow = false)
>
> If i take a look at GTK for C it looks like there is a function for that:
>
> http://www.gtk.org/tutorial1.2/gtk_tut-17.html
>
> Why is this so confusing?

The constructor accepts an delegate, witch can access it's context so it 
has access to some of the data.

The functions from GTK are also available like Timeout.add from the 
linked tutorial: http://api.gtkd.org/src/glib/Timeout.html#Timeout.add


You may want to do something like this:

```
private void letButtonsFlash()
{
     foreach(Button btn;bArr){
         btn.setSensitive(false);
     }

     Timeout t = new Timeout(&timeout_delay,5,false);
}

private bool timeout_delay()
{
     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");
     }

     return false;
}

```

-- 
Mike Wey


More information about the Digitalmars-d-learn mailing list