MCPcopy Create free account
hub / github.com/SpartanJ/eepp / onKeyDown

Method onKeyDown

src/eepp/ui/uitreeview.cpp:584–769  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

582}
583
584Uint32 UITreeView::onKeyDown( const KeyEvent& event ) {
585 if ( event.getMod() & KEYMOD_CTRL_SHIFT_ALT_META )
586 return UIAbstractTableView::onKeyDown( event );
587 auto curIndex = getSelection().first();
588
589 if ( nullptr == getModel() || !getModel()->hasChildren() )
590 return UIAbstractTableView::onKeyDown( event );
591
592 switch ( event.getKeyCode() ) {
593 case KEY_PAGEUP: {
594 int pageSize = eefloor( getVisibleArea().getHeight() / getRowHeight() ) - 1;
595 std::deque<std::pair<ModelIndex, Float>> deque;
596 Float curY;
597 traverseTree(
598 [&]( const int&, const ModelIndex& index, const size_t&, const Float& offsetY ) {
599 deque.push_back( { index, offsetY } );
600 if ( (int)deque.size() > pageSize )
601 deque.pop_front();
602 if ( index == curIndex )
603 return IterationDecision::Break;
604 return IterationDecision::Continue;
605 } );
606 curY = deque.front().second - getHeaderHeight();
607 getSelection().set( deque.front().first );
608 scrollToPosition(
609 { { mScrollOffset.x, curY },
610 { columnData( deque.front().first.column() ).width, getRowHeight() } } );
611 return 1;
612 }
613 case KEY_PAGEDOWN: {
614 int pageSize = eefloor( getVisibleArea().getHeight() / getRowHeight() ) - 1;
615 int counted = 0;
616 bool foundStart = false;
617 bool resultFound = false;
618 ModelIndex foundIndex;
619 Float curY = 0;
620 Float lastOffsetY = 0;
621 ModelIndex lastIndex;
622 traverseTree(
623 [&]( const int&, const ModelIndex& index, const size_t&, const Float& offsetY ) {
624 if ( index == curIndex ) {
625 foundStart = true;
626 } else if ( foundStart ) {
627 counted++;
628 if ( counted == pageSize ) {
629 foundIndex = index;
630 curY = offsetY;
631 resultFound = true;
632 return IterationDecision::Break;
633 }
634 }
635 lastOffsetY = offsetY;
636 lastIndex = index;
637 return IterationDecision::Continue;
638 } );
639 if ( !resultFound ) {
640 foundIndex = lastIndex;
641 curY = lastOffsetY;

Callers

nothing calls this directly

Calls 15

onKeyDownFunction · 0.85
getSelectionFunction · 0.85
getModelFunction · 0.85
push_backMethod · 0.80
columnMethod · 0.80
hasChildrenMethod · 0.45
getHeightMethod · 0.45
sizeMethod · 0.45
setMethod · 0.45
isValidMethod · 0.45
setValueMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected