Canvas interactivity and Game of Life example#325
Conversation
6e9584e to
f2e63f1
Compare
f2e63f1 to
0a5f1bb
Compare
|
@clarkmoody I have implemented cursor-based zooming and increased the speed limit to
The lag is somewhat expected as the
If the tick rate is higher than the refresh rate of your monitor, there are states of the simulation you will not see. New cells will also immediately die after drawing them, given the rules of the game. |
|
Excellent! Tested and works at e7e8e76 |
This seems to produce a 2x speedup.
Also allow toggling the grid lines
|
I have made the simulation run in a background thread and also implemented some logic to avoid ticks from accumulating. The GUI now will stay responsive even if the simulation cannot keep up with the requested tick rate! Additionally, I have:
I am pretty happy with this example and I believe we are ready to merge! 🎉 |
This PR adds interactivity support for the
Canvaswidget and simplifies its API.A
Canvasis now created with a value implementing the newProgramtrait. AProgramcontains the local state of theCanvas, describes itsupdateanddrawlogic, and can produce meaningful messages.The
LayerandDrawabletraits have been removed as they added an unnecessary level of indirection to the drawing API. Drawing now consists in directly generating a bunch ofGeometrywith aFrameorCachein theProgram::drawmethod. Users should be able to create any further drawing abstractions on top of this API to satisfy specific use cases.The changes to the canvas API triggered a bunch of refactors and internal improvements, affecting a considerable part of the codebase. Specifically:
Rectangle,Point,Vector, andStroke.mousetypes oficed_nativehave been moved toiced_core.Translatewas added toiced_wgpu.Mesh2Dprimitive has now asizefield and any geometry that falls out of bounds is clipped.MouseCursorhas been renamed tomouse::Interactionwith a newCrosshairvariant.Inputvariant inkeyboard::Eventandmouse::Eventhas been split into explicit pressed and released variants.timemodule has been created, which is only exposed when either thetokioorasync-stdfeatures are enabled. This module currently only exposes aneveryfunction that returns aSubscriptionthat produces messages at a set interval. This simplifies some examples considerably!bezier_toolexample has been updated to also use aCanvaswidget instead of a custom one.As always, I have implemented a new example to showcase the new features. The new
game_of_lifeexample implements an interactive version of Conway's Game of Life on top of the new canvas API!