Skip to content
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

🐛Fix context menu and components panel spawn coordinates #169

Merged
merged 6 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 61 additions & 46 deletions src/components/xircuitBodyWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,7 @@ export const BodyWidget: FC<BodyWidgetProps> = ({
/**Component Panel & Node Action Panel Context Menu */
const [isComponentPanelShown, setIsComponentPanelShown] = useState(false);
const [actionPanelShown, setActionPanelShown] = useState(false);
const [dontHidePanel, setDontHidePanel] = useState(false);
const [isPanelAtTop, setIsPanelAtTop] = useState<boolean>(true);
const [isPanelAtLeft, setIsPanelAtLeft] = useState<boolean>(true);
const [componentPanelPosition, setComponentPanelPosition] = useState({ x: 0, y: 0 });
Expand All @@ -1590,35 +1591,41 @@ export const BodyWidget: FC<BodyWidgetProps> = ({
x: event.pageX,
y: event.pageY,
};
let newActionPanelPosition = {
x: event.pageX,
y: event.pageY,
};
const canvas = event.view as any;
const newCenterPosition = {
x: canvas.innerWidth / 2,
y: canvas.innerHeight / 2,
}
const menuDimension = {
x: 95,
y: 267
}
const fileBrowserWidth = document.getElementsByClassName("jp-FileBrowser")['filebrowser'].clientWidth;
const tabWidth = document.getElementsByClassName("lm-TabBar")[0].clientWidth;
if (newPanelPosition.x > newCenterPosition.x && newPanelPosition.y > newCenterPosition.y) {
// Bottom right
setIsPanelAtTop(false);
setIsPanelAtLeft(false);
newPanelPosition.y = canvas.innerHeight - newPanelPosition.y;
newPanelPosition.x = canvas.innerWidth - newPanelPosition.x;
newPanelPosition.x = canvas.innerWidth - newPanelPosition.x - tabWidth;
newPanelPosition.y = canvas.innerHeight - newPanelPosition.y - menuDimension.y;
} else if (newPanelPosition.x > newCenterPosition.x && newPanelPosition.y < newCenterPosition.y) {
// Top right
setIsPanelAtTop(true);
setIsPanelAtLeft(false);
newPanelPosition.x = canvas.innerWidth - newPanelPosition.x;
newPanelPosition.x = canvas.innerWidth - newPanelPosition.x - tabWidth;
newPanelPosition.y = newPanelPosition.y - 84;
} else if (newPanelPosition.x < newCenterPosition.x && newPanelPosition.y > newCenterPosition.y) {
// Bottom left
setIsPanelAtTop(false);
setIsPanelAtLeft(true);
newPanelPosition.y = canvas.innerHeight - newPanelPosition.y;
newPanelPosition.x = newPanelPosition.x - fileBrowserWidth - tabWidth;
newPanelPosition.y = canvas.innerHeight - newPanelPosition.y - menuDimension.y;
} else {
// Top left
setIsPanelAtTop(true);
setIsPanelAtLeft(true);
newPanelPosition.x = newPanelPosition.x - fileBrowserWidth - tabWidth;
newPanelPosition.y = newPanelPosition.y - 84;
}
setComponentPanelPosition(newPanelPosition);
setActionPanelPosition(newPanelPosition);
Expand Down Expand Up @@ -1762,52 +1769,60 @@ export const BodyWidget: FC<BodyWidgetProps> = ({
}}
onContextMenu={showNodeActionPanel}
onClick={(event) => {
hidePanel();
if (event.ctrlKey || event.metaKey) {
showComponentPanel(event);
return;
}
if(dontHidePanel){
return;
}
hidePanel();
}}>
<DemoCanvasWidget>
<CanvasWidget engine={xircuitsApp.getDiagramEngine()} />
{/**Add Component Panel(ctrl + left-click, dropped link)*/}
{isComponentPanelShown && (
<div
onMouseEnter={()=>setDontHidePanel(true)}
onMouseLeave={()=>setDontHidePanel(false)}
id='component-panel'
style={{
top: isPanelAtTop ? componentPanelPosition.y : null,
bottom: !isPanelAtTop ? componentPanelPosition.y : null,
right: !isPanelAtLeft ? componentPanelPosition.x : null,
left: isPanelAtLeft ? componentPanelPosition.x : null
}}
className="add-component-panel">
<ComponentsPanel
lab={app}
eng={xircuitsApp.getDiagramEngine()}
nodePosition={nodePosition}
linkData={looseLinkData}
isParameter={isParameterLink}
key="component-panel"
></ComponentsPanel>
</div>
)}
{/**Node Action Panel(left-click)*/}
{actionPanelShown && (
<div
id='context-menu'
style={{
top: isPanelAtTop ? actionPanelPosition.y : null,
bottom: !isPanelAtTop ? actionPanelPosition.y : null,
right: !isPanelAtLeft ? actionPanelPosition.x : null,
left: isPanelAtLeft ? actionPanelPosition.x : null
}}
className="node-action-context-menu">
<NodeActionsPanel
app={app}
eng={xircuitsApp.getDiagramEngine()}
nodePosition={nodePosition}
></NodeActionsPanel>
</div>
)}
</DemoCanvasWidget>
</Layer>
{/**Add Component Panel(right-click)*/}
{isComponentPanelShown && (
<div
style={{
top: isPanelAtTop ? componentPanelPosition.y : null,
bottom: !isPanelAtTop? componentPanelPosition.y : null,
right: !isPanelAtLeft? componentPanelPosition.x : null,
left: isPanelAtLeft? componentPanelPosition.x : null
}}
className="add-component-panel">
<ComponentsPanel
lab={app}
eng={xircuitsApp.getDiagramEngine()}
nodePosition={nodePosition}
linkData={looseLinkData}
isParameter={isParameterLink}
key="component-panel"
></ComponentsPanel>
</div>
)}
{/**Node Action Panel(ctrl + left-click)*/}
{actionPanelShown && (
<div
style={{
top: isPanelAtTop? actionPanelPosition.y : null,
bottom: !isPanelAtTop? actionPanelPosition.y : null,
right: !isPanelAtLeft? actionPanelPosition.x : null,
left: isPanelAtLeft? actionPanelPosition.x : null
}}
className="node-action-context-menu">
<NodeActionsPanel
app={app}
eng={xircuitsApp.getDiagramEngine()}
nodePosition={nodePosition}
></NodeActionsPanel>
</div>
)}
</Content>
</Body>
);
Expand Down
10 changes: 5 additions & 5 deletions src/context-menu/ComponentsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import { TrayPanel } from './TrayPanel';
import { TrayItemPanel } from './TrayItemPanel';

export const Body = styled.div`
flex-grow: 1;
display: flex;
flex-wrap: wrap;
min-height: 100%;
background-color: black;
height: 100%;
height: 270px;
border-top: 10px;
border-radius: 12px;
overflow-y: auto;
`;

Expand Down Expand Up @@ -167,7 +167,7 @@ export default function ComponentsPanel(props: ComponentsPanelProps) {

return (
<Body>
<Content>
<Content onBlur={focusInput}>
<TrayPanel>
<div>
<p className='title-panel'>Add Component</p>
Expand Down Expand Up @@ -195,7 +195,7 @@ export default function ComponentsPanel(props: ComponentsPanelProps) {
})
}
</div>
<Accordion allowZeroExpanded onBlur={focusInput}>
<Accordion allowZeroExpanded>
{
category.filter((val) => {
if (searchTerm == "") {
Expand Down
10 changes: 4 additions & 6 deletions style/ComponentsPanel.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
}

.add-component-panel {
width: 250px;
height: 270px;
position: fixed;
z-index: 10;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
max-width: 250px;
max-height: 270px;
position: absolute;
z-index: 1000;
border-top: 10px;
border-color: #000;
border-radius: 12px;
overflow-y: auto;
}

.accordion__item_panel {
Expand Down
5 changes: 3 additions & 2 deletions style/NodeActionPanel.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.node-action-context-menu {
position: fixed;
z-index: 10;
position: absolute;
z-index: 1000;
max-width: 95px;
border-top: 10px;
border-color: #000;
border-radius: 12px;
Expand Down