-
Notifications
You must be signed in to change notification settings - Fork 39
feat: add layer visibility toggling feature #524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@ShiboSoftwareDev @imrishabh18 Do Check it out, Thanks. |
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
src/LayerVisibilitySubmenu.tsx
Outdated
| left: (submenuRef.current && window.innerWidth < position.x + submenuRef.current.offsetWidth + 220) | ||
| ? position.x - submenuRef.current?.offsetWidth | ||
| : position.x + 220, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a reference to submenuRef.current in the positioning logic, but this variable isn't defined in this component. Since this component uses forwardRef, the correct reference to use is the ref parameter that's passed to the component.
The positioning code should be updated to:
left: (ref.current && window.innerWidth < position.x + ref.current.offsetWidth + 220)
? position.x - ref.current?.offsetWidth
: position.x + 220,This will ensure the submenu is properly positioned based on available screen space.
| left: (submenuRef.current && window.innerWidth < position.x + submenuRef.current.offsetWidth + 220) | |
| ? position.x - submenuRef.current?.offsetWidth | |
| : position.x + 220, | |
| left: (ref.current && window.innerWidth < position.x + ref.current.offsetWidth + 220) | |
| ? position.x - ref.current?.offsetWidth | |
| : position.x + 220, | |
Spotted by Graphite Agent
Is this helpful? React 👍 or 👎 to let us know.
imrishabh18
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's incorrect smtPad or the via is not a kicad layer
| import React, { forwardRef } from "react" | ||
|
|
||
| export type LayerVisibility = { | ||
| board: boolean | ||
| platedHoles: boolean | ||
| smtPads: boolean | ||
| vias: boolean | ||
| copperPours: boolean | ||
| topTrace: boolean | ||
| bottomTrace: boolean | ||
| topSilkscreen: boolean | ||
| bottomSilkscreen: boolean | ||
| cadComponents: boolean | ||
| } | ||
|
|
||
| interface LayerVisibilitySubmenuProps { | ||
| layerVisibility: LayerVisibility | ||
| presentLayers: Partial<LayerVisibility> | ||
| onToggleLayer: (layer: keyof LayerVisibility) => void | ||
| onShowAllLayers: () => void | ||
| position: { x: number; y: number } | ||
| } | ||
|
|
||
| export const LayerVisibilitySubmenu = forwardRef< | ||
| HTMLDivElement, | ||
| LayerVisibilitySubmenuProps | ||
| >( | ||
| ( | ||
| { | ||
| layerVisibility, | ||
| presentLayers, | ||
| onToggleLayer, | ||
| onShowAllLayers, | ||
| position, | ||
| }, | ||
| ref, | ||
| ) => { | ||
| const submenuWidth = 200 | ||
| const left = | ||
| position.x + 220 > window.innerWidth - submenuWidth | ||
| ? position.x - submenuWidth - 20 | ||
| : position.x + 220 | ||
|
|
||
| return ( | ||
| <div | ||
| ref={ref} | ||
| style={{ | ||
| position: "fixed", | ||
| top: position.y, | ||
| left, | ||
| background: "#23272f", | ||
| color: "#f5f6fa", | ||
| borderRadius: 6, | ||
| boxShadow: "0 6px 24px 0 rgba(0,0,0,0.18)", | ||
| zIndex: 1001, | ||
| minWidth: 180, | ||
| border: "1px solid #353945", | ||
| padding: 0, | ||
| fontSize: 14, | ||
| fontWeight: 500, | ||
| }} | ||
| > | ||
| <div | ||
| style={{ | ||
| padding: "12px 18px 8px 18px", | ||
| fontSize: 12, | ||
| opacity: 0.7, | ||
| fontWeight: 500, | ||
| color: "#c0c0c0", | ||
| borderBottom: "1px solid rgba(255, 255, 255, 0.1)", | ||
| marginBottom: "4px", | ||
| }} | ||
| > | ||
| Layer Visibility | ||
| </div> | ||
| <div | ||
| style={{ | ||
| padding: "8px 18px", | ||
| cursor: "pointer", | ||
| display: "flex", | ||
| alignItems: "center", | ||
| gap: 10, | ||
| color: "#4ade80", | ||
| fontWeight: 500, | ||
| fontSize: 14, | ||
| borderRadius: 6, | ||
| transition: "background 0.1s", | ||
| }} | ||
| onClick={onShowAllLayers} | ||
| onMouseOver={(e) => (e.currentTarget.style.background = "#2d313a")} | ||
| onMouseOut={(e) => (e.currentTarget.style.background = "transparent")} | ||
| > | ||
| Show All Layers | ||
| </div> | ||
| {Object.entries(layerVisibility) | ||
| .filter(([layer]) => presentLayers[layer as keyof LayerVisibility]) | ||
| .map(([layer, visible]) => ( | ||
| <div | ||
| key={layer} | ||
| style={{ | ||
| padding: "8px 18px", | ||
| cursor: "pointer", | ||
| display: "flex", | ||
| alignItems: "center", | ||
| gap: 10, | ||
| color: "#f5f6fa", | ||
| fontWeight: 400, | ||
| fontSize: 14, | ||
| borderRadius: 6, | ||
| transition: "background 0.1s", | ||
| }} | ||
| onClick={() => onToggleLayer(layer as keyof LayerVisibility)} | ||
| onMouseOver={(e) => | ||
| (e.currentTarget.style.background = "#2d313a") | ||
| } | ||
| onMouseOut={(e) => | ||
| (e.currentTarget.style.background = "transparent") | ||
| } | ||
| > | ||
| <span style={{ marginRight: 8 }}>{visible ? "✔" : ""}</span> | ||
| {layer === "cadComponents" | ||
| ? "CAD Components" | ||
| : layer === "platedHoles" | ||
| ? "Plated Holes" | ||
| : layer === "smtPads" | ||
| ? "SMT Pads" | ||
| : layer === "copperPours" | ||
| ? "Copper Pours" | ||
| : layer === "topTrace" | ||
| ? "Top Traces" | ||
| : layer === "bottomTrace" | ||
| ? "Bottom Traces" | ||
| : layer === "topSilkscreen" | ||
| ? "Top Silkscreen" | ||
| : layer === "bottomSilkscreen" | ||
| ? "Bottom Silkscreen" | ||
| : layer.charAt(0).toUpperCase() + layer.slice(1)} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ) | ||
| }, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file name LayerVisibilitySubmenu.tsx does not follow the project's naming convention. Based on the stated rule "Generally kebab-case", this file should be renamed to layer-visibility-submenu.tsx to maintain consistency with the project's file naming standards.
Spotted by Graphite Agent (based on custom rule: Custom rule)
Is this helpful? React 👍 or 👎 to let us know.
|
@seveibar I had PR the solution earlier. |
I have added layer visibility toggling feature, where one can enable/disable the view of the available layer in the 3d viewer.
Below is the attached video of the working.
Screen.Recording.2025-10-15.150206.mp4
/claim #523
fixes #523