Skip to content
This repository has been archived by the owner on May 18, 2022. It is now read-only.

Refactor nannou_egui and add some basic docs #8

Merged
merged 3 commits into from Jul 14, 2021

Conversation

mitchmindtree
Copy link
Collaborator

@mitchmindtree mitchmindtree commented Jul 10, 2021

This refactor aims to clean up the nannou_egui code a little, and
provide a slightly more modular, cleaner interface (though for the most
part usage is almost identical other than some name changes).

One notable change is the use of RAII to "end the frame". The aim is to
avoid the situation where users forget to call end_frame, or
accidentally call end_frame on the inner CtxRef rather than
top-level API. begin_frame now returns a FrameCtx - a type that
derefs to a CtxRef and automatically calls end_frame and tesselates
graphics when it is dropped. Users can call FrameCtx::end if they wish
to end the frame before drop is invoked. Alternatively, they can just
call begin_frame within a block.

@AlexEne let me know your thoughts! I think I'll probably start using
this in a large downstream project soon.

This PR is based on #6, so it might be easier to review after merging that first.

Updates:
- `nannou` 0.16 -> 0.17.1
- `egui` 0.10 -> 0.13.1
- `egui_wgpu_backend` 0.6 -> 0.10

It looks like the latest version of the egui wgpu backend can now handle
MSAA other than 1. Closes AlexEne#3.

I also renamed the `EguiBackend` constructor from `new` to
`from_window`, as I think it might be worth adding some more
constructors e.g. for targeting non-window-frame textures, or
`from_app` where the default window is selected automatically, etc.

I'll likely do some more hacking on this today, I plan on trying to
solve AlexEne#4.
Currently multi-touch and the hyperlinks aren't working, but I think
both wouldn't be too tricky for someone to add in a follow-up PR. I also
haven't bothered tracking the CPU usage for the demo app yet, so it just
sits at `0`.

Otherwise everything else appears to work nicely!

Following this I plan to do some refactoring and add some docs, but I'll
get your thoughts on those changes on the next PR.
This refactor aims to clean up the `nannou_egui` code a little, and
provide a slightly more modular, cleaner interface (though for the most
part usage is almost identical other than some name changes).

One notable change is the use of RAII to "end the frame". The aim is to
avoid the situation where users forget to call `end_frame`, or
accidentally call `end_frame` on the inner `CtxRef` rather than
top-level API. `begin_frame` now returns a `FrameCtx` - a type that
derefs to a `CtxRef` and automatically calls `end_frame` and tesselates
graphics when it is dropped. Users can call `FrameCtx::end` if they wish
to end the frame before `drop` is invoked. Alternatively, they can just
call `begin_frame` within a block.

@AlexEne let me know your thoughts! I think I'll probably start using
this in a large downstream project soon.
mitchmindtree added a commit to mitchmindtree/nannou_egui that referenced this pull request Jul 14, 2021
Based on AlexEne#8 so might be easier to review after merging that.
@AlexEne AlexEne merged commit 414f6e3 into AlexEne:main Jul 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants