SecondHalfGames / yakui

yakui is a declarative Rust UI library for games
Apache License 2.0
237 stars 21 forks source link

Make Widget methods take context objects #55

Closed LPGhatguy closed 2 years ago

LPGhatguy commented 2 years ago

We've had a recurring problem of widget methods not having access to specific state that would be useful. For example, it'd be nice to have access to the LayoutDom in Widget::event.

One good solution would be to refactor all of these methods to take a context type specific to the method: LayoutContext, PaintContext, and EventContext, which can hold references to the DOM, Layout DOM, Paint DOM, and more. This helps with the mutability concerns we had before and is also a convenient place to put methods that only make sense in these contexts.