Skip to content

Commit

Permalink
Scrolltabs with mouse wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
Freaxed committed Jan 30, 2025
1 parent 804cf68 commit 9592fd2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 41 additions & 1 deletion src/helpers/gtab/TabsContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,45 @@ TabsContainer::DoLayout()
_SelectTabOnTabView(selected);
fFirstLayout = false;
}

}


void
TabsContainer::MessageReceived(BMessage* message)
{
switch(message->what){
case B_MOUSE_WHEEL_CHANGED:
{
// No tabs, exit
if (fSelectedTab == nullptr)
break;

float deltaX = 0.0f;
float deltaY = 0.0f;
message->FindFloat("be:wheel_delta_x", &deltaX);
message->FindFloat("be:wheel_delta_y", &deltaY);

if (deltaX == 0.0f && deltaY == 0.0f)
return;

if (deltaY == 0.0f)
deltaY = deltaX;

int32 selection = IndexOfTab(fSelectedTab);
int32 numTabs = CountTabs();

if (deltaY > 0 && selection < numTabs - 1) {
// move to the right tab.
_SelectTabOnTabView(TabAt(selection + 1));

} else if (deltaY < 0 && selection > 0 && numTabs > 1) {
// move to the left tab.
_SelectTabOnTabView(TabAt(selection - 1));

}
break;
}
default:
BGroupView::MessageReceived(message);
};
}
2 changes: 2 additions & 0 deletions src/helpers/gtab/TabsContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class TabsContainer : public BGroupView, public BInvoker {

void DoLayout() override;

void MessageReceived(BMessage*) override;

private:
void _SelectTabOnTabView(GTab* tab);
void _PrintToStream();
Expand Down

0 comments on commit 9592fd2

Please sign in to comment.