KKGLinearLayout.h
2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// KKGLinearLayout.h
// SteveAndMaggieWorld
//
// Created by Katarzyna Kalinowska-Górska on 03/12/2020.
//
#ifndef KKGLinearLayout_h
#define KKGLinearLayout_h
#include "cocos2d.h"
class KKGLinearLayout : public cocos2d::Node {
public:
enum LayoutType {
HORIZONTAL,
VERTICAL
};
// Alignment in the horizontal or vertical axis - the main one, chosen in LayoutType
typedef enum Alignment : int {
ASTART = 0,
ACENTER = 1,
AEND = 2
} Alignment;
// Alignment in the cross axis
typedef enum Gravity : int {
GSTART = 0,
GCENTER = 1,
GEND = 2
} Gravity;
static KKGLinearLayout* create(LayoutType type, Alignment alignment, Gravity gravity);
virtual bool init(LayoutType type, Alignment alignment, Gravity gravity);
virtual void setInterViewMargin(float margin, bool immediatelyRelayout = true);
float getInterViewMargin();
virtual void addViews(std::vector<cocos2d::Node*> views, bool immediatelyRelayout = true);
virtual void setLayoutContentSize(const cocos2d::Size & var, bool immediatelyRelayout = true);
const cocos2d::Size& getLayoutContentSize() const;
virtual void addView(cocos2d::Node * view, bool immediatelyRelayout = true);
virtual void substituteViewAtIndex(int index, cocos2d::Node * newView);
virtual void setBackgroundColor(const cocos2d::Color4B& bgColor);
cocos2d::Vector<cocos2d::Node*> getViews();
cocos2d::Node* getView(int index);
bool hasViews();
// void removeViewAtIndex(int index, bool relayout = true);
void removeAllViews(bool relayout);
void removeLastView(bool relayout = true);
void wrapContents();
virtual void layoutViews();
virtual void setCascadeOpacityEnabled(bool cascadeOpacityEnabled) override;
protected:
LayoutType m_type { HORIZONTAL };
Alignment m_alignment { ASTART };
Gravity m_gravity { GCENTER };
float m_interChildMargin { 0 };
cocos2d::Point m_internalContainerAnchorPoint;
cocos2d::LayerColor* m_backgroundNode {nullptr}; //TODO I might want to create a superclass node with some stuff like bg
cocos2d::Node* m_internalContainer { nullptr };
virtual void prepareInternalContainer();
virtual void adjustBackground(const cocos2d::Size& contentSize);
};
#endif /* KKGLinearLayout_h */