Fix prop tool not remembering settings in some cases

Namely, it would not write its settings to powder.pref if the property dropdown was changed with the up/down arrows.
This commit is contained in:
Tamás Bálint Misius 2023-10-21 22:43:09 +02:00
parent a9ffc8527c
commit 1c1ef12761
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2

View File

@ -27,6 +27,8 @@
class PropertyWindow: public ui::Window class PropertyWindow: public ui::Window
{ {
void HandlePropertyChange();
public: public:
ui::DropDown * property; ui::DropDown * property;
ui::Textbox * textField; ui::Textbox * textField;
@ -71,8 +73,7 @@ sim(sim_)
property = new ui::DropDown(ui::Point(8, 25), ui::Point(Size.X-16, 16)); property = new ui::DropDown(ui::Point(8, 25), ui::Point(Size.X-16, 16));
property->SetActionCallback({ [this] { property->SetActionCallback({ [this] {
FocusComponent(textField); HandlePropertyChange();
Update();
} }); } });
AddComponent(property); AddComponent(property);
for (int i = 0; i < int(properties.size()); i++) for (int i = 0; i < int(properties.size()); i++)
@ -97,6 +98,12 @@ sim(sim_)
MakeActiveWindow(); MakeActiveWindow();
} }
void PropertyWindow::HandlePropertyChange()
{
FocusComponent(textField);
Update();
}
void PropertyWindow::Update() void PropertyWindow::Update()
{ {
CheckProperty(); CheckProperty();
@ -267,9 +274,15 @@ void PropertyWindow::OnDraw()
void PropertyWindow::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) void PropertyWindow::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt)
{ {
if (key == SDLK_UP) if (key == SDLK_UP)
{
property->SetOption(property->GetOption().second-1); property->SetOption(property->GetOption().second-1);
HandlePropertyChange();
}
else if (key == SDLK_DOWN) else if (key == SDLK_DOWN)
{
property->SetOption(property->GetOption().second+1); property->SetOption(property->GetOption().second+1);
HandlePropertyChange();
}
} }
void PropertyTool::OpenWindow(Simulation *sim) void PropertyTool::OpenWindow(Simulation *sim)