[widgets] start handling drag
This commit is contained in:
parent
b0081c70de
commit
e52bd0b3c0
7 changed files with 37 additions and 1 deletions
2
Hardware/3rdparty/bugui
vendored
2
Hardware/3rdparty/bugui
vendored
|
@ -1 +1 @@
|
|||
Subproject commit d1cdce9329c01e98343d798adbe76c7df0013aec
|
||||
Subproject commit 92dbd6d9d49bd13e573fa644e71561c696423140
|
|
@ -40,6 +40,15 @@ bool Controller::on_double_press(int x, int y)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Controller::on_drag(int from_x, int from_y, int to_x, int to_y)
|
||||
{
|
||||
for (auto& w : widgets)
|
||||
if (w->on_drag(from_x, from_y, to_x, to_y))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Controller::on_play(bool pressed)
|
||||
{
|
||||
if (m_shift)
|
||||
|
|
|
@ -31,6 +31,7 @@ public:
|
|||
|
||||
bool on_press(int x, int y, bool pressed) override;
|
||||
bool on_double_press(int x, int y) override;
|
||||
bool on_drag(int from_x, int from_y, int to_x, int to_y) override;
|
||||
|
||||
private:
|
||||
Scenario::IntervalModel* interval;
|
||||
|
|
|
@ -62,6 +62,20 @@ bool IntervalWidget::on_double_press(int x, int y)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool IntervalWidget::on_drag(int from_x, int from_y, int to_x, int to_y)
|
||||
{
|
||||
if (!is_inside(from_x, from_y)) return false;
|
||||
|
||||
if (from_y != to_y)
|
||||
{
|
||||
double new_percentage{(1 / static_cast<double>(parent->height())) * to_y};
|
||||
model.requestHeightChange(new_percentage);
|
||||
parent->update();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const Scenario::IntervalModel &IntervalWidget::get_model() const
|
||||
{
|
||||
return model;
|
||||
|
|
|
@ -14,6 +14,7 @@ struct IntervalWidget final : bugui::base_widget
|
|||
void paint(bugui::painter& painter) const override;
|
||||
bool on_press(int x, int y, bool pressed) override;
|
||||
bool on_double_press(int x, int y) override;
|
||||
bool on_drag(int from_x, int from_y, int to_x, int to_y) override;
|
||||
|
||||
int x() const override;
|
||||
int y() const override;
|
||||
|
|
|
@ -44,6 +44,16 @@ bool ScenarioWidget::on_double_press(int x, int y)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ScenarioWidget::on_drag(int from_x, int from_y, int to_x, int to_y)
|
||||
{
|
||||
if (!is_inside(from_x, from_y)) return false;
|
||||
|
||||
for (auto& w : widgets)
|
||||
if (w->on_drag(from_x, from_y, to_x, to_y)) return true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int ScenarioWidget::x() const
|
||||
{
|
||||
return bugui::base_widget::parent->x();
|
||||
|
|
|
@ -20,6 +20,7 @@ public:
|
|||
void paint(bugui::painter& painter) const override;
|
||||
bool on_press(int x, int y, bool pressed) override;
|
||||
bool on_double_press(int x, int y) override;
|
||||
bool on_drag(int from_x, int from_y, int to_x, int to_y) override;
|
||||
|
||||
int x() const override;
|
||||
int y() const override;
|
||||
|
|
Loading…
Add table
Reference in a new issue