mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:38:11 +00:00
LibGUI: Allow scrolling through a ComboBox with the mouse wheel
This commit is contained in:
parent
18ff75e67b
commit
e064999e0d
4 changed files with 51 additions and 26 deletions
|
@ -35,9 +35,28 @@
|
|||
|
||||
namespace GUI {
|
||||
|
||||
class ComboBoxEditor final : public TextEditor {
|
||||
C_OBJECT(ComboBoxEditor);
|
||||
|
||||
public:
|
||||
Function<void(int delta)> on_mousewheel;
|
||||
|
||||
private:
|
||||
ComboBoxEditor()
|
||||
: TextEditor(TextEditor::SingleLine)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void mousewheel_event(MouseEvent& event) override
|
||||
{
|
||||
if (on_mousewheel)
|
||||
on_mousewheel(event.wheel_delta());
|
||||
}
|
||||
};
|
||||
|
||||
ComboBox::ComboBox()
|
||||
{
|
||||
m_editor = add<TextBox>();
|
||||
m_editor = add<ComboBoxEditor>();
|
||||
m_editor->on_change = [this] {
|
||||
if (on_change)
|
||||
on_change(m_editor->text(), m_list_view->selection().first());
|
||||
|
@ -74,6 +93,10 @@ ComboBox::ComboBox()
|
|||
on_change(m_editor->text(), index);
|
||||
});
|
||||
};
|
||||
|
||||
m_editor->on_mousewheel = [this](int delta) {
|
||||
m_list_view->move_selection(delta);
|
||||
};
|
||||
}
|
||||
|
||||
ComboBox::~ComboBox()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue