[bug] fix bugui/issues/8

This commit is contained in:
thibaud keller 2025-01-20 13:12:05 +00:00
parent 294e23cc9b
commit a6c770c4f8
5 changed files with 23 additions and 8 deletions

View file

@ -28,6 +28,11 @@ EventWidget::EventWidget(Scenario::EventModel& event,
static_cast<StateWidget*>(s.get())->set_y(); static_cast<StateWidget*>(s.get())->set_y();
} }
void EventWidget::set_y()
{
m_y = m_absolute_y - parent->y();
}
void EventWidget::set_span_recursive() void EventWidget::set_span_recursive()
{ {
int lowest{std::numeric_limits<int>::max()}; int lowest{std::numeric_limits<int>::max()};
@ -45,8 +50,6 @@ void EventWidget::set_span_recursive()
static_cast<TimeSyncWidget*>(bugui::base_widget::parent)->set_span(); static_cast<TimeSyncWidget*>(bugui::base_widget::parent)->set_span();
m_y = m_absolute_y - parent->y();
for(const auto& s : bugui::container_widget::children) for(const auto& s : bugui::container_widget::children)
static_cast<StateWidget*>(s.get())->set_y(); static_cast<StateWidget*>(s.get())->set_y();
} }

View file

@ -17,6 +17,7 @@ struct EventWidget final : Nano::Observer
int get_absolute_y() { return m_absolute_y; }; int get_absolute_y() { return m_absolute_y; };
int height() const override { return m_height; } int height() const override { return m_height; }
void set_y();
void set_span_recursive(); void set_span_recursive();
private: private:

View file

@ -31,8 +31,7 @@ bool IntervalWidget::contains(int px, int py) const
// ignore first and last cell // ignore first and last cell
// so that timesyncs are pressed // so that timesyncs are pressed
// at the extremeties // at the extremeties
if (px > 0 && px < width() && if (px > 0 && px < width() && py == 0)
py == 0)
return true; return true;
return false; return false;
@ -60,8 +59,12 @@ void IntervalWidget::on_double_press(int x, int y)
void IntervalWidget::on_drag(int from_x, int from_y, int to_x, int to_y) void IntervalWidget::on_drag(int from_x, int from_y, int to_x, int to_y)
{ {
double increment{to_y / static_cast<double>(scenario->height())}; double new_height{model.heightPercentage() +
model.requestHeightChange(model.heightPercentage() + increment); to_y / static_cast<double>(scenario->height())};
// prevent dragging out of scenario
if (new_height >= 0 && new_height <= 1)
model.setHeightPercentage(new_height);
} }
} // namespace hardware } // namespace hardware

View file

@ -53,8 +53,13 @@ void StateWidget::on_double_press(int x, int y)
void StateWidget::on_drag(int from_x, int from_y, int to_x, int to_y) void StateWidget::on_drag(int from_x, int from_y, int to_x, int to_y)
{ {
double increment{to_y / static_cast<double>(scenario->height())}; double new_height{model.heightPercentage() +
model.setHeightPercentage(model.heightPercentage() + increment); to_y / static_cast<double>(scenario->height())};
// prevent dragging out of scenario
if (new_height >= 0 && new_height <= 1)
model.setHeightPercentage(new_height);
} }
void StateWidget::set_absolute_y() void StateWidget::set_absolute_y()

View file

@ -79,6 +79,9 @@ void TimeSyncWidget::set_span()
m_y = lowest; m_y = lowest;
m_height = heighest - lowest; m_height = heighest - lowest;
for(const auto& e : bugui::container_widget::children)
static_cast<EventWidget*>(e.get())->set_y();
} }
void TimeSyncWidget::paint(bugui::painter& painter) const void TimeSyncWidget::paint(bugui::painter& painter) const