Skip to content

Allow BreakLine to be included for any mod #1309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions loader/include/Geode/ui/BreakLine.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include <cocos2d.h>

namespace geode {
class GEODE_DLL BreakLine : public cocos2d::CCNode {
protected:
cocos2d::ccColor4F m_color;

void draw() override;
bool init(float width, float height, cocos2d::ccColor4F color);
public:
/**
* Create a break line to act as a separator
* @param width Width of the line
* @param height Height of the line
* @param color The color of the line
*/
static BreakLine* create(
float width,
float height = 1.f,
cocos2d::ccColor4F color = {1.f, 1.f, 1.f, .2f}
);
};
}
32 changes: 32 additions & 0 deletions loader/src/ui/nodes/BreakLine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <cocos2d.h>
#include <Geode/ui/BreakLine.hpp>

using namespace geode::prelude;

bool BreakLine::init(float width, float height, ccColor4F color) {
if (!CCNode::init())
return false;

this->setContentSize({ width, height });
m_color = color;

return true;
}

void BreakLine::draw() {
// some nodes sometimes set the blend func to
// something else without resetting it back
ccGLBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
ccDrawSolidRect({ 0, 0 }, this->getContentSize(), m_color);
CCNode::draw();
}

BreakLine* BreakLine::create(float width, float height, ccColor4F color) {
auto ret = new BreakLine;
if (ret->init(width, height, color)) {
ret->autorelease();
return ret;
}
delete ret;
return nullptr;
}
24 changes: 1 addition & 23 deletions loader/src/ui/nodes/MDTextArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <Geode/loader/Mod.hpp>
#include <Geode/loader/Loader.hpp>
#include <Geode/ui/MDTextArea.hpp>
#include <Geode/ui/BreakLine.hpp>
#include <Geode/utils/casts.hpp>
#include <Geode/utils/cocos.hpp>
#include <Geode/utils/web.hpp>
Expand Down Expand Up @@ -156,29 +157,6 @@ MDTextArea::~MDTextArea() {
CC_SAFE_RELEASE(m_renderer);
}

class BreakLine : public CCNode {
protected:
void draw() override {
// some nodes sometimes set the blend func to
// something else without resetting it back
ccGLBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
ccDrawSolidRect({ 0, 0 }, this->getContentSize(), { 1.f, 1.f, 1.f, .2f });
CCNode::draw();
}

public:
static BreakLine* create(float width) {
auto ret = new BreakLine;
if (ret->init()) {
ret->autorelease();
ret->setContentSize({ width, 1.f });
return ret;
}
delete ret;
return nullptr;
}
};

void MDTextArea::onLink(CCObject* pSender) {
auto href = as<CCString*>(as<CCNode*>(pSender)->getUserObject());
auto layer = FLAlertLayer::create(
Expand Down
Loading