Skip to content

Commit b5f2638

Browse files
authored
feat(ui): make BreakLine publicly available (#1309)
1 parent 9954af4 commit b5f2638

File tree

3 files changed

+58
-23
lines changed

3 files changed

+58
-23
lines changed

loader/include/Geode/ui/BreakLine.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
3+
#include <cocos2d.h>
4+
5+
namespace geode {
6+
class GEODE_DLL BreakLine : public cocos2d::CCNode {
7+
protected:
8+
cocos2d::ccColor4F m_color;
9+
10+
void draw() override;
11+
bool init(float width, float height, cocos2d::ccColor4F color);
12+
public:
13+
/**
14+
* Create a break line to act as a separator
15+
* @param width Width of the line
16+
* @param height Height of the line
17+
* @param color The color of the line
18+
*/
19+
static BreakLine* create(
20+
float width,
21+
float height = 1.f,
22+
cocos2d::ccColor4F color = {1.f, 1.f, 1.f, .2f}
23+
);
24+
};
25+
}

loader/src/ui/nodes/BreakLine.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <cocos2d.h>
2+
#include <Geode/ui/BreakLine.hpp>
3+
4+
using namespace geode::prelude;
5+
6+
bool BreakLine::init(float width, float height, ccColor4F color) {
7+
if (!CCNode::init())
8+
return false;
9+
10+
this->setContentSize({ width, height });
11+
m_color = color;
12+
13+
return true;
14+
}
15+
16+
void BreakLine::draw() {
17+
// some nodes sometimes set the blend func to
18+
// something else without resetting it back
19+
ccGLBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
20+
ccDrawSolidRect({ 0, 0 }, this->getContentSize(), m_color);
21+
CCNode::draw();
22+
}
23+
24+
BreakLine* BreakLine::create(float width, float height, ccColor4F color) {
25+
auto ret = new BreakLine;
26+
if (ret->init(width, height, color)) {
27+
ret->autorelease();
28+
return ret;
29+
}
30+
delete ret;
31+
return nullptr;
32+
}

loader/src/ui/nodes/MDTextArea.cpp

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <Geode/loader/Mod.hpp>
88
#include <Geode/loader/Loader.hpp>
99
#include <Geode/ui/MDTextArea.hpp>
10+
#include <Geode/ui/BreakLine.hpp>
1011
#include <Geode/utils/casts.hpp>
1112
#include <Geode/utils/cocos.hpp>
1213
#include <Geode/utils/web.hpp>
@@ -156,29 +157,6 @@ MDTextArea::~MDTextArea() {
156157
CC_SAFE_RELEASE(m_renderer);
157158
}
158159

159-
class BreakLine : public CCNode {
160-
protected:
161-
void draw() override {
162-
// some nodes sometimes set the blend func to
163-
// something else without resetting it back
164-
ccGLBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
165-
ccDrawSolidRect({ 0, 0 }, this->getContentSize(), { 1.f, 1.f, 1.f, .2f });
166-
CCNode::draw();
167-
}
168-
169-
public:
170-
static BreakLine* create(float width) {
171-
auto ret = new BreakLine;
172-
if (ret->init()) {
173-
ret->autorelease();
174-
ret->setContentSize({ width, 1.f });
175-
return ret;
176-
}
177-
delete ret;
178-
return nullptr;
179-
}
180-
};
181-
182160
void MDTextArea::onLink(CCObject* pSender) {
183161
auto href = as<CCString*>(as<CCNode*>(pSender)->getUserObject());
184162
auto layer = FLAlertLayer::create(

0 commit comments

Comments
 (0)