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"
|
|
|
|
#include "renderers/Renderer.h"
|
|
|
|
|
2021-09-13 23:01:46 +00:00
|
|
|
// Default values.
|
2021-10-02 19:58:04 +00:00
|
|
|
#define DEFAULT_DIRECTION Direction::row
|
|
|
|
#define DEFAULT_ALIGN Align::center
|
2021-09-13 23:01:46 +00:00
|
|
|
#define DEFAULT_ITEMS_PER_LINE 4
|
2021-10-09 15:04:04 +00:00
|
|
|
#define DEFAULT_LINES 1
|
2021-09-13 23:01:46 +00:00
|
|
|
#define DEFAULT_MARGIN_X 10.0f
|
|
|
|
#define DEFAULT_MARGIN_Y 10.0f
|
2021-09-07 15:21:54 +00:00
|
|
|
|
|
|
|
class FlexboxComponent : public GuiComponent
|
|
|
|
{
|
|
|
|
public:
|
2021-10-02 19:58:04 +00:00
|
|
|
enum class Direction : char { row, column };
|
|
|
|
enum class Align : char { start, end, center, stretch };
|
|
|
|
|
|
|
|
explicit FlexboxComponent(Window* window);
|
2021-09-13 23:01:46 +00:00
|
|
|
|
|
|
|
// Getters/Setters for rendering options.
|
2021-10-02 19:58:04 +00:00
|
|
|
[[nodiscard]] Align getAlign() const { return mAlign; };
|
|
|
|
void setAlign(Align value)
|
|
|
|
{
|
|
|
|
mAlign = value;
|
|
|
|
mLayoutValid = false;
|
|
|
|
};
|
|
|
|
[[nodiscard]] unsigned int getItemsPerLine() const { return mItemsPerLine; };
|
|
|
|
void setItemsPerLine(unsigned int value)
|
|
|
|
{
|
|
|
|
mItemsPerLine = value;
|
|
|
|
mLayoutValid = false;
|
|
|
|
};
|
2021-10-09 15:04:04 +00:00
|
|
|
[[nodiscard]] unsigned int getLines() const { return mLines; };
|
|
|
|
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-09 15:04:04 +00:00
|
|
|
[[nodiscard]] glm::vec2 getItemMargin() const { return mItemMargin; };
|
|
|
|
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-09-07 15:21:54 +00:00
|
|
|
|
|
|
|
void onSizeChanged() override;
|
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;
|
|
|
|
std::vector<HelpPrompt> getHelpPrompts() 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-09-13 23:01:46 +00:00
|
|
|
// Rendering options.
|
2021-10-02 19:58:04 +00:00
|
|
|
Direction mDirection;
|
|
|
|
Align mAlign;
|
2021-09-13 23:01:46 +00:00
|
|
|
unsigned int mItemsPerLine;
|
2021-10-09 15:04:04 +00:00
|
|
|
unsigned int mLines;
|
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
|