Skip to content

text: fix ellipsizing, layouting, etc. - #121

Closed
vaxerski wants to merge 1 commit into
mainfrom
text-fixes
Closed

vaxerski wants to merge 1 commit into
mainfrom
text-fixes

Conversation

@vaxerski

Copy link
Copy Markdown
Member

adds some tests (codex) and fixes a bunch of repositioning issues with text, flip-flops, ellipsizing relayouting, etc. Codex-assisted.

@BlueZeeKing

BlueZeeKing commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor
#include <hyprtoolkit/core/Backend.hpp>
#include <hyprtoolkit/window/Window.hpp>
#include <hyprtoolkit/element/Text.hpp>

#include <hyprutils/memory/SharedPtr.hpp>
#include <hyprutils/memory/UniquePtr.hpp>

using namespace Hyprutils::Memory;
using namespace Hyprutils::Math;
using namespace Hyprtoolkit;

#define SP CSharedPointer
#define WP CWeakPointer
#define UP CUniquePointer

static SP<IBackend> backend;

int                 main(int argc, char** argv, char** envp) {
    backend = IBackend::create();

    auto window = CWindowBuilder::begin()->appTitle("Dialog")->appClass("hyprtoolkit-dialog")->commence();

    auto testText = CTextBuilder::begin()->text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")->noEllipsize(true)->commence();
    
    window->m_rootElement->addChild(testText);

    window->m_events.closeRequest.listenStatic([w = WP<IWindow>{window}] {
        w->close();
        backend->destroy();
    });

    window->open();

    backend->enterLoop();

    return 0;
}

results in the following:

image

when the text should wrap. I'm not sure how this is different from the working example in the controls test because that wraps correctly. The text in controls wraps for me even though it is set to ellipsize.

image

using namespace Hyprtoolkit;

static Vector2D childSizeForConstraint(const SP<IElement>& child, const Vector2D& constraint, const Vector2D& textConstraint) {
const auto CHILD_CONSTRAINT = dynamicPointerCast<CTextElement>(child) ? textConstraint : constraint;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think having a specific work around for one type of element is a good idea. Putting text inside a rectangle for a background or a border would break this.

for (const auto& child : impl->children) {
max.x = std::max(childSize(child).x, max.x);
max.y += childSize(child).y + m_impl->data.gap;
const auto CHILD_SIZE = childSizeForConstraint(child, parent, TEXT_CONSTRAINT);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should respect calc if it is defined, not just pass in parent.

for (const auto& child : impl->children) {
max.x = std::max(childSize(child).x, max.x);
max.y += childSize(child).y + m_impl->data.gap;
const auto CHILD_SIZE = childSizeForConstraint(child, parent, TEXT_CONSTRAINT);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing the parent means that percent children will grow to the full size of the parent, not the container (hence the fix in the spinbox). I think this behavior is helpful and should be kept.

+-------------------------+
| button |  two  | button |
|        | lines |        |
+-------------------------+

The center element is multi line text or some larger height element. And there are two buttons beside it (like a spinbox). There is no way for the side buttons to grow to be the same height as the center element without being able to set their height percent.

@UncleJ4ck

UncleJ4ck commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Heads up for whenever this merges: #158 fixes the link-region offset bug (#127) in this same file. It only changes how parseText computes STextLink::begin/end (displayed bytes instead of raw-markup bytes) and tightens the recheckTextBoxes loop to half-open. It doesn't touch the reposition/ellipsize paths this PR reworks, so the two should compose cleanly whichever lands first. Flagging it so the overlap in Text.cpp isn't a surprise at merge time.

@vaxerski vaxerski closed this Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants