> generally it depends. if it's an immediate mode gui, then you pass those 
> state variables every time you draw, and the internal system checks if 
> drawing is needed.

Figet's implementation roughly follows that. However, I also tied it into Nim's 
async event system which enables nicer integration with out-of-band events.

What I'd like to figure out is a nice API avoid having to explicitly pass 
around explicit state variables. In larger UI's you often end up 
wanting/needing to send events into unrelated modules. Plumbing variables 
requires tons of extra arguments being passed around. Though that's basically 
what React Redux does.

Here's a draft API I've come up with after some tinkering:
    
    
    # Trigger an animation on animatedProgress below
          Widget button:
            text: fmt"Clicked2: {self.count:4d}"
            onClick:
              self.count.inc()
              trigger("pb1") <- gotoValue(self.count*0.1)
          
          Widget animatedProgress:
            signals:
              "pbc1" = gotoValue(target: float32)
            delta: 0.1'f32
            setup: box 10.WPerc, 20, 80.WPerc, 2.Em
    
    
    Run

This would require a 
_[little](https://forum.nim-lang.org/postActivity.xml#little) magic where the 
`signals` macro would need to register some hidden state for the current node's 
scope. Though the macro could check that the signal is valid for the target 
widget though.

The `trigger("pb1")` macro would activate the event by storing it in the hidden 
state and calling `refresh`. It'd require 1-2 `refresh`'s (redraw in Fidget 
parlance) in the general case. What I'm unsure of implementation wise in this 
setup is how to avoid infinite refresh cycles.

Though thinking about this again, I'm wondering if a global event queue 
(Table?) might solve that. The struggle with that is keeping this event in the 
scope it's used in (e.g. we don't want every widget of a given type 
triggering). We also don't want widgets to care that the same name "pb1" was 
used in an unrelated widget.

ImGUI seems to handle this by requiring the programmer to set unique id's for 
widgets. Then it uses those id's to communicate out-of-band with widgets (e.g. 
to set their background color). It's easy to mess up and get weird 
interactions. 

Reply via email to