Skip to content

Commit

Permalink
fixed selection corner case and added dragzone on cardview
Browse files Browse the repository at this point in the history
  • Loading branch information
Freaxed committed Feb 4, 2025
1 parent 192623f commit fb32889
Showing 1 changed file with 40 additions and 5 deletions.
45 changes: 40 additions & 5 deletions src/helpers/gtab/GTabView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,36 @@ enum {

};

class CardViewDropZone : public BCardView, public GTabDropZone {
public:
CardViewDropZone(TabsContainer *tabsContainer) : BCardView("_cardview_") {
SetContainer(tabsContainer);
SetFlags(Flags() | B_WILL_DRAW);
}
void Draw(BRect rect) override {
BCardView::Draw(rect);
DropZoneDraw(this, rect);
}

void MouseUp(BPoint where) override {
DropZoneMouseUp(this, where);
}

void MessageReceived(BMessage *message) override {
if (DropZoneMessageReceived(message) == false)
BCardView::MessageReceived(message);
}

void MouseMoved(BPoint where, uint32 transit,
const BMessage *dragMessage) override {
DropZoneMouseMoved(this, where, transit, dragMessage);
}

void OnDropMessage(BMessage *message) override {
Container()->OnDropTab(nullptr, message);
}
};

GTabView::GTabView(const char* name,
tab_affinity affinity,
orientation content_orientation,
Expand Down Expand Up @@ -55,9 +85,11 @@ GTabView::AddTab(GTab* tab, BView* view, int32 index)
if (index == -1 || index > Container()->CountTabs())
index = Container()->CountTabs();

fTabsContainer->AddTab(tab, index);
_AddViewToCard(view, index);
_FixContentOrientation(view);

fTabsContainer->AddTab(tab, index);

OnTabAdded(tab, view);
}

Expand Down Expand Up @@ -213,7 +245,7 @@ GTabView::_Init(tab_affinity affinity)

fTabMenuTabButton = new GTabMenuTabButton(new BMessage(kMenuTabButton));

fCardView = new BCardView("_cardview_");
fCardView = new CardViewDropZone(fTabsContainer);

BLayoutBuilder::Group<>(this, B_VERTICAL, 0.0f)
.AddGroup(B_HORIZONTAL, 0.0f)
Expand Down Expand Up @@ -303,11 +335,12 @@ void
GTabView::SelectTab(GTab* tab)
{
int32 index = fTabsContainer->IndexOfTab(tab);
if (index > -1) {
fTabsContainer->SetFrontTab(tab);
if (index > -1 && index < fTabsContainer->CountTabs()) {
fCardView->CardLayout()->SetVisibleItem(index);
OnTabSelected(tab);
}

fTabsContainer->SetFrontTab(tab);
OnTabSelected(tab);
}


Expand All @@ -323,3 +356,5 @@ GTabView::CreateTabView(GTab* clone)
{
return CreateTabView(clone->Label());
}


0 comments on commit fb32889

Please sign in to comment.