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

Show tooltips for keys with a shortName #188

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/components/three-fiber/unit-key/keycap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ export const Keycap: React.FC<ThreeFiberKeycapProps> = React.memo((props) => {
/>
</AniMeshMaterial>
</animated.mesh>
{(macroData || overflowsTexture) && (
{(macroData || overflowsTexture || (label && label.shortName)) && (
<React.Suspense fallback={null}>
<animated.group
position={props.position}
Expand Down
4 changes: 3 additions & 1 deletion src/components/two-string/unit-key/combo-keycap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ export const ComboKeycap = (props: any) => {
></TestOverlay>
) : null}
</ComboKeyBoundingContainer>
{(props.macroData || props.overflowsTexture) && (
{(props.macroData ||
props.overflowsTexture ||
(props.lablel && props.label.shortName)) && (
<TooltipContainer $rotate={props.rotation[2]}>
<Keycap2DTooltip>
{props.macroData || (props.label && props.label.tooltipLabel)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/two-string/unit-key/keycap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export const Keycap: React.FC<TwoStringKeycapProps> = React.memo((props) => {
<canvas ref={canvasRef} style={{}} />
</CanvasContainer>
</GlowContainer>
{(macroData || overflowsTexture) && (
{(macroData || overflowsTexture || (label && label.shortName)) && (
<TooltipContainer $rotate={rotation[2]}>
<Keycap2DTooltip>
{macroData || (label && label.tooltipLabel)}
Expand Down
10 changes: 10 additions & 0 deletions src/utils/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,16 @@ export function getShortNameForKeycode(keycode: IKeycode, size = 100) {
return name;
}

export function byteHasShortname(
byte: number,
basicKeyToByte: Record<string, number>,
byteToKey: Record<number, string>,
) {
const keycode = getCodeForByte(byte, basicKeyToByte, byteToKey);
const basicKeycode = keycodesList.find(({code}) => code === keycode);
return basicKeycode?.shortName;
}

export function getOtherMenu(
basicKeyToByte: Record<string, number>,
): IKeycodeMenu {
Expand Down
7 changes: 7 additions & 0 deletions src/utils/keyboard-rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
isArrowKey,
isMacroKeycodeByte,
getMacroKeycodeIndex,
byteHasShortname,
} from './key';

export const CSSVarObject = {
Expand Down Expand Up @@ -462,6 +463,7 @@ export const getLabel = (

// Full name
let tooltipLabel: string = '';
let shortName: string | undefined;
if (
isCustomKeycodeByte(keycodeByte, basicKeyToByte) &&
selectedDefinition?.customKeycodes &&
Expand All @@ -477,12 +479,16 @@ export const getLabel = (
selectedDefinition.customKeycodes[customKeycodeIdx] as IKeycode,
700,
);
shortName = (
selectedDefinition.customKeycodes[customKeycodeIdx] as IKeycode
).shortName;
} else if (keycodeByte) {
label =
getLabelForByte(keycodeByte, width * 100, basicKeyToByte, byteToKey) ??
'';
tooltipLabel =
getLabelForByte(keycodeByte, 700, basicKeyToByte, byteToKey) ?? '';
shortName = byteHasShortname(keycodeByte, basicKeyToByte, byteToKey);
}
let macroExpression: string | undefined;
if (isMacroKeycodeByte(keycodeByte, basicKeyToByte)) {
Expand Down Expand Up @@ -529,6 +535,7 @@ export const getLabel = (
key: (label || '') + (macroExpression || ''),
size: size,
offset: offset,
shortName,
};
}
};