daybrush / moveable

Moveable! Draggable! Resizable! Scalable! Rotatable! Warpable! Pinchable! Groupable! Snappable!
https://daybrush.com/moveable/
MIT License
10.15k stars 623 forks source link

How to make Snapping Grid visible during the drag Event? #935

Closed jadiagaurang closed 1 year ago

jadiagaurang commented 1 year ago

Environments

Description

I would like to show Snapping Grid during the drag Event to help user visualize the Snapping Grid. Is it possible with current implementation or are you planning to add a feature in the future?

Example Image: drag+with+uneven+rows

Example Config for the Moveable Object:

const designCanvas = $(".design-canvas")[0];
const designCanvasWidth = $(".design-canvas").width();
const designCanvasHeight = $(".design-canvas").height();

window.objMoveable = new Moveable(designCanvas, {
  target: [],

  draggable: true,

  // Snapping!
  snappable: true,
  snapContainer: designCanvas,
  bounds: { // Limit movement within the container
    left: 0,
    top: 0,
    right: designCanvas.offsetWidth,
    bottom: designCanvas.offsetHeight,
  },
  verticalGuidelines: [
    50, 
    designCanvasWidth / 4, 
    designCanvasWidth / 2, 
    designCanvasWidth * 3 / 4, 
    designCanvasWidth - 50
  ],
  horizontalGuidelines: [
    50, 
    designCanvasHeight / 4, 
    designCanvasHeight / 2, 
    designCanvasHeight * 3 / 4, 
    designCanvasHeight - 50
  ],
  snapThreshold: 5,
  snapGridWidth: 50,
  snapGridHeight: 50,
  snapElement: true,
  snapGap: true,
  snapDistFormat: (v, type) => `${v}px`,
  snapDirections: {
    left: true,
    top: true,
    right: true,
    bottom: true,
    center: true,
    middle: true
  },
  snapDigit: 0,
  isDisplaySnapDigit: true,
  isDisplayInnerSnapDigit: true,
  elementSnapDirections: true,
  elementGuidelines: $(".el").get()  //Add List of Element to enable Guidelines!
});
daybrush commented 1 year ago

@jadiagaurang

I'll add it in the next update.

daybrush commented 1 year ago

@jadiagaurang

moveable's new version is released. Set isDisplayGridGuidelines to true.

jadiagaurang commented 1 year ago

@daybrush

Thank you so much for adding new config to display Grid Guidelines. I tried the config on a new CodePen example.

Testable Address: https://codepen.io/jadiagaurang/pen/PoxYVRN

I have set grid cell to be 50x50 (px) and snapThreshold = 50 as well.

isDisplayGridGuidelines: true,
snapThreshold: 50,
snapGridWidth: 50,
snapGridHeight: 50

I am trying to generate CSS Grid from the pixel coordinate. I am trying to show entire Grid to help user place on a Grid Cell which should help user design a Block more efficiently.

Some Technical Blog which I am following to generate CSS Grid from Pixel Coordinates.

  1. https://www.canva.dev/blog/engineering/css-absolutely-positioning-things-relatively/
  2. https://engineering.squarespace.com/blog/2022/developing-fluid-engine

Is it possible to show entire grid with the provided config or via CSS?

daybrush commented 1 year ago

@jadiagaurang Sorry. There are no plans to provide a function that displays the entire guideline or grid. You have to create Guidelines or Grid through component or HTML or CSS.

I support Guides Manager. https://github.com/daybrush/guides

I'm preparing an editor, but I haven't made a Grid yet.

Assuming that I create a Grid, it seems that I can create a Grid shape through a background or pattern.

https://github.com/daybrush/scena

jadiagaurang commented 1 year ago

@daybrush Thanks for the clarification. I will try to render a CSS Grid and show the Gridlines.