Comments (13)
Sorry for the delay - had no internet for a while there :)
I really like this feature idea! I share the same semantic concerns with having the onClick
handler be in the tag style, since it's not really a style. It also seems weird to have an event listener be applied without going through the usual methods for doing so.
One option would be to extend the event classes for any events we want to handle and include additional information about the tag that was clicked on. In this case, we might also want to allow the addition of user-defined properties on tags a-la HTML; I could see this being useful for a Pixi approximation of links:
let content = `Click on the links to navigate:
<link href="home">Home</link>
<link href="about">About</link>
<link href="shop">Shop</link>`;
let pmt = new PixiMultistyleText(content, {
link: {
color: "#4466ff",
fontStyle: "italic"
}
});
pmt.on("click", (event) => {
console.log(event.targetTag);
// For a click on the "about" link, { name: "link", properties: { href: "about" } }
});
Thoughts?
from pixi-multistyle-text.
PR Filed: #53. It's not particularly thoroughly-tested, but if you want to use this version now, you can grab a copy of the updated source from branch iss52
of my fork and build it.
from pixi-multistyle-text.
This should generate a built copy (in <working path>/pixi-multistyle-text/dist/pixi-multistyle-test.js
) and launch the demo, though requires that you have TypeScript and Browserify installed globally:
git clone https://github.com/bluepichu/pixi-multistyle-text.git
cd pixi-multistyle-text
git checkout iss52
npm install
npm run demo
I can push a prebuilt copy to another branch if this doesn't work for some reason.
from pixi-multistyle-text.
That worked great, thanks a bunch! Couple of things I noticed:
- The inside quotes for the link element require a double quote - doesn't work for a single quote
- The property 'targetTag' contains 'undefined'
But the event is generated and the handler is called.
from pixi-multistyle-text.
That was missing an undefined
check, but was otherwise correct. Good catch :)
from pixi-multistyle-text.
@bluepichu This sounds like an interesting feature.
We could handle a onClick
property inside the tag descriptor style... Unless you have a better idea, since a click event is not a style...?
from pixi-multistyle-text.
ZOMG, yes! That would be brilliant! I could really use clickable links in my Pixi app so that users can click on the text and go to another link (e.g., page). My Pixi site is at:
And the projects section will need clickable links.
from pixi-multistyle-text.
@bluepichu I like your approach!
from pixi-multistyle-text.
I forgot how to download the finished compiled version in JavaScript from branch iss52. You have another link?
from pixi-multistyle-text.
I've fixed the former issue in the above commit, but I'm not sure what (if anything) can or should be done about the latter. Any interaction events that don't overlap any tag will currently result in targetTag
being undefined
, and that behavior seems consistent with the rest of the implementation to me. That said, if there's a good reason why it shouldn't be undefined
in that case - and a good suggestion for what it should be instead - I'm definitely open to changing this behavior.
from pixi-multistyle-text.
Hi, Matthew, that's great thanks for fixing the former. The latter was because I was looking at the example demo which has the following code:
interaction.on("pointerdown", (e) => {
if (e.targetTag.name === "link") {
alert(`You clicked on the link for "${e.targetTag.properties.name}"!`);
}
});
Or is this not how to get the actual link value that was posted in the name attribute of the link element?
Again thank you so much for your time.
from pixi-multistyle-text.
Ha ha, nice, thanks!
from pixi-multistyle-text.
This has been released as v0.7.0-rc.1
, and will be made into a release version once we can get more thorough testing done on it. Please let us know if you find any more bugs. Thanks!
from pixi-multistyle-text.
Related Issues (20)
- Formatting tags cannot be used together
- Error when used "@pixi/text": "5.2.2" and fillGradientStops style HOT 1
- BitmapText support? HOT 1
- Cropped characters
- Change FILL color .on('pointerover'
- Hire You To Build This Feature
- Request for Write privileges HOT 6
- wordWrap + letterSpacing is broken HOT 3
- Unable to update wordWrapWidth HOT 3
- A feature request, textOverflow with ellipsis HOT 1
- Incorrect formatting when using breakWords. HOT 3
- Negative local bounds on root container
- option to use bbcode style [tags][/tags] instead of <xml></xml> style HOT 3
- ability to take in parameters inside tag <color=red> red text </color> HOT 2
- Ability to use this as a library inside a JS project
- demo no longer works HOT 4
- Do you plan to make it compatible with Pixi 5? HOT 2
- Cannot set property realWidth HOT 7
- adding "lineHeight" param
- Added to list of v5 plugins HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pixi-multistyle-text.