Refactor the ModelViewer to use PiGui #4849
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've re-implemented the ModelViewer in PiGui, using the GuiApplication class and the Input system to simplify a fair amount of the handling.
To accomplish this, I've done a fair amount of refactoring:
PiGui
is nowPiGui::Instance
, and all of the static drawing methods have been moved out of the class, opening up the possibility to add more C++-side widgets for both Lua and C++ to use.PiGui::Instance
is now only responsible for handling ImGui - all Lua-side initialization is handled byPiGUI::Lua::Init()
instead.PiGui::Instance
has its renderer dependency injected by its owner rather than relying onPi::renderer
. This actually reduced complexity a bit, because we no longer had to manually specify the SDL window every time we started an ImGui frame.Input
had its last ties toPi
removed, with the Config dependency injected by the owner, similarly to PiGui.KeyBindings::AxisBinding
andActionBinding
still depend on thePi::input
singleton variable, so there's an ugly hack in the ModelViewer to work around that. I'll address that in a later PR that refactors bindings (once again!).GuiApplication
now owns an Input instance and a PiGui instance, decoupling management of those two classes away fromPi.cpp
. It's not as automatic as I'd like, due to oldUI's issues with label drawing, but it's 90% of the way there.Input
now has methodsIsKeyPressed()
andIsKeyReleased()
to check whether a specific key was pressed or released during the current frame. This does come with some more runtime complexity, but the overall effect should be mostly negligible.Overall, this is a 1:1 replacement of the previous ModelViewer, with only one regression: the "snap view to direction" keybindings are not currently working because they're not being fed SDL_Events to trigger the
onPress
callbacks. This will also be resolved in a future Input PR, but is outside of the scope of this work.