Merge commit 'd9b2c00228' as 'libraries/ZWidget'
This commit is contained in:
commit
404123a22e
118 changed files with 26617 additions and 0 deletions
129
libraries/ZWidget/include/zwidget/widgets/tabwidget/tabwidget.h
Normal file
129
libraries/ZWidget/include/zwidget/widgets/tabwidget/tabwidget.h
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../../core/widget.h"
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class TabBar;
|
||||
class TabBarTab;
|
||||
class TabBarSpacer;
|
||||
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 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 OnGeometryChanged() override;
|
||||
|
||||
private:
|
||||
void OnTabClicked(TabBarTab* tab);
|
||||
int GetTabIndex(TabBarTab* tab);
|
||||
|
||||
int CurrentIndex = -1;
|
||||
std::vector<TabBarTab*> Tabs;
|
||||
TabBarSpacer* leftSpacer = nullptr;
|
||||
TabBarSpacer* rightSpacer = nullptr;
|
||||
};
|
||||
|
||||
class TabBarSpacer : public Widget
|
||||
{
|
||||
public:
|
||||
TabBarSpacer(Widget* parent);
|
||||
};
|
||||
|
||||
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 OnGeometryChanged() override;
|
||||
bool OnMouseDown(const Point& pos, InputKey key) override;
|
||||
bool OnMouseUp(const Point& pos, InputKey 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 OnGeometryChanged() override;
|
||||
|
||||
private:
|
||||
Widget* CurrentWidget = nullptr;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue