/**
* Чистая логика курсора вертикального списка: без Pixi, тестируется изолированно.
* MenuList использует её для клавиатурной навигации.
*/
export class ListCursor {
/** Индекс выбранного элемента. */
index = 0;
constructor(private count: number) {}
/** Изменить количество элементов (список пересобран); курсор зажимается. */
setCount(count: number): void {
this.count = count;
if (this.index >= count) {
this.index = Math.max(0, count - 1);
}
}
move(delta: number): void {
if (this.count === 0) return;
this.index = (this.index + delta + this.count) % this.count;
}
/** Курсор в начало/конец. */
home(): void {
this.index = 0;
}
end(): void {
if (this.count > 0) this.index = this.count - 1;
}
/** Есть ли элементы. */
get empty(): boolean {
return this.count === 0;
}
}