Skip to content

Commit b6114c5

Browse files
authored
Merge pull request #213 from DmNote-App/fix/hitline
fix: 키 옆 요소가 만들던 오버레이 여백 제거
2 parents e396f13 + fd5dc53 commit b6114c5

5 files changed

Lines changed: 332 additions & 38 deletions

File tree

‎docs/content/en/api-reference/keys/page.mdx‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,12 @@ share the field. The logical box (`dx`/`dy`/`width`/`height`) stays axis
403403
aligned while the face, the note track, and the outside counter rotate
404404
together about the box center. Omitting the field means 0; `null`, non-finite
405405
values, and values outside `-180..180` are rejected. Automatic hitline
406-
correction (`noteAutoYCorrection`) aligns unrotated keys to the content top,
407-
and aligns rotated keys that flow in the same direction (within 0.5°) to the
408-
top edge that is furthest along that direction. A key rotated on its own
409-
starts at its own top edge, and note offsets apply after the correction.
406+
correction (`noteAutoYCorrection`) aligns unrotated keys to the top edge of
407+
the highest visible key, and aligns rotated keys that flow in the same
408+
direction (within 0.5°) to the top edge that is furthest along that
409+
direction. Other elements such as stats, graphs, and plugins do not move the
410+
start line. A key rotated on its own starts at its own top edge, and note
411+
offsets apply to their own key after the correction.
410412
Sprites also have an element-level placement `rotation`, independent of their
411413
idle and per-pose rotations. See [Sprite Position Types](/docs/api-reference/editor#sprite-position-types).
412414

‎docs/content/ko/api-reference/keys/page.mdx‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,11 @@ interface ElementShadowSpec {
235235
`dx`/`dy`/`width`/`height` 논리 상자는 축 정렬 그대로 두고 얼굴, 노트
236236
트랙, 외부 카운터가 상자 중심을 축으로 함께 돕니다. 생략하면 0이고
237237
`null`, 비유한값, `-180~180` 밖의 값은 거절됩니다. 자동 히트라인
238-
보정(`noteAutoYCorrection`)은 회전 0인 키는 콘텐츠 상단에, 회전한 키는
239-
같은 방향(각도 차 0.5° 이내)으로 도는 키끼리 가장 앞선 상변에 시작선을
240-
맞춥니다. 혼자 돌린 키는 자기 상변에서 시작하고 노트 오프셋은 그 뒤에
241-
적용됩니다. 스프라이트도 요소 배치용 `rotation`을 가지며 대기·자세별 회전과
238+
보정(`noteAutoYCorrection`)은 회전 0인 키는 보이는 키 중 가장 위 키의
239+
상변에, 회전한 키는 같은 방향(각도 차 0.5° 이내)으로 도는 키끼리 가장 앞선
240+
상변에 시작선을 맞춥니다. 통계·그래프·플러그인 같은 다른 요소는 시작선을
241+
옮기지 않습니다. 혼자 돌린 키는 자기 상변에서 시작하고 노트 오프셋은 그
242+
키에만 보정 뒤에 적용됩니다. 스프라이트도 요소 배치용 `rotation`을 가지며 대기·자세별 회전과
242243
독립적으로 적용합니다. [스프라이트 위치 타입](/docs/api-reference/editor#스프라이트-위치-타입)을 참고하세요.
243244

244245
```javascript

‎src/renderer/hooks/shared/useLayoutComputation.test.ts‎

Lines changed: 254 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,35 @@ describe('computeLayout 스프라이트 오버행', () => {
134134

135135
// 배경 박스는 콘텐츠 바운즈 기준 위치·크기 유지
136136
expect(layout.backgroundBox?.x).toBeCloseTo(41.4214, 3);
137-
expect(layout.backgroundBox?.y).toBeCloseTo(41.4214, 3);
138137
expect(layout.backgroundBox?.width).toBe(260);
139138
expect(layout.backgroundBox?.height).toBe(410);
140139

141140
// 아이템 오프셋은 창 바운즈 기준이라 콘텐츠가 여유만큼 안쪽으로 밀린다
142141
expect(layout.positionOffset.x).toBeCloseTo(30 - 58.5786, 3);
143-
expect(layout.positionOffset.y).toBeCloseTo(180 - 8.5786, 3);
144142
expect(layout.displaySpritePositions[0].dx).toBeCloseTo(71.4214, 3);
145-
146-
// 트랙 시작은 콘텐츠 상단을 따라간다
147-
expect(layout.topMostY).toBeCloseTo(221.4214, 3);
148-
// 왼쪽 오버행도 같은 방식 - 네이티브 x 보정이 이 delta를 소비한다
143+
// 위쪽 오버행 41.42는 트랙 밴드(150) 안이라 창을 위로 키우지 않는다
144+
expect(layout.positionOffset.y).toBe(130);
145+
expect(layout.backgroundBox?.y).toBe(0);
146+
expect(layout.topMostY).toBe(180);
147+
// 왼쪽 오버행 - 네이티브 x 보정이 이 delta를 소비한다
149148
expect(layout.leftMostX).toBeCloseTo(71.4214, 3);
150149
});
151150

151+
it('트랙 밴드를 넘는 위쪽 오버행만 창을 위로 키우고 원점 보정 delta가 된다', () => {
152+
const layout = computeLayout({
153+
...makeInput([
154+
makeSprite({ idleTransform: makeTransform({ rotation: 45 }) }),
155+
]),
156+
trackHeight: 20,
157+
});
158+
// 밴드 상단 30보다 오버행 상단 8.58이 더 위
159+
expect(layout.positionOffset.y).toBeCloseTo(30 - 8.5786, 3);
160+
expect(layout.backgroundBox?.y).toBeCloseTo(21.4214, 3);
161+
expect(layout.backgroundBox?.height).toBe(280);
162+
// 밴드 아래 콘텐츠 상단(50)의 창 좌표가 오버행만큼 내려간다
163+
expect(layout.topMostY).toBeCloseTo(71.4214, 3);
164+
});
165+
152166
it('이미지 없는 스프라이트는 회전해도 창을 넓히지 않는다', () => {
153167
const layout = computeLayout(
154168
makeInput([
@@ -705,3 +719,237 @@ describe('computeLayout 회전 키 자동 시작선 세부', () => {
705719
expect(layout.contentSize?.height).toBeLessThan(1060 + 60 + 30);
706720
});
707721
});
722+
723+
describe('computeLayout 히트라인과 비키 요소', () => {
724+
// 노트 열은 x 0~240, 키 상변 y=300, 트랙 밴드는 y 0~300
725+
const makeInput = (
726+
extra: {
727+
plugins?: Array<{ x: number; y: number; width: number; height: number }>;
728+
stats?: Array<{ dx: number; dy: number; width: number; height: number }>;
729+
noteOffsetYA?: number;
730+
hideKeys?: boolean;
731+
rotation?: number;
732+
} = {},
733+
) => ({
734+
currentKeys: ['A', 'B', 'C', 'D'],
735+
currentPositions: ['A', 'B', 'C', 'D'].map(
736+
(id, index) =>
737+
({
738+
id,
739+
dx: index * 60,
740+
dy: 300,
741+
width: 60,
742+
height: 60,
743+
rotation: extra.rotation ?? 0,
744+
noteOffsetY: index === 0 ? extra.noteOffsetYA : undefined,
745+
hidden: extra.hideKeys,
746+
} as never),
747+
),
748+
currentStatPositions: (extra.stats ?? []) as never[],
749+
currentGraphPositions: [],
750+
currentKnobPositions: [],
751+
currentSpritePositions: [],
752+
trackHeight: 300,
753+
noteSettings: DEFAULT_NOTE_SETTINGS,
754+
selectedKeyType: '4key',
755+
pluginElements: (extra.plugins ?? []).map((plugin) => ({
756+
position: { x: plugin.x, y: plugin.y },
757+
measuredSize: { width: plugin.width, height: plugin.height },
758+
})),
759+
});
760+
const tracksOf = (layout: ReturnType<typeof computeLayout>) =>
761+
layout.webglTracks as Array<{ position: { dx: number; dy: number } }>;
762+
const keyTopOf = (layout: ReturnType<typeof computeLayout>) =>
763+
(layout.displayPositions[0] as { dy: number }).dy;
764+
765+
it('키만 있으면 창은 키 + 트랙 높이 + 패딩이다', () => {
766+
const layout = computeLayout(makeInput());
767+
expect(layout.contentSize).toEqual({ width: 300, height: 420 });
768+
expect(keyTopOf(layout)).toBe(330);
769+
expect(tracksOf(layout)[0].position.dy).toBe(330);
770+
});
771+
772+
it('노트 열 밖 패널은 트랙 밴드 안에 있으면 창 높이를 키우지 않는다', () => {
773+
const layout = computeLayout(
774+
makeInput({ plugins: [{ x: 260, y: 100, width: 200, height: 260 }] }),
775+
);
776+
expect(layout.contentSize).toEqual({ width: 520, height: 420 });
777+
expect(keyTopOf(layout)).toBe(330);
778+
for (const track of tracksOf(layout)) {
779+
expect(track.position.dy).toBe(330);
780+
}
781+
});
782+
783+
it('노트 열 밖 패널을 밴드 안에서 옮겨도 키·시작선·창 기준점이 그대로다', () => {
784+
const upper = computeLayout(
785+
makeInput({ plugins: [{ x: 260, y: 50, width: 200, height: 260 }] }),
786+
);
787+
const lower = computeLayout(
788+
makeInput({ plugins: [{ x: 260, y: 150, width: 200, height: 260 }] }),
789+
);
790+
expect(keyTopOf(lower)).toBe(keyTopOf(upper));
791+
expect(tracksOf(lower)[0].position.dy).toBe(tracksOf(upper)[0].position.dy);
792+
expect(lower.topMostY).toBe(upper.topMostY);
793+
expect(lower.contentOrigin).toEqual(upper.contentOrigin);
794+
// 아래로 나간 만큼만 창이 아래로 자란다
795+
expect(lower.contentSize!.height - upper.contentSize!.height).toBe(50);
796+
});
797+
798+
it('밴드 위로 나간 열 밖 패널은 나간 만큼만 창을 키우고 노트는 키에서 시작한다', () => {
799+
const layout = computeLayout(
800+
makeInput({ plugins: [{ x: 260, y: -100, width: 200, height: 200 }] }),
801+
);
802+
expect(layout.contentSize!.height).toBe(360 + 100 + 60);
803+
expect(keyTopOf(layout)).toBe(430);
804+
expect(tracksOf(layout)[0].position.dy).toBe(430);
805+
});
806+
807+
it('노트 열 밖 통계 카운터도 같은 규칙을 따른다', () => {
808+
const layout = computeLayout(
809+
makeInput({ stats: [{ dx: 260, dy: 100, width: 60, height: 200 }] }),
810+
);
811+
expect(layout.contentSize).toEqual({ width: 380, height: 420 });
812+
expect(tracksOf(layout)[0].position.dy).toBe(keyTopOf(layout));
813+
});
814+
815+
// top-left 앵커는 topMostY delta만큼 창을 되당긴다 - 0이면 키가 화면에서 제자리
816+
const keyScreenShift = (
817+
before: ReturnType<typeof computeLayout>,
818+
after: ReturnType<typeof computeLayout>,
819+
) => keyTopOf(after) - keyTopOf(before) - (after.topMostY - before.topMostY);
820+
821+
it('패널이 밴드 안에 머무는 동안 트랙 높이를 바꾸면 키는 화면에서 제자리다', () => {
822+
const plugins = [{ x: 260, y: 150, width: 200, height: 210 }];
823+
const tall = computeLayout(makeInput({ plugins }));
824+
const short = computeLayout({
825+
...makeInput({ plugins }),
826+
trackHeight: 200,
827+
});
828+
expect(keyScreenShift(tall, short)).toBe(0);
829+
});
830+
831+
it('밴드 위로 나간 패널을 옮기면 창 원점은 그대로고 fixed-position만 따라간다', () => {
832+
const upper = computeLayout(
833+
makeInput({ plugins: [{ x: 260, y: -200, width: 200, height: 200 }] }),
834+
);
835+
const lower = computeLayout(
836+
makeInput({ plugins: [{ x: 260, y: -100, width: 200, height: 200 }] }),
837+
);
838+
// 창 위쪽을 정하는 요소의 이동은 기존처럼 창 원점 보정이 없다
839+
expect(lower.topMostY).toBe(upper.topMostY);
840+
expect(lower.contentOrigin!.y - upper.contentOrigin!.y).toBe(100);
841+
});
842+
843+
it('노트 효과를 끈 채 키 위에 요소가 있으면 키 배치가 달라져도 창 원점 보정이 없다', () => {
844+
// 탭 전환·키 이동처럼 키 상단만 다른 두 배치
845+
const stats = [{ dx: 260, dy: 100, width: 60, height: 60 }];
846+
const a = computeLayout({ ...makeInput({ stats }), trackHeight: 0 });
847+
const moved = makeInput({ stats });
848+
const b = computeLayout({
849+
...moved,
850+
currentPositions: moved.currentPositions.map(
851+
(pos) => ({ ...(pos as object), dy: 200 } as never),
852+
),
853+
trackHeight: 0,
854+
});
855+
expect(b.topMostY).toBe(a.topMostY);
856+
});
857+
858+
it('보이는 키가 있으면 숨긴 키의 위치는 창에 영향을 주지 않는다', () => {
859+
const base = makeInput({
860+
stats: [{ dx: 260, dy: 100, width: 60, height: 60 }],
861+
});
862+
const withHidden = computeLayout({
863+
...base,
864+
currentKeys: [...base.currentKeys, 'E'],
865+
currentPositions: [
866+
...base.currentPositions,
867+
{
868+
id: 'E',
869+
dx: 0,
870+
dy: -1000,
871+
width: 60,
872+
height: 60,
873+
hidden: true,
874+
} as never,
875+
],
876+
});
877+
const without = computeLayout(base);
878+
expect(withHidden.topMostY).toBe(without.topMostY);
879+
expect(withHidden.contentSize).toEqual(without.contentSize);
880+
expect(withHidden.contentOrigin).toEqual(without.contentOrigin);
881+
});
882+
883+
const sideExtra = {
884+
stats: [{ dx: 0, dy: 100, width: 60, height: 60 }],
885+
plugins: [{ x: 260, y: 100, width: 200, height: 260 }],
886+
};
887+
888+
it('노트 효과를 끈 채 키를 모두 숨겨도 남은 요소는 화면에서 제자리다', () => {
889+
const shown = computeLayout({ ...makeInput(sideExtra), trackHeight: 0 });
890+
const hidden = computeLayout({
891+
...makeInput({ ...sideExtra, hideKeys: true }),
892+
trackHeight: 0,
893+
});
894+
const statTopOf = (layout: ReturnType<typeof computeLayout>) =>
895+
(layout.displayStatPositions[0] as { dy: number }).dy;
896+
expect(
897+
statTopOf(hidden) - statTopOf(shown) - (hidden.topMostY - shown.topMostY),
898+
).toBe(0);
899+
});
900+
901+
it('키를 모두 숨기면 키가 없는 배치와 같고 숨긴 키 자리는 창을 넓히지 않는다', () => {
902+
const hidden = makeInput({ ...sideExtra, hideKeys: true });
903+
const withFarHidden = computeLayout({
904+
...hidden,
905+
currentKeys: [...hidden.currentKeys, 'E'],
906+
currentPositions: [
907+
...hidden.currentPositions,
908+
{
909+
id: 'E',
910+
dx: 0,
911+
dy: -1000,
912+
width: 60,
913+
height: 60,
914+
hidden: true,
915+
} as never,
916+
],
917+
});
918+
const noKeys = computeLayout({
919+
...hidden,
920+
currentKeys: [],
921+
currentPositions: [],
922+
});
923+
expect(withFarHidden.contentSize).toEqual(noKeys.contentSize);
924+
expect(withFarHidden.topMostY).toBe(noKeys.topMostY);
925+
expect(computeLayout(hidden).contentSize).toEqual(noKeys.contentSize);
926+
});
927+
928+
it.each([0.1, -0.1, 5])(
929+
'옆 패널이 밴드 안에 있을 때 키를 %s° 돌려도 키는 화면에서 제자리다',
930+
(rotation) => {
931+
const plugins = [{ x: 260, y: 100, width: 200, height: 260 }];
932+
const flat = computeLayout(makeInput({ plugins }));
933+
const tilted = computeLayout(makeInput({ plugins, rotation }));
934+
// 회전으로 밴드 예약이 꺼져도 트랙은 거의 같은 높이로 뻗는다
935+
expect(keyScreenShift(flat, tilted)).toBeCloseTo(0, 6);
936+
},
937+
);
938+
939+
it('밴드 밖 패널이 있어도 한 키의 노트 오프셋을 바꾸면 키는 화면에서 제자리다', () => {
940+
const plugins = [{ x: 260, y: -300, width: 200, height: 660 }];
941+
const before = computeLayout(makeInput({ plugins }));
942+
const after = computeLayout(makeInput({ plugins, noteOffsetYA: -100 }));
943+
expect(keyScreenShift(before, after)).toBe(0);
944+
});
945+
946+
it('음수 노트 Y 오프셋은 자기 키의 노트만 그만큼 올린다', () => {
947+
const layout = computeLayout(makeInput({ noteOffsetYA: -100 }));
948+
const [trackA, trackB] = tracksOf(layout);
949+
const keyTop = keyTopOf(layout);
950+
expect(trackA.position.dy).toBe(keyTop - 100);
951+
expect(trackB.position.dy).toBe(keyTop);
952+
// 오프셋 트랙 끝까지만 창이 자란다
953+
expect(layout.contentSize!.height).toBe(420 + 100);
954+
});
955+
});

0 commit comments

Comments
 (0)