~whereswaldon/riga2023

f6b2a3887b541f31c5c8e5629240923d8eb49a52 — Chris Waldon 11 months ago 7108da5
todo-app: add trace regions to event loop

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
1 files changed, 24 insertions(+), 18 deletions(-)

M todo-app/main.go
M todo-app/main.go => todo-app/main.go +24 -18
@@ 173,24 173,30 @@ func (u *UI) Run() error {
			// we return to end the event loop.
			return ev.Err
		case system.FrameEvent:
			// If we get a frame event, it's time to display a new frame. First, we
			// build a layout context using our operation list and info from the frame
			// event.
			gtx := layout.NewContext(&ops, ev)
			// Install some global key event handlers for some dev hotkeys.
			u.hotkeys(gtx)
			// Then we lay out our UI to generate an operation list.
			u.page.Layout(gtx)
			// Then we give the operation list to Gio. This actually triggers rendering
			// our window.
			ev.Frame(gtx.Ops)
			// Trigger a sweep of our stream controller. Doing this once per frame allows
			// us to gracefully start and stop UI-driven streams of data from our backend
			// without manually managing their lifecycle. If we sweep twice and a given stream
			// was not used between them, we can conclude that it is not powering an active
			// portion of the UI and shut it down for now.
			// All that you really need to remember is that this must be called once per frame.
			u.controller.Sweep()
			trace.WithRegion(u.parentCtx, "frame", func() {
				// If we get a frame event, it's time to display a new frame. First, we
				// build a layout context using our operation list and info from the frame
				// event.
				gtx := layout.NewContext(&ops, ev)
				trace.WithRegion(u.parentCtx, "layout", func() {
					// Install some global key event handlers for some dev hotkeys.
					u.hotkeys(gtx)
					// Then we lay out our UI to generate an operation list.
					u.page.Layout(gtx)
				})
				trace.WithRegion(u.parentCtx, "render", func() {
					// Then we give the operation list to Gio. This actually triggers rendering
					// our window.
					ev.Frame(gtx.Ops)
				})
				// Trigger a sweep of our stream controller. Doing this once per frame allows
				// us to gracefully start and stop UI-driven streams of data from our backend
				// without manually managing their lifecycle. If we sweep twice and a given stream
				// was not used between them, we can conclude that it is not powering an active
				// portion of the UI and shut it down for now.
				// All that you really need to remember is that this must be called once per frame.
				u.controller.Sweep()
			})
		}
	}
	return nil