~eliasnaur/gio

2 2

Delayed InvalidateOp?

Details
Message ID
<CAFcc3FQwb5zRxn2EUjw+h9v8nwSwAkbN5H_K76k51LD=tLqu6w@mail.gmail.com>
DKIM signature
pass
Download raw message
So I was working on some animation code today for showing and hiding
tooltips, and I realized that I was having to constantly invalidate
the screen in order to handle "this tooltip should disappear after 1.5
seconds". That's a kinda irritating reason to invalide, as there isn't
even (necessarily) content changing between frames.

I could always schedule a window.Invalidate() call, but for that my
widget code has to have access to a window pointer or some kind of
system for performing that scheduling. It substantially complicates
the implementation of a very simple UI widget.

What are people's thoughts on having a variant of op.InvalidateOp{}
(or maybe just a field) that adds a delay to the invalidation? If I
know that I have an animation that should kick off in a second, I can
go ahead and issue the "invalidate in a second from now" operation and
then the UI can sleep until then (assuming a different widget doesn't
invalidate in the interim).

I expect that it's pretty trivial to coalesce multiple pending
invalidations, though I haven't yet attempted to prototype this.

What do you think? Is this generally useful? Is it a reasonable
feature request? Should I just bite the bullet and implement an
invalidate scheduler on top of the primitives that Gio already
provides instead of adding it to core?

Cheers,
Chris
Details
Message ID
<CANtNKfpa=9w0NikdWh+5QXKdV0Zm20wYigsgTO4ZTH3J7p3LOQ@mail.gmail.com>
In-Reply-To
<CAFcc3FQwb5zRxn2EUjw+h9v8nwSwAkbN5H_K76k51LD=tLqu6w@mail.gmail.com> (view parent)
DKIM signature
pass
Download raw message
I think `InvalidateOp{At: gtx.Now.Add(time.Second)}.Add(gtx.Ops)` should do it.

https://pkg.go.dev/gioui.org/op#InvalidateOp

+ Egon

On Fri, Apr 23, 2021 at 5:13 AM Chris Waldon
<christopher.waldon.dev@gmail.com> wrote:
>
> So I was working on some animation code today for showing and hiding
> tooltips, and I realized that I was having to constantly invalidate
> the screen in order to handle "this tooltip should disappear after 1.5
> seconds". That's a kinda irritating reason to invalide, as there isn't
> even (necessarily) content changing between frames.
>
> I could always schedule a window.Invalidate() call, but for that my
> widget code has to have access to a window pointer or some kind of
> system for performing that scheduling. It substantially complicates
> the implementation of a very simple UI widget.
>
> What are people's thoughts on having a variant of op.InvalidateOp{}
> (or maybe just a field) that adds a delay to the invalidation? If I
> know that I have an animation that should kick off in a second, I can
> go ahead and issue the "invalidate in a second from now" operation and
> then the UI can sleep until then (assuming a different widget doesn't
> invalidate in the interim).
>
> I expect that it's pretty trivial to coalesce multiple pending
> invalidations, though I haven't yet attempted to prototype this.
>
> What do you think? Is this generally useful? Is it a reasonable
> feature request? Should I just bite the bullet and implement an
> invalidate scheduler on top of the primitives that Gio already
> provides instead of adding it to core?
>
> Cheers,
> Chris
Details
Message ID
<CAFcc3FQ56+q1uORrc+x6PZ-PFgLbpdr=iNuxK1x4N-sea03fkg@mail.gmail.com>
In-Reply-To
<CANtNKfpa=9w0NikdWh+5QXKdV0Zm20wYigsgTO4ZTH3J7p3LOQ@mail.gmail.com> (view parent)
DKIM signature
pass
Download raw message
> I think `InvalidateOp{At: gtx.Now.Add(time.Second)}.Add(gtx.Ops)` should do it.
>
> https://pkg.go.dev/gioui.org/op#InvalidateOp

Somehow, I've never seen this field. :facepalm: Yes, it does exactly
what I'm talking about. Thank you! Clearly Elias already thought of
this. How embarrassing.

Well, PSA: InvalidateOp already has this feature. :D

Sorry for the ML noise.

Cheers,
Chris

> On Fri, Apr 23, 2021 at 5:13 AM Chris Waldon
> <christopher.waldon.dev@gmail.com> wrote:
> >
> > So I was working on some animation code today for showing and hiding
> > tooltips, and I realized that I was having to constantly invalidate
> > the screen in order to handle "this tooltip should disappear after 1.5
> > seconds". That's a kinda irritating reason to invalide, as there isn't
> > even (necessarily) content changing between frames.
> >
> > I could always schedule a window.Invalidate() call, but for that my
> > widget code has to have access to a window pointer or some kind of
> > system for performing that scheduling. It substantially complicates
> > the implementation of a very simple UI widget.
> >
> > What are people's thoughts on having a variant of op.InvalidateOp{}
> > (or maybe just a field) that adds a delay to the invalidation? If I
> > know that I have an animation that should kick off in a second, I can
> > go ahead and issue the "invalidate in a second from now" operation and
> > then the UI can sleep until then (assuming a different widget doesn't
> > invalidate in the interim).
> >
> > I expect that it's pretty trivial to coalesce multiple pending
> > invalidations, though I haven't yet attempted to prototype this.
> >
> > What do you think? Is this generally useful? Is it a reasonable
> > feature request? Should I just bite the bullet and implement an
> > invalidate scheduler on top of the primitives that Gio already
> > provides instead of adding it to core?
> >
> > Cheers,
> > Chris
Reply to thread Export thread (mbox)