-
Notifications
You must be signed in to change notification settings - Fork 0
/
GTabView.cpp
113 lines (94 loc) · 2.52 KB
/
GTabView.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Copyright 2024, Andrea Anzani <andrea.anzani@gmail.com>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "GTabView.h"
#include "TabButtons.h"
#include "TabView.h"
#include "TabsContainer.h"
enum {
kLeftTabButton = 'GTlb',
kRightTabButton = 'GTrb',
kSelectedTabButton = 'GTse'
};
GTabView::GTabView() :
BGroupView(B_VERTICAL, 0.0f),
fScrollLeftTabButton(nullptr),
fTabsContainer(nullptr),
fScrollRightTabButton(nullptr),
fTabMenuTabButton(nullptr),
fCardView(nullptr)
{
_Init();
}
void
GTabView::AddTab(const char* label, BView* view)
{
fTabsContainer->AddTab(new TabView(label, fTabsContainer));
fCardView->AddChild(view);
}
void
GTabView::UpdateScrollButtons(bool left, bool right)
{
_SetButtonVisibility(fScrollLeftTabButton, left);
_SetButtonVisibility(fScrollRightTabButton, right);
}
void
GTabView::AttachedToWindow()
{
fScrollLeftTabButton->SetTarget(this);
fScrollRightTabButton->SetTarget(this);
fTabsContainer->SetTarget(this);
fTabMenuTabButton->SetTarget(this);
}
void
GTabView::MessageReceived(BMessage* message)
{
switch(message->what) {
case kLeftTabButton:
fTabsContainer->ShiftTabs(-1);
break;
case kRightTabButton:
fTabsContainer->ShiftTabs(+1);
break;
case kSelectedTabButton:
fCardView->CardLayout()->SetVisibleItem(message->GetInt32("index", 0));
break;
default:
BGroupView::MessageReceived(message);
};
}
void
GTabView::_Init()
{
fScrollLeftTabButton = new ScrollLeftTabButton(new BMessage(kLeftTabButton));
fScrollRightTabButton = new ScrollRightTabButton(new BMessage(kRightTabButton));
fTabsContainer = new TabsContainer(this, new BMessage(kSelectedTabButton));
fTabMenuTabButton = new TabMenuTabButton(nullptr);
fCardView = new BCardView("_cardview_");
BLayoutBuilder::Group<>(this, B_VERTICAL, 0.0f)
.AddGroup(B_HORIZONTAL, 0.0f)
.Add(fScrollLeftTabButton)
.Add(fTabsContainer)
.AddGroup(B_HORIZONTAL, 0.0f)
.Add(fScrollRightTabButton)
.Add(fTabMenuTabButton)
.SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT, B_ALIGN_VERTICAL_CENTER))
.End()
.SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_VERTICAL_UNSET))
.End()
.Add(fCardView)
//.Add(new BStringView("test", "text", B_WILL_DRAW))
.AddGlue(1)
;
fScrollLeftTabButton->Hide();
fScrollRightTabButton->Hide();
}
void
GTabView::_SetButtonVisibility(TabButton* button, bool newState)
{
if (newState == false && !button->IsHidden()){
button->Hide();
} else if (newState == true && button->IsHidden())
button->Show();
}