-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
3,134 additions
and
2,821 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
libraries/ZWidget/include/zwidget/widgets/tabwidget/tabwidget.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
|
||
#pragma once | ||
|
||
#include "../../core/widget.h" | ||
#include <vector> | ||
#include <functional> | ||
#include <string> | ||
|
||
class TabBar; | ||
class TabBarTab; | ||
class TabWidgetStack; | ||
class TextLabel; | ||
class ImageBox; | ||
class Image; | ||
|
||
class TabWidget : public Widget | ||
{ | ||
public: | ||
TabWidget(Widget* parent); | ||
|
||
int AddTab(Widget* page, const std::string& label); | ||
int AddTab(Widget* page, const std::shared_ptr<Image>& icon, const std::string& label); | ||
|
||
void SetTabText(int index, const std::string& text); | ||
void SetTabText(Widget* page, const std::string& text); | ||
void SetTabIcon(int index, const std::shared_ptr<Image>& icon); | ||
void SetTabIcon(Widget* page, const std::shared_ptr<Image>& icon); | ||
|
||
int GetCurrentIndex() const; | ||
Widget* GetCurrentWidget() const; | ||
|
||
int GetPageIndex(Widget* pageWidget) const; | ||
|
||
void SetCurrentIndex(int pageIndex); | ||
void SetCurrentWidget(Widget* pageWidget); | ||
|
||
std::function<void()> OnCurrentChanged; | ||
|
||
protected: | ||
void OnPaintFrame(Canvas* canvas) override; | ||
void OnGeometryChanged() override; | ||
|
||
private: | ||
void OnBarCurrentChanged(); | ||
|
||
TabBar* Bar = nullptr; | ||
TabWidgetStack* PageStack = nullptr; | ||
std::vector<Widget*> Pages; | ||
}; | ||
|
||
class TabBar : public Widget | ||
{ | ||
public: | ||
TabBar(Widget* parent); | ||
|
||
int AddTab(const std::string& label); | ||
int AddTab(const std::shared_ptr<Image>& icon, const std::string& label); | ||
|
||
void SetTabText(int index, const std::string& text); | ||
void SetTabIcon(int index, const std::shared_ptr<Image>& icon); | ||
|
||
int GetCurrentIndex() const; | ||
void SetCurrentIndex(int pageIndex); | ||
|
||
double GetPreferredHeight() const { return 30.0; } | ||
|
||
std::function<void()> OnCurrentChanged; | ||
|
||
protected: | ||
void OnPaintFrame(Canvas* canvas) override; | ||
void OnGeometryChanged() override; | ||
|
||
private: | ||
void OnTabClicked(TabBarTab* tab); | ||
int GetTabIndex(TabBarTab* tab); | ||
|
||
int CurrentIndex = -1; | ||
std::vector<TabBarTab*> Tabs; | ||
}; | ||
|
||
class TabBarTab : public Widget | ||
{ | ||
public: | ||
TabBarTab(Widget* parent); | ||
|
||
void SetText(const std::string& text); | ||
void SetIcon(const std::shared_ptr<Image>& icon); | ||
void SetCurrent(bool value); | ||
|
||
double GetPreferredWidth() const; | ||
|
||
std::function<void()> OnClick; | ||
|
||
protected: | ||
void OnPaintFrame(Canvas* canvas) override; | ||
void OnGeometryChanged() override; | ||
bool OnMouseDown(const Point& pos, int key) override; | ||
bool OnMouseUp(const Point& pos, int key) override; | ||
void OnMouseMove(const Point& pos) override; | ||
void OnMouseLeave() override; | ||
|
||
private: | ||
bool IsCurrent = false; | ||
|
||
ImageBox* Icon = nullptr; | ||
TextLabel* Label = nullptr; | ||
bool hot = false; | ||
}; | ||
|
||
class TabWidgetStack : public Widget | ||
{ | ||
public: | ||
TabWidgetStack(Widget* parent); | ||
|
||
void SetCurrentWidget(Widget* widget); | ||
Widget* GetCurrentWidget() const { return CurrentWidget; } | ||
|
||
protected: | ||
void OnPaintFrame(Canvas* canvas) override; | ||
void OnGeometryChanged() override; | ||
|
||
private: | ||
Widget* CurrentWidget = nullptr; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.