diff --git a/sutk/include/sutk/Constants.hpp b/sutk/include/sutk/Constants.hpp index 8bcefd01..bd160bf6 100644 --- a/sutk/include/sutk/Constants.hpp +++ b/sutk/include/sutk/Constants.hpp @@ -38,7 +38,17 @@ namespace SUTK namespace Notebook { - static constexpr Color4 TabSelectColor { 0x749bafffu }; + namespace Tab + { + static constexpr Color4 SelectColor { 0x749bafffu }; + static constexpr f32 CloseButtonSize { 0.5f }; + static constexpr f32 LeftMargin { 0.2f }; + static constexpr f32 RightMargin { 0.2f }; + static constexpr f32 LabelCloseSpacing { }; + static constexpr f32 LabelMaxSize { 8 }; // 8 centimeters + static constexpr f32 LabelMinSize { 3 }; // 3 centimeters + static constexpr f32 Height { 0.8f }; // 0.8 centimeters + } } } } diff --git a/sutk/include/sutk/NotebookView.hpp b/sutk/include/sutk/NotebookView.hpp index 20706ba7..c87e7630 100644 --- a/sutk/include/sutk/NotebookView.hpp +++ b/sutk/include/sutk/NotebookView.hpp @@ -7,6 +7,7 @@ #include // for SUTK::Label::set() #include #include +#include // for SUTK::TabButtonGraphic #include // for com::CompareFunction #include // for com::Event @@ -56,17 +57,13 @@ namespace SUTK const std::string& getLabel() const noexcept; }; - class ImageButtonGraphic; - class DefaultButtonGraphic; class NotebookView; class SUTK_API TabView : public Button { friend class NotebookView; private: - DefaultButtonGraphic* m_graphic; - Button* m_closeButton; - ImageButtonGraphic* m_closeButtonGraphic; + TabButtonGraphic* m_graphic; // Preserve hover and press color of the m_graphic // Since we modify those when the tab is selected // we would need to restore them to their initial values @@ -74,9 +71,8 @@ namespace SUTK Color4 m_hoverColor; Color4 m_pressColor; Color4 m_idleColor; - static UIDriver::ImageReference s_closeIcon; - Button* getCloseButton() noexcept { return m_closeButton; } + Button* getCloseButton() noexcept { return m_graphic->getCloseButton(); } public: TabView(UIDriver& driver, Container* parent) noexcept; ~TabView() noexcept; diff --git a/sutk/include/sutk/TabButtonGraphic.hpp b/sutk/include/sutk/TabButtonGraphic.hpp new file mode 100644 index 00000000..75a76a29 --- /dev/null +++ b/sutk/include/sutk/TabButtonGraphic.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include // for SUTK::DefaultButtonGraphicNoLabel + +namespace SUTK +{ + class Label; + class ImageButtonGraphic; + class Button; + + class SUTK_API TabButtonGraphic : public DefaultButtonGraphicNoLabel + { + private: + Label* m_label; + Button* m_closeButton; + ImageButtonGraphic* m_closeButtonGraphic; + Color4 m_hoverColor; + Color4 m_pressColor; + Color4 m_idleColor; + static UIDriver::ImageReference s_closeIcon; + + public: + TabButtonGraphic(UIDriver& driver, Container* parent, GfxDriverObjectHandleType textGroup = GFX_DRIVER_OBJECT_NULL_HANDLE) noexcept; + virtual ~TabButtonGraphic() noexcept; + + // Overrides + virtual Vec2Df getMinBoundSize() noexcept override; + + Button* getCloseButton() noexcept { return m_closeButton; } + Label& getLabel() noexcept { return *m_label; } + + void selectedState() noexcept; + void unselectedState() noexcept; + }; +} diff --git a/sutk/source/NotebookView.cpp b/sutk/source/NotebookView.cpp index e7c89254..ae1b6a6b 100644 --- a/sutk/source/NotebookView.cpp +++ b/sutk/source/NotebookView.cpp @@ -4,20 +4,11 @@ #include #include #include // for SUTK::ImageButtonGraphic +#include // for SUTK::TabButtonGraphic #include // for SUTK::Panel #include #define TAB_VIEW_MIN_WIDTH 3.0f -#define TAB_BAR_HEIGHT 0.8f -#define TAB_LABEL_LEFT_MARGIN 0.2f -#define TAB_LABEL_TOP_MARGIN 0.2f -#define TAB_LABEL_BOTTOM_MARGIN 0.2f -#define TAB_LABEL_CLOSE_BUTTON_SPACING 0.1f -#define CLOSE_BUTTON_RIGHT_MARGIN 0.2f -#define CLOSE_BUTTON_WIDTH 0.5f -#define CLOSE_BUTTON_HEIGHT 0.5f - -#define TAB_VIEW_MIDDLE_SPREAD 0.1f #define TAB_VIEW_ANIM_START_WIDTH 0.0f #define DEFAULT_NEW_TAB_ANIM_DURATION 0.28f @@ -71,42 +62,21 @@ namespace SUTK onDeactivate(); } - UIDriver::ImageReference TabView::s_closeIcon = UIDriver::InvalidImage; - - TabView::TabView(UIDriver& driver, Container* parent) noexcept : Button(driver, parent, /* isCreateDefaultGraphic: */ true) + TabView::TabView(UIDriver& driver, Container* parent) noexcept : Button(driver, parent, /* isCreateDefaultGraphic: */ false) { - m_graphic = getGraphicAs(); - m_hoverColor = m_graphic->getHoverColor(); - m_pressColor = m_graphic->getPressColor(); - m_idleColor = m_graphic->getIdleColor(); - Label& label = m_graphic->getLabel(); - label.setAlignment(HorizontalAlignment::Left, VerticalAlignment::Middle); - label.fitInParent({ TAB_LABEL_LEFT_MARGIN, TAB_LABEL_CLOSE_BUTTON_SPACING + CLOSE_BUTTON_RIGHT_MARGIN + CLOSE_BUTTON_WIDTH, TAB_LABEL_TOP_MARGIN, TAB_LABEL_BOTTOM_MARGIN }); - m_graphic->getAnchorRect()->fitToParentRect(); - - m_closeButton = driver.createContainer