Piano: Add Toggle parameter widget

This is for enum widgets; though positioning is not correct as
checkboxes need more options for text-less layout.
This commit is contained in:
kleines Filmröllchen 2022-07-23 15:37:22 +02:00 committed by Andreas Kling
parent d5166ddbcf
commit 6389384882
Notes: sideshowbarker 2024-07-17 08:35:52 +09:00

View file

@ -0,0 +1,39 @@
/*
* Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibCore/Object.h>
#include <LibDSP/ProcessorParameter.h>
#include <LibGUI/CheckBox.h>
#include <LibGUI/Widget.h>
class ProcessorParameterToggle : public GUI::CheckBox {
C_OBJECT(ProcessorParameterToggle)
public:
ProcessorParameterToggle(DSP::ProcessorBooleanParameter& parameter)
: CheckBox("")
, m_parameter(parameter)
{
on_checked = [this](auto checked) {
if (m_currently_setting_from_ui)
return;
m_currently_setting_from_ui = true;
m_parameter.set_value(checked);
m_currently_setting_from_ui = false;
};
m_parameter.register_change_listener([this](auto muted) {
set_checked(muted, GUI::AllowCallback::No);
});
set_checked(parameter.value());
}
private:
DSP::ProcessorBooleanParameter& m_parameter;
bool m_currently_setting_from_ui { false };
};