Coder Social home page Coder Social logo

Comments (4)

asturur avatar asturur commented on June 2, 2024 1

When doing the first version of the control api, that is the one that is still available today, there were 2 way to define controls properties. On the object and with styleOverrides.

The reasoning was that we would see what was the usage and we would change depending on feedback.
At the moment duplicating the setting on the object and on the control and then deciding which one has the priority didn't look good ( it doesn't to me also today ).

You can create a custom render function, let's say you want to render a circle, pass a render option to your control:

      acc[`newPoint${index}`] = new fabric.Control({
          positionHandler: this.newPointPolygonPositionHandler.bind(this, index),
          mouseUpHandler: this.newPointAnchorWrapper(index),
          actionName: "newPointPolygon",
          cursorStyle: "copy",
          render: function(
                          ctx: CanvasRenderingContext2D,
                          left: number,
                          top: number,
                          styleOverride: ControlRenderingStyleOverride | undefined,
                          fabricObject,
                       )  {
        renderCircleControl.call(
          this,
          ctx,
          left,
          top,
          styleOverride: {
             cornerColor: 'specialColorYouWant'
           }
          fabricObject,
        );
      }
  })

this is a way to do it.
You can also define this control as a subclass of the standard control and keep it as a preconfigured class

from fabric.js.

elerocks avatar elerocks commented on June 2, 2024

thank you @asturur ! That's exactly what I needed.
Additional question, is it possible to catch right click event on fabric.Control? I've only managed to catch left click (using the mouseUpHandler)

from fabric.js.

asturur avatar asturur commented on June 2, 2024

ah. If it doesn't fire no, but i would agree it would be sort of normal to have it?
It probably doesn't work because if the click is not left with let go the whole function and we stop checking.

Maybe you can use _findTargetCorner on the activeObject on a generic mouseUp/mouseDown on the canvas and call the control mouseUp handler manually?

This could be something we could support out of the box, you should open a separate feature request for it

from fabric.js.

elerocks avatar elerocks commented on June 2, 2024

Thank you, separate feature request filed. I think this issue can be closed.

from fabric.js.

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.