2021-09-07 15:21:54 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//
|
|
|
|
// EmulationStation Desktop Edition
|
|
|
|
// FlexboxComponent.h
|
|
|
|
//
|
|
|
|
// Flexbox layout component.
|
|
|
|
// Used by gamelist views.
|
|
|
|
//
|
|
|
|
|
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-11 19:28:37 +00:00
|
|
|
enum class Direction : char {
|
|
|
|
row, // Replace with AllowShortEnumsOnASingleLine: false (clang-format >=11.0).
|
|
|
|
column
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class Align : char {
|
|
|
|
start, // Replace with AllowShortEnumsOnASingleLine: false (clang-format >=11.0).
|
|
|
|
end,
|
|
|
|
center,
|
|
|
|
stretch
|
|
|
|
};
|
2021-10-02 19:58:04 +00:00
|
|
|
|
2021-10-11 19:28:37 +00:00
|
|
|
explicit FlexboxComponent(Window* window,
|
|
|
|
std::vector<std::pair<std::string, ImageComponent>>& images);
|
2021-09-13 23:01:46 +00:00
|
|
|
|
|
|
|
// Getters/Setters for rendering options.
|
2021-10-11 19:28:37 +00:00
|
|
|
Align getAlign() const { return mAlign; }
|
2021-10-02 19:58:04 +00:00
|
|
|
void setAlign(Align value)
|
|
|
|
{
|
|
|
|
mAlign = value;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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-09 15:04:04 +00:00
|
|
|
mItemMargin = value;
|
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-10-02 20:00:54 +00:00
|
|
|
void applyTheme(const std::shared_ptr<ThemeData>& theme,
|
|
|
|
const std::string& view,
|
|
|
|
const std::string& element,
|
|
|
|
unsigned int properties) 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
|
|
|
// Layout options.
|
2021-10-02 19:58:04 +00:00
|
|
|
Direction mDirection;
|
|
|
|
Align mAlign;
|
2021-10-11 19:28:37 +00:00
|
|
|
|
|
|
|
std::vector<std::pair<std::string, ImageComponent>>& mImages;
|
|
|
|
|
2021-09-13 23:01:46 +00:00
|
|
|
unsigned int mItemsPerLine;
|
2021-10-09 15:04:04 +00:00
|
|
|
unsigned int mLines;
|
2021-10-11 19:28:37 +00:00
|
|
|
|
2021-09-13 23:01:46 +00:00
|
|
|
glm::vec2 mItemMargin;
|
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
|