Writing PhysicsTweaker Interface

This commit is contained in:
2025-06-23 21:12:23 -05:00
parent bcd1c86318
commit 27349b2ee1
3 changed files with 50 additions and 1 deletions

View File

@@ -0,0 +1,2 @@
#pragma once

View File

@@ -2,14 +2,45 @@
#include <JUI/Widgets/Window.hpp>
#include "JUI/Widgets/LabeledSlider.hpp"
#include "JUI/Widgets/ListLayout.hpp"
namespace TestGame {
/// A window widget that displays physics variables as tunable sliders.
class PhysicsTweaker : public JUI::Window {
public:
Event<float> GravityChanged;
Event<float> AirResistanceChanged;
Event<float> MassChanged;
Event<float> AccelerationChanged;
Event<> PhysicsPaused;
Event<> PhysicsResumed;
Event<int> PhysicsStepped;
PhysicsTweaker() : JUI::Window() {
using namespace JUI::UDimLiterals;
this->Name("PhysicsTweaker");
this->Title("PhysicsParameters");
Size({300_px, 100_px});
Position({95_percent - 300_px, 95_percent - 200_px});
auto* layout = new JUI::VerticalListLayout(Content());
auto* grav_slider = new JUI::LabeledSlider(layout);
grav_slider->Minimum(0); grav_slider->Maximum(100);
}
explicit PhysicsTweaker(const JUI::Window& parent) : PhysicsTweaker() {
this->Parent(parent);
}
protected:
private:
};
}
}

View File

@@ -14,9 +14,25 @@
#include <TestGame/TestGameApp.hpp>
template <typename T>
struct Range {
T min;
T max;
};
template <typename T>
T map(T value, T in_min, T in_max, T out_min, T out_max) {
return (value - in_min) / (in_max - in_min) * (out_max - out_min) + out_min;
}
template <typename T>
T map(T value, const Range<T>& in, const Range<T>& out) {
return map(value, in.min, in.max, out.min, out.max);
}
int main()
{
ReWindow::Logger::Debug.EnableConsole(false);
TestGame::TestGameAppWindow* app = new TestGame::TestGameAppWindow();