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

graph editor: limit port label size and added on hover styles #186

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 20 additions & 4 deletions src/components/editor/controlNode.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FunctionComponent, memo } from "react";
import { EditorNodeProps, calcPortOffset } from "./util";
import { EditorNodeProps, calcPortOffset, defaultNodeWidth } from "./util";
import { GraphPortRecord, PortDirection } from "../../models/graph";
import EditorPort from "./port";
import classes from "./editor.module.css";
Expand All @@ -16,17 +16,33 @@ const EditorControlNode: FunctionComponent<EditorNodeProps> = memo(function Wrap
return result;
}, { sinks: [], sources: [] } as { sinks: GraphPortRecord[]; sources: GraphPortRecord[]; });

const portSizeLimit = sinks.length && sources.length ? Math.round(defaultNodeWidth / 2) : defaultNodeWidth;

return (
<Paper className={ classes.node } shadow="md" withBorder data-selected={ selected } >
<div className={ classes.nodeHeader } >
{ node.id }
</div>
<div className={ classes.nodeContent } style={{ height: `${node.contentHeight}px` }} >
<div className={ classes.nodeContent } style={{ height: `${node.contentHeight}px`, minWidth: defaultNodeWidth }} >
{
sinks.map((port, i) => <EditorPort key={ port.id } port={ port } offset={ calcPortOffset(sinks.length, i)}/>)
sinks.map((port, i) => (
<EditorPort
key={ port.id }
port={ port }
offset={ calcPortOffset(sinks.length, i)}
maxWidth={ portSizeLimit }
/>
))
}
{
sources.map((port, i) => <EditorPort key={ port.id } port={ port } offset={ calcPortOffset(sources.length, i) } />)
sources.map((port, i) => (
<EditorPort
key={ port.id }
port={ port }
offset={ calcPortOffset(sources.length, i) }
maxWidth={ portSizeLimit }
/>
))
}
</div>
</Paper>
Expand Down
94 changes: 52 additions & 42 deletions src/components/editor/editor.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,31 @@
flex: 1;

&[data-color-scheme="light"] {
.node {
background-color: var(--mantine-color-default-hover);
border-color: var(--mantine-color-gray-4);

&[data-selected="true"] {
border-color: var(--mantine-primary-color-filled);
}
}

.nodeHeader {
color: var(--mantine-color-default-color);
}
--node-background-color: var(--mantine-color-default-hover);
--node-border-color: var(--mantine-color-gray-4);
--node-border-color-selected: var(--mantine-primary-color-filled);
}

&[data-color-scheme="dark"] {
.node {
background-color: var(--mantine-color-default);
border-color: var(--mantine-color-gray-7);
--node-background-color: var(--mantine-color-default);
--node-border-color: var(--mantine-color-gray-7);
--node-border-color-selected: var(--mantine-primary-color-filled);
}

&[data-selected="true"] {
border-color: var(--mantine-primary-color-filled);
}
}
.node {
background-color: var(--node-background-color);
border-color: var(--node-border-color);

.nodeHeader {
color: var(--mantine-color-default-color);
&[data-selected="true"] {
border-color: var(--node-border-color-selected);
}
}

.nodeHeader {
color: var(--mantine-color-default-color);
}

:global {

.react-flow__attribution {
Expand Down Expand Up @@ -105,21 +101,54 @@
}

.react-flow__handle {

--label-offset: 24px;

&[data-c74-type="audio"] {
--handle-color: var(--mantine-color-green-outline);
}

&[data-c74-type="midi"] {
--handle-color: var(--mantine-color-orange-outline);
}

border: 2px solid var(--handle-color);
border-radius: 50%;
height: 20px;
width: 20px;

&:hover {
background-color: var(--handle-color);
}
}

.react-flow__handle-right,
.react-flow__handle-left {

&:before,
&:after {
background-clip: padding-box;
border-radius: var(--mantine-radius-sm);
font-size: var(--mantine-font-size-sm);
max-width: calc(var(--label-max-width) - var(--label-offset));
overflow: hidden;
padding: 0px 4px;
position: absolute;
text-overflow: ellipsis;
transform: translateY(-20%);
white-space: nowrap;
}

&:hover {

z-index: 50000;

&:before,
&:after {
background-color: var(--node-background-color);
box-shadow: var(--mantine-shadow-xs);
max-width: fit-content;
}
}
}

Expand All @@ -130,9 +159,8 @@

&:before {
content: attr(data-c74-name);
padding-right: 25px;
right: 0;
white-space: nowrap;
direction: rtl;
right: var(--label-offset);
}
}

Expand All @@ -142,25 +170,7 @@

&:after {
content: attr(data-c74-name);
padding-left: 25px;
left: 0;
white-space: nowrap;
}
}

.react-flow__handle[data-c74-type="audio"] {
border: 2px solid var(--mantine-color-green-outline);

&:hover {
background-color: var(--mantine-color-green-outline);
}
}

.react-flow__handle[data-c74-type="midi"] {
border: 2px solid var(--mantine-color-orange-outline);

&:hover {
background-color: var(--mantine-color-orange-outline);
left: var(--label-offset);
}
}
}
Expand Down
24 changes: 20 additions & 4 deletions src/components/editor/patcherNode.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FunctionComponent, memo } from "react";
import { EditorNodeProps, calcPortOffset } from "./util";
import { EditorNodeProps, calcPortOffset, defaultNodeWidth } from "./util";
import { GraphPatcherNodeRecord, GraphPortRecord, PortDirection } from "../../models/graph";
import EditorPort from "./port";
import classes from "./editor.module.css";
Expand All @@ -21,6 +21,8 @@ const EditorPatcherNode: FunctionComponent<EditorNodeProps> = memo(function Wrap
return result;
}, { sinks: [], sources: [] } as { sinks: GraphPortRecord[]; sources: GraphPortRecord[]; });

