| 460 | } |
| 461 | |
| 462 | Optional<Point> SimpleTable::cellIndex(const Vec2& tablePos, const Vec2& pos) const noexcept |
| 463 | { |
| 464 | if (m_grid.isEmpty()) |
| 465 | { |
| 466 | return none; |
| 467 | } |
| 468 | |
| 469 | const RectF region{ this->region(tablePos) }; |
| 470 | |
| 471 | if (not region.intersects(pos)) |
| 472 | { |
| 473 | return none; |
| 474 | } |
| 475 | |
| 476 | const double x = (pos.x - tablePos.x + m_style.borderThickness / 2); |
| 477 | const double y = (pos.y - tablePos.y - m_style.borderThickness / 2); |
| 478 | const int64 xi = (std::lower_bound(m_columnAccumulatedWidths.values.begin(), m_columnAccumulatedWidths.values.end(), x) - m_columnAccumulatedWidths.values.begin()); |
| 479 | |
| 480 | const int32 column = Clamp(static_cast<int32>(xi - 1), 0, static_cast<int32>(m_grid.width() - 1)); |
| 481 | const int32 row = Clamp(static_cast<int32>(y / (m_style.cellHeight + m_style.borderThickness)), 0, static_cast<int32>(m_grid.height() - 1)); |
| 482 | |
| 483 | return Point{ column, row }; |
| 484 | } |
| 485 | |
| 486 | void SimpleTable::draw(const Vec2& tablePos) const |
| 487 | { |