Giter VIP home page Giter VIP logo

Comments (13)

bluepichu avatar bluepichu commented on June 6, 2024 2

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.

bluepichu avatar bluepichu commented on June 6, 2024 1

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.

bluepichu avatar bluepichu commented on June 6, 2024 1

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.

ArronFerguson avatar ArronFerguson commented on June 6, 2024 1

That worked great, thanks a bunch! Couple of things I noticed:

  1. The inside quotes for the link element require a double quote - doesn't work for a single quote
  2. The property 'targetTag' contains 'undefined'

But the event is generated and the handler is called.

from pixi-multistyle-text.

bluepichu avatar bluepichu commented on June 6, 2024 1

That was missing an undefined check, but was otherwise correct. Good catch :)

from pixi-multistyle-text.

tleunen avatar tleunen commented on June 6, 2024

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

ArronFerguson avatar ArronFerguson commented on June 6, 2024

@bluepichu

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:

http://arronferguson.com/

And the projects section will need clickable links.

from pixi-multistyle-text.

tleunen avatar tleunen commented on June 6, 2024

@bluepichu I like your approach!

from pixi-multistyle-text.

ArronFerguson avatar ArronFerguson commented on June 6, 2024

I forgot how to download the finished compiled version in JavaScript from branch iss52. You have another link?

from pixi-multistyle-text.

bluepichu avatar bluepichu commented on June 6, 2024

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.

ArronFerguson avatar ArronFerguson commented on June 6, 2024

@bluepichu

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.

ArronFerguson avatar ArronFerguson commented on June 6, 2024

Ha ha, nice, thanks!

from pixi-multistyle-text.

bluepichu avatar bluepichu commented on June 6, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.