5#include "fifechan/widgets/panel.hpp"
11#include "fifechan/font.hpp"
12#include "fifechan/graphics.hpp"
26 mVisibilityState = state;
31 return mVisibilityState;
36 mCollapsedWidth = width;
41 return mCollapsedWidth;
48 mVisibilityState = VisibilityState::Visible;
50 mVisibilityState = VisibilityState::Hidden;
57 if (mVisibilityState == VisibilityState::Collapsed) {
60 }
else if (mVisibilityState == VisibilityState::Hidden) {
91 if (mVisibilityState == VisibilityState::Collapsed) {
106 if (!mTitle.empty() &&
getFont() !=
nullptr) {
119 graphics->
drawText(mTitle, textX, textY);
126 int const closeY = (titleBarHeight - 12) / 2;
127 mCloseButtonBounds =
Rectangle(closeX, closeY, 12, 12);
131 mCloseButtonBounds.x,
132 mCloseButtonBounds.y,
133 mCloseButtonBounds.x + mCloseButtonBounds.width,
134 mCloseButtonBounds.y + mCloseButtonBounds.height);
136 mCloseButtonBounds.x,
137 mCloseButtonBounds.y + mCloseButtonBounds.height,
138 mCloseButtonBounds.x + mCloseButtonBounds.width,
139 mCloseButtonBounds.y);
148 if (mTitle.empty()) {
165 graphics->
drawText(mTitle, textX, textY);
170 int const closeY = (titleBarHeight - 12) / 2;
171 mCloseButtonBounds =
Rectangle(closeX, closeY, 12, 12);
175 mCloseButtonBounds.x,
176 mCloseButtonBounds.y,
177 mCloseButtonBounds.x + mCloseButtonBounds.width,
178 mCloseButtonBounds.y + mCloseButtonBounds.height);
180 mCloseButtonBounds.x,
181 mCloseButtonBounds.y + mCloseButtonBounds.height,
182 mCloseButtonBounds.x + mCloseButtonBounds.width,
183 mCloseButtonBounds.y);
193 if (mClosable && !mCloseButtonBounds.isEmpty()) {
194 int const x =
event.getX();
195 int const y =
event.getY();
197 if (x >= mCloseButtonBounds.x && x < mCloseButtonBounds.x + mCloseButtonBounds.width &&
198 y >= mCloseButtonBounds.y && y < mCloseButtonBounds.y + mCloseButtonBounds.height) {
205 if (event.
getY() > titleBarHeight) {
void draw(Graphics *graphics) override
Draws the widget.
virtual bool isOpaque() const
Checks if the container is opaque or not.
void adjustSize() override
Adjust the size of the container after layout computations.
Widget * getSource() const
Gets the source widget of the event.
virtual int getHeight() const =0
Gets the height of the glyphs in the font.
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
virtual void popClipArea()
Removes the top most clip area from the stack.
void drawText(std::string const &text, int x, int y)
Draws text with a default left alignment.
virtual bool pushClipArea(Rectangle area)
Pushes a clip area onto the stack.
virtual void setFont(Font *font)
Sets the font to use when drawing text.
virtual void drawLine(int x1, int y1, int x2, int y2)=0
Draws a line.
virtual void setColor(Color const &color)=0
Sets the color to use when drawing.
virtual void fillRectangle(Rectangle const &rectangle)=0
Draws a filled rectangle.
Represents a mouse event.
int getY() const
Gets the y coordinate of the mouse event.
virtual bool handleContentClick(MouseEvent &event)
Handles content area mouse clicks.
int getCollapsedWidth() const
Gets the collapsed width.
void setClosable(bool closable)
Sets whether the panel has a close button.
void draw(Graphics *graphics) override
Draws the panel content.
VisibilityState getVisibilityState() const
Gets the visibility state of the panel.
void setCollapsedWidth(int width)
Sets the width when the panel is collapsed.
void adjustSize() override
Adjusts the panel size based on its visibility state.
void setTitle(std::string const &title)
Sets the panel title.
void setVisibilityState(VisibilityState state)
Sets the visibility state of the panel.
bool isClosable() const
Checks if the panel has a close button.
void mousePressed(MouseEvent &event) override
std::string const & getTitle() const
Gets the panel title.
void setVisible(bool visible)
Sets whether the panel is visible.
Represents a rectangular area (X, Y, Width, Height).
Used replacement tokens by configure_file():
VisibilityState
Defines the visibility state of a Panel.