launcher: add custom button and spacer plugin config options

This commit is contained in:
somewhatlurker
2019-08-30 00:16:35 +10:00
parent f5989b74ac
commit b70fd18dd3
5 changed files with 119 additions and 2 deletions
@@ -231,6 +231,22 @@ public:
}
};
ref class CustomFuncHandler
{
public:
void(*_func)();
CustomFuncHandler(void(*func)())
{
_func = func;
}
System::Void RunFunc(System::Object^ sender, System::EventArgs^ e)
{
_func();
}
};
class ConfigOptionBase
{
@@ -276,6 +292,22 @@ public:
}
};
class OptionMetaSpacer : public ConfigOptionBase
{
public:
int _height;
OptionMetaSpacer(int height)
{
_height = height;
}
virtual int AddToPanel(Panel^ panel, unsigned int left, unsigned int top, ToolTip^ tooltip)
{
return _height;
}
};
class BooleanOption : public ConfigOptionBase
{
@@ -945,6 +977,52 @@ public:
};
class ButtonOption : public ConfigOptionBase
{
public:
void(*_func)();
ButtonOption(LPCWSTR friendlyName, LPCWSTR description, void(*func)())
{
_friendlyName = friendlyName;
_description = description;
_func = func;
}
virtual int AddToPanel(Panel^ panel, unsigned int left, unsigned int top, ToolTip^ tooltip)
{
Button^ button = gcnew Button();
button->Text = gcnew String(_friendlyName);
button->Left = left;
button->Top = top;
button->AutoSize = true;
button->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
Form^ RootForm = panel->FindForm();
float ScaleWidth = 1.0f;
float ScaleHeight = 1.0f;
if (RootForm)
{
Drawing::SizeF CurrentScaleSize = RootForm->CurrentAutoScaleDimensions;
ScaleWidth = CurrentScaleSize.Width / BaseScaleSize;
ScaleHeight = CurrentScaleSize.Height / BaseScaleSize;
}
button->Scale(ScaleWidth, ScaleHeight);
tooltip->SetToolTip(button, gcnew String(_description));
CustomFuncHandler^ funchandler = gcnew CustomFuncHandler(_func);
button->Click += gcnew System::EventHandler(funchandler, &CustomFuncHandler::RunFunc);
panel->Controls->Add(button);
int ControlHeight = button->Height / ScaleHeight;
return ControlHeight + ControlSpacing;
}
};
class PluginOption : public ConfigOptionBase
{
public: