-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**Problem:** The orange grid gap controls are sometimes 1px off, they are one frame behind, they show weird delays when the canvas zooms. **Fix:** A lot of the problem came down to `gridGapControlBoundsFromMetadata` trying to calculate the bounding boxes of where the gaps are in the selected Grid. However this is error prone because a lot of these boxes will fall on fractional pixel values, and we were not rounding them the same way Chrome was rounding the real grid. Instead of trying to fix the math, I had an idea to replicate our hack for the grid cell outline controls: take the ComputedStyle.gridTemplateRows / Columns, and create a helper grid which has the correct position and sizing for our gap outlines. The trick is that we want to take the original grid's gap value, and turn those into grid tracks too, setting the helper grid's gap to zero. So if my original grid's ComputedStyle has tracks [5px 10px 15px 5px] and a gap of 13px, we would create a helper grid with the tracks [5px 13px 10px 13px 15px 13px 5px]! Now the only job is to fill it with the elements and make sure to only draw anything in the tracks that correspond to gaps in the original grid (they are always the odd numbered tracks). This means we can offload the entire positioning and rendering to Chrome, and makes our life much simpler going forward. **Commit Details:** - Fixed Hot Reload by creating a new file `grid-gap-control-component.tsx` - Brand new `GridGapControlComponent`, `GridPaddingOutlineForDimension` and `GridRowHighlight` components. - `GridPaddingOutlineForDimension` creates the helper grid with the inlined gaps as tracks - `GridRowHighlight` is responsible for the visual lines, and it recreates the original grid in the given dimension so it can have a handle for each original row - `GridGapHandle` mostly unchanged --------- Co-authored-by: Federico Ruggi <1081051+ruggi@users.noreply.github.com>
- Loading branch information
1 parent
66fc4c8
commit 9d74ac4
Showing
9 changed files
with
597 additions
and
558 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
editor/src/components/canvas/controls/grid-controls-helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import type { CSSProperties } from 'react' | ||
import type { GridMeasurementHelperData } from './grid-controls-for-strategies' | ||
import { getNullableAutoOrTemplateBaseString } from './grid-controls-for-strategies' | ||
|
||
export function getGridHelperStyleMatchingTargetGrid( | ||
grid: GridMeasurementHelperData, | ||
): CSSProperties { | ||
let style: CSSProperties = { | ||
position: 'absolute', | ||
top: grid.frame.y, | ||
left: grid.frame.x, | ||
width: grid.frame.width, | ||
height: grid.frame.height, | ||
display: 'grid', | ||
gridTemplateColumns: getNullableAutoOrTemplateBaseString(grid.gridTemplateColumns), | ||
gridTemplateRows: getNullableAutoOrTemplateBaseString(grid.gridTemplateRows), | ||
justifyContent: grid.justifyContent ?? 'initial', | ||
alignContent: grid.alignContent ?? 'initial', | ||
pointerEvents: 'none', | ||
padding: | ||
grid.padding == null | ||
? 0 | ||
: `${grid.padding.top}px ${grid.padding.right}px ${grid.padding.bottom}px ${grid.padding.left}px`, | ||
} | ||
|
||
// Gap needs to be set only if the other two are not present or we'll have rendering issues | ||
// due to how measurements are calculated. | ||
if (grid.rowGap != null && grid.columnGap != null) { | ||
style.rowGap = grid.rowGap | ||
style.columnGap = grid.columnGap | ||
} else { | ||
if (grid.gap != null) { | ||
style.gap = grid.gap | ||
} | ||
if (grid.rowGap != null) { | ||
style.rowGap = grid.rowGap | ||
} | ||
if (grid.columnGap != null) { | ||
style.columnGap = grid.columnGap | ||
} | ||
} | ||
|
||
return style | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.