Repository navigation
text: fix ellipsizing, layouting, etc. #121
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,9 +8,19 @@ | |
|
|
||
| #include "../Element.hpp" | ||
| #include "../LinearLayout.hpp" | ||
| #include "../text/Text.hpp" | ||
|
|
||
| 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; | ||
| if (const auto PREFERRED = child->preferredSize(CHILD_CONSTRAINT)) | ||
| return *PREFERRED; | ||
| if (const auto MINIMUM = child->minimumSize(CHILD_CONSTRAINT)) | ||
| return *MINIMUM; | ||
| return {-1, -1}; | ||
| } | ||
|
|
||
| SP<CColumnLayoutElement> CColumnLayoutElement::create(const SColumnLayoutData& data) { | ||
| auto p = SP<CColumnLayoutElement>(new CColumnLayoutElement(data)); | ||
| p->impl->self = p; | ||
|
|
@@ -51,11 +61,8 @@ Hyprutils::Math::Vector2D CColumnLayoutElement::size() { | |
| } | ||
|
|
||
| Hyprutils::Math::Vector2D CColumnLayoutElement::childSize(Hyprutils::Memory::CSharedPointer<IElement> child) { | ||
| if (child->preferredSize(impl->position.size())) | ||
| return *child->preferredSize(impl->position.size()); | ||
| else if (child->minimumSize(impl->position.size())) | ||
| return *child->minimumSize(impl->position.size()); | ||
| return {-1, -1}; | ||
| const auto CONSTRAINT = impl->position.size(); | ||
| return childSizeForConstraint(child, CONSTRAINT, {CONSTRAINT.x, -1.F}); | ||
| } | ||
|
|
||
| std::optional<Hyprutils::Math::Vector2D> CColumnLayoutElement::preferredSize(const Hyprutils::Math::Vector2D& parent) { | ||
|
|
@@ -64,10 +71,12 @@ std::optional<Hyprutils::Math::Vector2D> CColumnLayoutElement::preferredSize(con | |
| if (calc.x != -1 && calc.y != -1) | ||
| return calc; | ||
|
|
||
| Vector2D max; | ||
| const Vector2D TEXT_CONSTRAINT{calc.x > 0 ? std::max(1.0, calc.x - impl->margin * 2.F) : -1.F, -1.F}; | ||
| Vector2D max; | ||
| 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should respect
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. 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. |
||
| max.x = std::max(CHILD_SIZE.x, max.x); | ||
| max.y += CHILD_SIZE.y + m_impl->data.gap; | ||
| } | ||
|
|
||
| if (!impl->children.empty()) | ||
|
|
@@ -88,9 +97,12 @@ std::optional<Hyprutils::Math::Vector2D> CColumnLayoutElement::preferredSize(con | |
| } | ||
|
|
||
| std::optional<Hyprutils::Math::Vector2D> CColumnLayoutElement::minimumSize(const Hyprutils::Math::Vector2D& parent) { | ||
| Vector2D min; | ||
| const auto CALC = m_impl->data.size.calculate(parent); | ||
| const Vector2D TEXT_CONSTRAINT = {CALC.x > 0 ? std::max(1.0, CALC.x - impl->margin * 2.F) : -1.F, -1.F}; | ||
| Vector2D min; | ||
| for (const auto& child : impl->children) { | ||
| min.x = std::max(min.x, childSize(child).x); | ||
| const auto CHILD_SIZE = childSizeForConstraint(child, parent, TEXT_CONSTRAINT); | ||
| min.x = std::max(min.x, CHILD_SIZE.x); | ||
| } | ||
|
|
||
| return min; | ||
|
|
||
There was a problem hiding this comment.
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.