Skip to content
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

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

Open
mischnic opened this issue May 2, 2018 · 17 comments
Open
Labels
Milestone

Comments

@mischnic
Copy link
Collaborator

mischnic commented May 2, 2018

examples/text.js:

Expected (correct on Sierra):
text js

High Sierra:
text js

Need test whether this is an issue of libui.

@parro-it parro-it added this to the 0_3_0 milestone May 2, 2018
@parro-it parro-it added the bug label May 2, 2018
@mischnic
Copy link
Collaborator Author

mischnic commented May 2, 2018

Need test whether this is an issue of libui.

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

@parro-it
Copy link
Owner

parro-it commented May 2, 2018

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

image

@mischnic
Copy link
Collaborator Author

mischnic commented May 2, 2018

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

Interesting. I can't reproduce this, unfortunately.

@parro-it
Copy link
Owner

parro-it commented May 2, 2018

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

@mischnic
Copy link
Collaborator Author

mischnic commented May 2, 2018

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

Then why does it work on Sierra? 😕

@parro-it
Copy link
Owner

parro-it commented May 2, 2018

Then why does it work on Sierra?

We should investigate 🕵🏻‍♂️

@mischnic
Copy link
Collaborator Author

mischnic commented May 2, 2018

I'd guess somewhere in here? After that, it's out of our control.

void AttributedString::appendAttributedInternal(
const char *str, std::vector<FontAttribute *> attrs) {
size_t start = this->toStringLen();
size_t end = start + strlen(str);
this->appendUnattributed(str);
for (std::vector<FontAttribute *>::size_type i = 0; i < attrs.size(); i++) {
this->setAttribute(attrs[i], start, end);
}
}

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

@parro-it parro-it changed the title Background text Background text of attributed string does not work properly on High Sierra May 3, 2018
@parro-it parro-it mentioned this issue May 3, 2018
10 tasks
@parro-it parro-it modified the milestones: 0_3_0, 0.4.0 May 30, 2018
@mischnic
Copy link
Collaborator Author

Does it work correctly with libui-napi?

@parro-it
Copy link
Owner

No, it work the same as libui-node 😭

@parro-it
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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

@mischnic
Copy link
Collaborator Author

mischnic commented Jun 19, 2018

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?

@parro-it
Copy link
Owner

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

@mischnic
Copy link
Collaborator Author

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

@parro-it
Copy link
Owner

parro-it commented Nov 8, 2018

The problem is still present on macOS Mojave ☹️

image

@mischnic
Copy link
Collaborator Author

mischnic commented Nov 8, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants