MCPcopy Create free account
hub / github.com/Siv3D/OpenSiv3D / cellIndex

Method cellIndex

Siv3D/src/Siv3D/SimpleTable/SivSimpleTable.cpp:462–484  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls 8

regionMethod · 0.95
ClampFunction · 0.50
isEmptyMethod · 0.45
intersectsMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected