idanarye / woab

Widgets on Actors Bridge - a GUI microframework for combining GTK with Actix
https://crates.io/crates/woab
MIT License
14 stars 1 forks source link

Refactor the signal connection syntax #8

Closed idanarye closed 3 years ago

idanarye commented 3 years ago

With #4, my solution to #2 of adding a signals_inhibit method that fills an optional closure (79abc12336ce363ab2367b707d25ef35d69b909f) is no longer going to work, because the same builder utilizer can be used to generate multiple signal types for multiple actors - so we can no longer just have a single optional field with that closure. While this can be a new variation of connect_signals, we also have connect_signals_tagged so we'll need 4 variants, and as we add new features this is going to either grow exponentially or add many many arguments to that method. I like neither way - we need a better solution.

c.c. @piegamesde

idanarye commented 3 years ago

I would like to use a fluent interface, so maybe something like this:

ctx.signals::<MySignal>().tagged(my_tag).inhibit(|signal| match { ... }).connect();

Both tagged and inhibit are optional, of course.

Alternatively, I can use something like this:

ctx.connect_signals(MySignal::connector().tagged(...).inhibit(...));

The benefit here is that the connector object is the same, so if we want to support the fluent interface for building the actor - we can:

builder
    .actor() // might need to add ::<MyActor> here, but that's another story
    .connet_signals(MySignal::connector().tagged(...).inhibit(...))
    .make(MyActor {
        widgets: builder.widgets()
    });