libui-node icon indicating copy to clipboard operation
libui-node copied to clipboard

Background text of attributed string does not work properly on High Sierra

Open mischnic opened this issue 7 years ago • 17 comments

examples/text.js:

Expected (correct on Sierra): text js

High Sierra: text js

Need test whether this is an issue of libui.

mischnic avatar May 02 '18 17:05 mischnic

Need test whether this is an issue of libui.

Does the same happen if you run the libui drawtext example on High Sierra?

mischnic avatar May 02 '18 18:05 mischnic

No, but it seems it doesn't use background at all:

image

parro-it avatar May 02 '18 18:05 parro-it

4th Line: "text background color" has a yellow-ish background

Interesting. I can't reproduce this, unfortunately.

mischnic avatar May 02 '18 18:05 mischnic

Oh, yes. So it seems a bug on bindings...

parro-it avatar May 02 '18 18:05 parro-it

Oh, yes. So it seems a bug on bindings...

Then why does it work on Sierra? 😕

mischnic avatar May 02 '18 18:05 mischnic

Then why does it work on Sierra?

We should investigate 🕵🏻‍♂️

parro-it avatar May 02 '18 18:05 parro-it

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);
}

mischnic avatar May 02 '18 20:05 mischnic

Does it work correctly with libui-napi?

mischnic avatar Jun 19 '18 09:06 mischnic

No, it work the same as libui-node 😭

parro-it avatar Jun 19 '18 09:06 parro-it

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.

parro-it avatar Jun 19 '18 18:06 parro-it

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:

image

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:

image

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

image

parro-it avatar Jun 19 '18 18:06 parro-it

The problem even appear/disappear if I resize the window.

parro-it avatar Jun 19 '18 19:06 parro-it

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?

mischnic avatar Jun 19 '18 19:06 mischnic

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:

giu-19-2018 21-57-44

parro-it avatar Jun 19 '18 19:06 parro-it

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...

mischnic avatar Jun 19 '18 20:06 mischnic

The problem is still present on macOS Mojave ☹️

image

parro-it avatar Nov 08 '18 20:11 parro-it

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

mischnic avatar Nov 08 '18 20:11 mischnic