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

Support text background (for text selection) #29

Open
felixmariotto opened this issue Jun 6, 2020 · 3 comments
Open

Support text background (for text selection) #29

felixmariotto opened this issue Jun 6, 2020 · 3 comments
Labels
roadmap Feature planned, must be addressed

Comments

@felixmariotto
Copy link
Owner

Planes should be added to all instances of Text, so that it's possible to control the text background with an attribute. It would also help with raycasting on the text.

I'm not really sure how it can be integrated in the code and the API though.

related : #1

@felixmariotto felixmariotto added the roadmap Feature planned, must be addressed label Jun 6, 2020
@swingingtom
Copy link
Collaborator

swingingtom commented Feb 7, 2022

During the implementation of white-space #120 , I built an advanced demo that required that the lines property of InlineManager was published.

If this lines property stays published, this could be the entry point of textselection and textbackground without the need to overhead any text component with additional planes.

This was done within onAfterUpdate

text.onAfterUpdate = function () {

            if( text.children.length == 0 ) return;

            // retrieve all lines sent by InlineManager for the textBlock
            for (let i = 0; i < text.parent.lines.length; i++) {
                  const line = text.parent.lines[i]
                  // add a background here  with line.x, line.y, line.width, line.height
                  // choose to place it before or behind the text component
                 // its color, its blendmode, etc...
            }
}

If we can get multiple onAfterUpdate on the same component, we could externalize behaviour to components

const textBlock = new ThreeMeshUI.Block({});
ThreeMeshUI.SelecteableBehaviour( textBlock , options );

Then a raycast on the textBlock could compare its interesected position to any inline positions contained in textBlock.lines[i]

[EDIT] : Without the need to push Selecteable logic into three-mesh-ui core components. They will be open to.

@felixmariotto
Copy link
Owner Author

felixmariotto commented Feb 7, 2022

Well yes this may be a good way of accessing the objects from an API point of view.

I suggested that we would need a second set of planes because currently all the planes have different shapes and sizes depending on the character they map.

When you select text in your browser for instance, the text background highlighting the selection has constant height, wether you select a "o" or a "P". So we can't just color the background in the text shader...

Unless we update MSDFGlyph to output quads of constant height, and update the text shader to discard the parts of the quads that would overlap other characters of the MSDF texture (in order to not see a bit of "p" above the "o" for instance)

@swingingtom
Copy link
Collaborator

@felixmariotto indeed. I didn't correctly understand it at first.

This idea was to put fresh feedback on this previous issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
roadmap Feature planned, must be addressed
Projects
None yet
Development

No branches or pull requests

2 participants