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
[guilib] Decouple left/right text truncate from alignment #24799
Conversation
e29ee53
to
125e3b1
Compare
125e3b1
to
78004ff
Compare
78004ff
to
1bdf694
Compare
xbmc/guilib/GUIFontTTF.cpp
Outdated
} | ||
} | ||
else | ||
{ | ||
// Determines the maximum width the text can have within the maximum width |
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.
not very clear, defines the max width with the max width?
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.
"Calculates the text width based on the characters that can be contained within the maximum width"
better?
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.
replaced
xbmc/guilib/GUIFontTTF.cpp
Outdated
if (alignment & XBFONT_CENTER_X && !(alignment & XBFONT_RIGHT) && !(alignment & XBFONT_LEFT)) | ||
{ | ||
if (alignment & XBFONT_CENTER_X) |
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.
Which case is the first if() meant to filter? There is overlap with the second if()
A validation that alignment doesn't contain conflicting flags could be good but would belong to the beginning of the function (or its caller), would have some error logging and would override the flags to go back to a normal situation for the rest of the code.
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.
add a validation would be nice,but the callers are many and come from different components, i dont think there is a good common place to add a validation you need to add it on each use case component, not feasible here, too much changes to do and prone to easy oversights (and i dont want to do much big PR since need to be backported)
if you thing to force change the alignment for validation purpose in to CGUIFontTTF::DrawTextInternal
will make a bit of mess with parent callers behaviours that use same align value to do other things,
maybe a kind of "middle ground" is in the CGUIFont
and you need to add the validation before each CGUIFontTTF::DrawTextInternal
call and alignment value uses
for now are both cases: CGUIFont::DrawText
and CGUIFont::DrawScrollingText
I can try adding align validation on these two methods, hoping it won't be printed in the log millions of error lines when the validation fails
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 made an attempt and as i was thinking it print on log millions lines of validating errors
so i will add a kid of validation check in to CGUIFontTTF::DrawTextInternal
inside the if (dirtyCache)
,
so that when cached dont print anymore tons of log lines
maybe not perfect but at least users/devs can know if has set an invalid alignment that can produce wrong rendering
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.
added validation as said on my previous comment, please try give a look
xbmc/guilib/GUIFontTTF.cpp
Outdated
@@ -516,10 +538,10 @@ void CGUIFontTTF::DrawTextInternal(CGraphicContext& context, | |||
{ | |||
float nextCursorX = cursorX; | |||
|
|||
if (alignment & XBFONT_TRUNCATED) | |||
if (alignment & XBFONT_TRUNCATED || alignment & XBFONT_TRUNCATED_LEFT) |
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.
Is this addition necessary? cursorX is initialized with ellipsesWidth in case of left truncation and the iterator of the loop begins at the first character that fits with left truncation
Alternatively mirror the Render loop more closely, which does require this condition and an exception treatment for the first char.
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.
removed
@@ -554,13 +576,13 @@ void CGUIFontTTF::DrawTextInternal(CGraphicContext& context, | |||
continue; | |||
} | |||
|
|||
if (alignment & XBFONT_TRUNCATED) | |||
if (alignment & XBFONT_TRUNCATED || alignment & XBFONT_TRUNCATED_LEFT) | |||
{ |
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.
since the XBFONT_TRUNCATED and the XBFONT_TRUNCATED_LEFT case don't share anything, might be clearer to do
if (alignment & XBFONT_TRUNCATED)
{ existing code }
else if (alignment & XBFONT_TRUNCATED_LEFT && itGlyph == glypghBegin)
{ new code }
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.
done
@@ -538,7 +537,7 @@ void CGUIEditControl::ProcessText(unsigned int currentTime) | |||
if (HasFocus() || leftTextWidth == 0) | |||
changed |= m_label2.SetOverflow(CGUILabel::OVER_FLOW_CLIP); | |||
else | |||
changed |= m_label2.SetOverflow(CGUILabel::OVER_FLOW_TRUNCATE); | |||
changed |= m_label2.SetOverflow(CGUILabel::OVER_FLOW_TRUNCATE_LEFT); |
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.
Doesn't left or right truncation depend on the offset of the first character displayed and text length vs space available?
Worst case there could be both left and right truncation. probably best left for another PR though, this one does not mean to change the behavior.
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.
left or right truncation currently depends on:
- How you want to display a text on a control
- If the text is LTR / RTL (this can be a future improvement)
if case of edit control we want always display the last chars on screen and so truncate on left,
otherwise it will result in incomprehensible text displayed if you use truncate from right
maybe here i can try re-use SetAlign
instead to add the new OVER_FLOW_TRUNCATE_LEFT
in theory it should not cause problems, i will try
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.
no not good, better as is otherwise break the overflow behaviour, so always set the truncate align should not be a big problem but idk
I don't have much skinning skills, my limited runtime testing didn't find issues in Estuary but a skinner's feedback would be preferable. |
ce9b30a
to
0d100af
Compare
0d100af
to
4db197f
Compare
before this PR you cannot use truncate from LEFT with left/center alignment, because truncate to LEFT was linked to right alignment only, so no screenshots |
4db197f
to
17af1e2
Compare
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.
Found some time to test this today and everything is working as expected.
Thanks.
jenkins build this please |
Description
This PR introduce the left text truncate setting.
The problem is started with the GUI control improvements PR #22691 where in the past i tried to introduce the left truncate, but has caused some issues with the right text alignment. After that i had tried to fix with PR #24624, but was not so perfect solution (this PR also revert that changes).
The right solution is decouple left/right truncate so that can be configured without strictly depends from alignment.
XBFONT_TRUNCATED_LEFT
was inevitably added and should extend the "alignment" settings for python addons without particular impactHaving improved the code, I took the opportunity to include an additional fix for the use case having
<align>center</align>
andOVER_FLOW
to TRUNCATE, was already broken from oldest kodi versions (screenshots for center case below)These changes keep same behaviours for GUI settings improvements as shown on screenshots of PR #22691
In case of rebranch the backport to Kodi 21 is mandatory for the final release.
Note 1 for
<align>justify</align>
/XBFONT_JUSTIFIED
:This alignment was already broken, and will not be addressed with this PR
Note 2: the new left truncate can have an additional use for RTL text but requires other improvements
Motivation and context
fix #24725
How has this been tested?
user confirmed no regressions:
#24725 (comment)
#24610 (comment)
Used custom python addon with a xml window and with:
<control type="label" id="10000">
<control type="fadelabel" id="10000">
(note this control perform truncate without ellipses)<control type="textbox" id="10000">
CURRENT MASTER BRANCH (BEFORE):
Here i show only broken use cases
Multilines both lines are short, dont exceed the container width, and then text "truncate" is not applied
<align>right</align>
Multilines both lines are too long, exceed the container width, and text "truncate to RIGHT" is applied
<align>center</align>
(broken already before Kodi 20)<align>right</align>
WITH PR (NOW):
Multilines both lines are short, dont exceed the container width, and then text "truncate" is not applied
<align>left</align>
<align>center</align>
<align>right</align>
Multilines both lines are too long, exceed the container width, and text "truncate to RIGHT" is applied
<align>left</align>
<align>center</align>
<align>right</align>
Only for sake of completness, example of truncate from LEFT, on right aligned text:
What is the effect on users?
Various type of GUI controls used on skins should display text as expected
Screenshots (if appropriate):
Types of change
Checklist: