Update to latest JGL & check if bounds is zero because that breaks *everything* to do with RenderTargets.
This commit is contained in:
2025-01-20 20:49:21 -05:00
parent 5293a845ad
commit c9a9c6aeb5
3 changed files with 10 additions and 8 deletions

View File

@@ -58,7 +58,7 @@ CPMAddPackage(
CPMAddPackage(
NAME JGL
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-46.zip
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-47.zip
)
target_include_directories(JUI PUBLIC ${Event_SOURCE_DIR}/include)

View File

@@ -116,7 +116,7 @@ namespace JUI
const Color4 &color);
protected:
RenderTarget* render_target;
RenderTarget* text_canvas;
std::string content = "Sample Text";
Color4 text_color = {255,255,255};
float text_outline = 1.f;

View File

@@ -48,6 +48,8 @@ namespace JUI {
float align_y = abs_pos.y;
auto bounds = this->GetFont().MeasureString(content, size);
if (bounds.x == 0 || bounds.y == 0)
return;
if (h_align == TextAlign::H::Left) {
// Render from left-side of boundary.
@@ -78,9 +80,9 @@ namespace JUI {
bool use_render_target = false;
if (content == this->content) {
// if Render Target needs updating.
if (Vector2(render_target->GetDimensions()) != bounds) {
render_target->Resize({(int) bounds.x, (int) bounds.y});
J2D::Begin(render_target, true);
if (Vector2(text_canvas->GetDimensions()) != bounds) {
text_canvas->Resize({(int) bounds.x, (int) bounds.y});
J2D::Begin(text_canvas, true);
J2D::DrawString(color, content, 0, 0, scale, size, this->set_font);
J2D::End();
}
@@ -90,7 +92,7 @@ namespace JUI {
Vector2 text_pos = {align_x, align_y};
J2D::Begin();
J2D::OutlineRect(color, text_pos, bounds);
use_render_target ? J2D::DrawRenderTarget(render_target, {align_x, align_y})
use_render_target ? J2D::DrawRenderTarget(text_canvas, {align_x, align_y})
: J2D::DrawString(color, content, align_x, align_y, scale, size, this->set_font);
J2D::End();
}
@@ -121,11 +123,11 @@ namespace JUI {
TextBase::TextBase() {
SetFont(JGL::Fonts::Jupiteroid);
render_target = new RenderTarget({1, 1}, {0, 0, 0, 0});
text_canvas = new RenderTarget({1, 1}, {0, 0, 0, 0});
}
TextBase::~TextBase() {
delete render_target;
delete text_canvas;
}
void TextBase::SetTextSize(u32 size) {
text_size = size;