VisualBuilder: Add some keyboard navigation support.

Allow selecting widgets using the Tab key, and moving them around
using the arrow keys. :^)
This commit is contained in:
Andreas Kling 2019-04-16 23:01:37 +02:00
parent ac324f14b8
commit f7157520eb
2 changed files with 45 additions and 0 deletions

View file

@ -105,6 +105,50 @@ void VBForm::grabber_mousedown_event(GMouseEvent& event, VBWidget& widget, Direc
m_resize_direction = grabber;
}
void VBForm::keydown_event(GKeyEvent& event)
{
if (event.key() == KeyCode::Key_Tab) {
if (!m_selected_widget && !m_widgets.is_empty()) {
m_selected_widget = m_widgets.first()->make_weak_ptr();
update();
return;
} else {
int selected_widget_index = 0;
for (; selected_widget_index < m_widgets.size(); ++selected_widget_index) {
if (m_widgets[selected_widget_index] == m_selected_widget)
break;
}
++selected_widget_index;
if (selected_widget_index == m_widgets.size())
selected_widget_index = 0;
m_selected_widget = m_widgets[selected_widget_index]->make_weak_ptr();
update();
return;
}
}
if (m_selected_widget) {
switch (event.key()) {
case KeyCode::Key_Up:
update();
m_selected_widget->gwidget()->move_by(0, -m_grid_size);
break;
case KeyCode::Key_Down:
update();
m_selected_widget->gwidget()->move_by(0, m_grid_size);
break;
case KeyCode::Key_Left:
update();
m_selected_widget->gwidget()->move_by(-m_grid_size, 0);
break;
case KeyCode::Key_Right:
update();
m_selected_widget->gwidget()->move_by(m_grid_size, 0);
break;
}
return;
}
}
void VBForm::mousedown_event(GMouseEvent& event)
{
if (m_selected_widget && m_resize_direction == Direction::None) {

View file

@ -31,6 +31,7 @@ protected:
virtual void mousedown_event(GMouseEvent&) override;
virtual void mousemove_event(GMouseEvent&) override;
virtual void mouseup_event(GMouseEvent&) override;
virtual void keydown_event(GKeyEvent&) override;
private:
void grabber_mousedown_event(GMouseEvent&, VBWidget&, Direction grabber);