2021-09-07 15:21:54 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//
|
|
|
|
// EmulationStation Desktop Edition
|
|
|
|
// FlexboxComponent.h
|
|
|
|
//
|
|
|
|
// Flexbox layout component.
|
|
|
|
//
|
|
|
|
|
2021-09-27 20:18:19 +00:00
|
|
|
#ifndef ES_CORE_COMPONENTS_FLEXBOX_COMPONENT_H
|
|
|
|
#define ES_CORE_COMPONENTS_FLEXBOX_COMPONENT_H
|
2021-09-07 15:21:54 +00:00
|
|
|
|
|
|
|
#include "GuiComponent.h"
|
2021-10-11 19:28:37 +00:00
|
|
|
#include "components/ImageComponent.h"
|
2021-09-07 15:21:54 +00:00
|
|
|
|
|
|
|
class FlexboxComponent : public GuiComponent
|
|
|
|
{
|
|
|
|
public:
|
2021-10-13 16:18:23 +00:00
|
|
|
FlexboxComponent(Window* window, std::vector<std::pair<std::string, ImageComponent>>& images);
|
2021-09-13 23:01:46 +00:00
|
|
|
|
2021-10-12 20:53:02 +00:00
|
|
|
// Getters/setters for the layout.
|
2021-10-13 16:18:23 +00:00
|
|
|
std::string getDirection() const { return mDirection; }
|
2021-10-12 20:53:02 +00:00
|
|
|
void setDirection(const std::string& direction)
|
2021-10-02 19:58:04 +00:00
|
|
|
{
|
2021-10-12 20:53:02 +00:00
|
|
|
assert(direction == "row" || direction == "column");
|
|
|
|
mDirection = direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string getAlignment() const { return mAlignment; }
|
|
|
|
void setAlignment(const std::string& value)
|
|
|
|
{
|
|
|
|
assert(value == "left" || value == "right");
|
|
|
|
mAlignment = value;
|
2021-10-02 19:58:04 +00:00
|
|
|
mLayoutValid = false;
|
2021-10-11 19:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int getItemsPerLine() const { return mItemsPerLine; }
|
2021-10-02 19:58:04 +00:00
|
|
|
void setItemsPerLine(unsigned int value)
|
|
|
|
{
|
|
|
|
mItemsPerLine = value;
|
|
|
|
mLayoutValid = false;
|
2021-10-11 19:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int getLines() const { return mLines; }
|
2021-10-09 15:04:04 +00:00
|
|
|
void setLines(unsigned int value)
|
2021-10-02 19:58:04 +00:00
|
|
|
{
|
2021-10-09 15:04:04 +00:00
|
|
|
mLines = value;
|
2021-10-02 19:58:04 +00:00
|
|
|
mLayoutValid = false;
|
2021-10-11 19:28:37 +00:00
|
|
|
}
|
|
|
|
|
2021-10-12 20:53:02 +00:00
|
|
|
std::string getItemPlacement() const { return mItemPlacement; }
|
|
|
|
void setItemPlacement(const std::string& value)
|
|
|
|
{
|
|
|
|
assert(value == "start" || value == "center" || value == "end" || value == "stretch");
|
|
|
|
mItemPlacement = value;
|
|
|
|
mLayoutValid = false;
|
|
|
|
}
|
|
|
|
|
2021-10-11 19:28:37 +00:00
|
|
|
glm::vec2 getItemMargin() const { return mItemMargin; }
|
2021-10-09 15:04:04 +00:00
|
|
|
void setItemMargin(glm::vec2 value)
|
2021-10-02 19:58:04 +00:00
|
|
|
{
|
2021-10-12 20:53:02 +00:00
|
|
|
mItemMargin.x = std::roundf(value.x * Renderer::getScreenWidth());
|
|
|
|
mItemMargin.y = std::roundf(value.y * Renderer::getScreenHeight());
|
2021-10-02 19:58:04 +00:00
|
|
|
mLayoutValid = false;
|
2021-10-11 19:28:37 +00:00
|
|
|
}
|
2021-09-07 15:21:54 +00:00
|
|
|
|
2021-10-11 19:28:37 +00:00
|
|
|
void onSizeChanged() override { mLayoutValid = false; }
|
2021-09-13 23:01:46 +00:00
|
|
|
void render(const glm::mat4& parentTrans) override;
|
2021-09-07 15:21:54 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Calculate flexbox layout.
|
2021-09-13 23:01:46 +00:00
|
|
|
void computeLayout();
|
2021-09-07 15:21:54 +00:00
|
|
|
|
2021-10-11 19:28:37 +00:00
|
|
|
std::vector<std::pair<std::string, ImageComponent>>& mImages;
|
|
|
|
|
2021-10-12 20:53:02 +00:00
|
|
|
// Layout options.
|
|
|
|
std::string mDirection;
|
|
|
|
std::string mAlignment;
|
2021-09-13 23:01:46 +00:00
|
|
|
unsigned int mItemsPerLine;
|
2021-10-09 15:04:04 +00:00
|
|
|
unsigned int mLines;
|
2021-10-12 20:53:02 +00:00
|
|
|
std::string mItemPlacement;
|
2021-09-13 23:01:46 +00:00
|
|
|
glm::vec2 mItemMargin;
|
2021-10-12 20:53:02 +00:00
|
|
|
|
2021-09-23 22:05:32 +00:00
|
|
|
bool mLayoutValid;
|
2021-09-07 15:21:54 +00:00
|
|
|
};
|
|
|
|
|
2021-09-27 20:18:19 +00:00
|
|
|
#endif // ES_CORE_COMPONENTS_FLEXBOX_COMPONENT_H
|