libui-node
libui-node copied to clipboard
Background text of attributed string does not work properly on High Sierra
examples/text.js:
Expected (correct on Sierra):

High Sierra:

Need test whether this is an issue of libui.
Need test whether this is an issue of libui.
Does the same happen if you run the libui drawtext example on High Sierra?
No, but it seems it doesn't use background at all:

4th Line: "text background color" has a yellow-ish background
Interesting. I can't reproduce this, unfortunately.
Oh, yes. So it seems a bug on bindings...
Oh, yes. So it seems a bug on bindings...
Then why does it work on Sierra? 😕
Then why does it work on Sierra?
We should investigate 🕵🏻♂️
I'd guess somewhere in here? After that, it's out of our control.
https://github.com/parro-it/libui-node/blob/4d72285024645d8f7947772808230c4d0cf0dc52/src/Font/AttributedString.cc#L70-L79
Could you check if start and end are really the right values and whether the for loop properly iterates over the vector?
libui drawtext example:
static void appendWithAttribute(const char *what, uiAttribute *attr, uiAttribute *attr2)
{
size_t start, end;
start = uiAttributedStringLen(attrstr);
end = start + strlen(what);
uiAttributedStringAppendUnattributed(attrstr, what);
uiAttributedStringSetAttribute(attrstr, attr, start, end);
if (attr2 != NULL)
uiAttributedStringSetAttribute(attrstr, attr2, start, end);
}
Does it work correctly with libui-napi?
No, it work the same as libui-node 😭
I discovered that the problem go away if I change the text passed to the AttributedString constructor. I'm trying to dissect changes until I found what particular text change is causing the problem.
This attributed string:
const str = new libui.AttributedString(
'Drawing strings with libui is done with the uiAttributedString and uiDrawTextLayout objects.\n' +
'uiAttributedString lets you have a variety of attributes: font family, font size, font weight,' +
'font italicness, font stretch, text color',
FontAttribute.newColor(new libui.Color(0.75, 0.25, 0.5, 0.75)));
str.appendAttributed('text background color', FontAttribute.newBackgroundColor(
new libui.Color(0.5, 0.5, 0.25, 0.5)));
str.appendUnattributed(', underline style, and ');
renders to this:

This one:
const str = new libui.AttributedString(
'Drawing strings with ',
FontAttribute.newColor(new libui.Color(0.75, 0.25, 0.5, 0.75)));
str.appendAttributed('text background color', FontAttribute.newBackgroundColor(
new libui.Color(0.5, 0.5, 0.25, 0.5)));
str.appendUnattributed(', underline style, and ');
renders correctly:

Maybe there is a problem when an attributed string part spans throw multiple lines?

The problem even appear/disappear if I resize the window.
Maybe there is a problem when an attributed string part spans throw multiple lines?
That might be it. Does the libui drawtext example behave the same?
The problem even appear/disappear if I resize the window.
So if you "remove" the line break in the background color region?
So if you "remove" the line break in the background color region?
Exactly...
That might be it. Does the libui drawtext example behave the same?
Yes, the libui drawtext example has the same behaviour. It just happens that the background text by default does not break on lines, you have to resize the window:

Yes, the libui drawtext example has the same behaviour. It just happens that the background text by default does not break on lines, you have to resize the window:
Time to open a issue on libui with that gif...
The problem is still present on macOS Mojave ☹️

I'll have to research if libui is using the API incorrectly (if not, there should be other apps experiencing this).