const portSizeLimit = sinks.length && sources.length ? Math.round(defaultNodeWidth / 2) : defaultNodeWidth;

return (
<Paper className={ classes.node } shadow="md" withBorder data-selected={ selected } >
<div className={ classes.nodeHeader } >
Expand All @@ -40,12 +42,26 @@ const EditorPatcherNode: FunctionComponent<EditorNodeProps> = memo(function Wrap
</Tooltip>
</div>
</div>
<div className={ classes.nodeContent } style={{ height: `${node.contentHeight}px` }} >
<div className={ classes.nodeContent } style={{ height: `${node.contentHeight}px`, minWidth: defaultNodeWidth }} >
{
sinks.map((port, i) => <EditorPort key={ port.id } port={ port } offset={ calcPortOffset(sinks.length, i)}/>)
sinks.map((port, i) => (
<EditorPort
key={ port.id }
port={ port }
offset={ calcPortOffset(sinks.length, i)}
maxWidth={ portSizeLimit }
/>
))
}
{
sources.map((port, i) => <EditorPort key={ port.id } port={ port } offset={ calcPortOffset(sources.length, i) } />)
sources.map((port, i) => (
<EditorPort
key={ port.id }
port={ port }
offset={ calcPortOffset(sources.length, i) }
maxWidth={ portSizeLimit }
/>
))
}
</div>
</Paper>
Expand Down
6 changes: 4 additions & 2 deletions src/components/editor/port.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { FunctionComponent, memo } from "react";
import React, { CSSProperties, FunctionComponent, memo } from "react";
import { GraphPortRecord, PortDirection } from "../../models/graph";
import { Handle, HandleType, Position } from "reactflow";

export type PortProps = {
offset: number;
alias?: string;
port: GraphPortRecord;
maxWidth: number;
};

const handleTypeByPortDirection: Record<PortDirection, HandleType> = {
Expand All @@ -20,6 +21,7 @@ const handlePositionByPortDirection: Record<PortDirection, Position> = {

const EditorPort: FunctionComponent<PortProps> = memo(function WrappedPort({
port,
maxWidth,
alias,
offset
}) {
Expand All @@ -31,7 +33,7 @@ const EditorPort: FunctionComponent<PortProps> = memo(function WrappedPort({
data-c74-type={ port.type }
data-c74-name={ (alias || port.id.replace(/\((capture|playback)_[0-9]+\)/, "")) }
type={ handleTypeByPortDirection[port.direction] }
style={{ top: `${offset}%` }}
style={{ top: `${offset}%`, "--label-max-width": `${maxWidth}px` } as CSSProperties }
/>
);
});
Expand Down
25 changes: 22 additions & 3 deletions src/components/editor/systemNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,36 @@ const EditorSystemNode: FunctionComponent<EditorNodeProps> = memo(function Wrapp
return alias.length > result ? alias.length : result;
}, 0);

const width = 300 + Math.max(0, (longestAliasCharCount - 10) * 5);
const portSizeLimit = sinks.length && sources.length ? Math.round(width / 2) : width;

return (
<Paper className={ classes.node } shadow="md" withBorder data-selected={ selected } >
<div className={ classes.nodeHeader } >
{ node.jackName }
</div>
<div className={ classes.nodeContent } style={{ height: `${node.contentHeight}px`, minWidth: `${300 + Math.max(0, (longestAliasCharCount - 10) * 5)}px` }} >
<div className={ classes.nodeContent } style={{ height: `${node.contentHeight}px`, minWidth: `${width}px` }} >
{
sinks.map((port, i) => <EditorPort key={ port.id } port={ port } offset={ calcPortOffset(sinks.length, i) } alias={ aliases.get(port.portName) } />)
sinks.map((port, i) => (
<EditorPort
key={ port.id }
port={ port }
offset={ calcPortOffset(sinks.length, i) }
alias={ aliases.get(port.portName) }
maxWidth={ portSizeLimit }
/>
))
}
{
sources.map((port, i) => <EditorPort key={ port.id } port={ port } offset={ calcPortOffset(sources.length, i) } alias={ aliases.get(port.portName) } />)
sources.map((port, i) => (
<EditorPort
key={ port.id }
port={ port }
offset={ calcPortOffset(sources.length, i) }
alias={ aliases.get(port.portName) }
maxWidth={ portSizeLimit }
/>
))
}
</div>
</Paper>
Expand Down
2 changes: 2 additions & 0 deletions src/components/editor/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ export type EditorEdgeProps = EdgeProps<EdgeDataProps>;
export const calcPortOffset = (total: number, index: number): number => {
return (index + 1) * (1 / (total + 1)) * 100;
};

export const defaultNodeWidth = 300;
Loading