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-23 17:08:32 +00:00
|
|
|
#include "Window.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-23 17:08:32 +00:00
|
|
|
struct FlexboxItem {
|
|
|
|
// Optional label, mostly a convenience for the calling class to track items.
|
|
|
|
std::string label;
|
|
|
|
// Main image that governs grid sizing and placement.
|
|
|
|
ImageComponent baseImage{nullptr};
|
|
|
|
// Optional overlay image that can be sized and positioned relative to the base image.
|
|
|
|
ImageComponent overlayImage{nullptr};
|
|
|
|
bool visible = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
FlexboxComponent(Window* window, std::vector<FlexboxItem>& items);
|
2021-09-13 23:01:46 +00:00
|
|
|
|
2021-10-12 20:53:02 +00:00
|
|
|
// Getters/setters for the layout.
|
2021-11-09 21:40:08 +00:00
|
|
|
const 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;
|
|
|
|
}
|
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
const std::string& getAlignment() const { return mAlignment; }
|
2021-10-12 20:53:02 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-10-25 17:13:54 +00:00
|
|
|
unsigned int getLines() const { return mLines; }
|
|
|
|
void setLines(unsigned int value)
|
2021-10-02 19:58:04 +00:00
|
|
|
{
|
2021-10-25 17:13:54 +00:00
|
|
|
mLines = value;
|
2021-10-02 19:58:04 +00:00
|
|
|
mLayoutValid = false;
|
2021-10-11 19:28:37 +00:00
|
|
|
}
|
|
|
|
|
2021-10-25 17:13:54 +00:00
|
|
|
unsigned int getItemsPerLine() const { return mItemsPerLine; }
|
|
|
|
void setItemsPerLine(unsigned int value)
|
2021-10-02 19:58:04 +00:00
|
|
|
{
|
2021-10-25 17:13:54 +00:00
|
|
|
mItemsPerLine = value;
|
2021-10-02 19:58:04 +00:00
|
|
|
mLayoutValid = false;
|
2021-10-11 19:28:37 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
const std::string& getItemPlacement() const { return mItemPlacement; }
|
2021-10-12 20:53:02 +00:00
|
|
|
void setItemPlacement(const std::string& value)
|
|
|
|
{
|
|
|
|
assert(value == "start" || value == "center" || value == "end" || value == "stretch");
|
|
|
|
mItemPlacement = value;
|
|
|
|
mLayoutValid = false;
|
|
|
|
}
|
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
const glm::vec2& getItemMargin() const { return mItemMargin; }
|
2021-10-23 17:08:32 +00:00
|
|
|
void setItemMargin(glm::vec2 value);
|
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
const glm::vec2& getOverlayPosition() const { return mOverlayPosition; }
|
2021-10-23 17:08:32 +00:00
|
|
|
void setOverlayPosition(glm::vec2 position) { mOverlayPosition = position; }
|
|
|
|
|
|
|
|
float getOverlaySize() const { return mOverlaySize; }
|
|
|
|
void setOverlaySize(float size) { mOverlaySize = size; }
|
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-23 17:08:32 +00:00
|
|
|
std::vector<FlexboxItem>& mItems;
|
2021-10-11 19:28:37 +00:00
|
|
|
|
2021-10-12 20:53:02 +00:00
|
|
|
// Layout options.
|
|
|
|
std::string mDirection;
|
|
|
|
std::string mAlignment;
|
2021-10-09 15:04:04 +00:00
|
|
|
unsigned int mLines;
|
2021-10-25 17:13:54 +00:00
|
|
|
unsigned int mItemsPerLine;
|
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-10-23 17:08:32 +00:00
|
|
|
glm::vec2 mOverlayPosition;
|
|
|
|
float mOverlaySize;
|
|
|
|
|
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
|