<?phpnamespace Tests;use App\Form\LyricsEditorForm;use JumPHP\Gui\ListBox;use JumPHP\Gui\TextBox;use JumPHP\Gui\Widget;/** Long lyrics in the editor: both panels stay inside the window and scroll, the buttons under them stay in sight. */final class LyricsEditorLayoutTest extends PlayerTestCase{ private const LINES = 80; protected function tearDown(): void { $this->resize(900, 860); parent::tearDown(); } /** * A window of the computer of this size, at one screen pixel per dp: the headless surface has one size, so the view * stops following it (the view of a window that is not 'window') and is made that size. */ private function resize(int $width, int $height): void { $config = $this->game->engine->config; $values = new \ReflectionProperty($config, 'values'); $all = $values->getValue($config); $all['view'] = $width === 900 && $height === 860 ? 'window' : 'fixed'; $values->setValue($config, $all); $this->game->engine->sdl->getRenderer()->resizeView($width, $height); $this->game->run(2); } private function openWithLongLyrics(int $width, int $height): LyricsEditorForm { $this->startPlayer(); $this->wz->playIndex(1); // archettes-city: no lyrics $this->resize($width, $height); $this->form->openLyricsEditor(); $this->game->run(2); $editor = $this->game->scene(); self::assertInstanceOf(LyricsEditorForm::class, $editor); $lines = []; for ($i = 1; $i <= self::LINES; $i++) { $lines[] = "Ligne $i : chill out, what you yelling for, lay back, it's all been done before"; } $editor->widget('text')->text = implode("\n", $lines); $this->game->run(2); self::assertCount(self::LINES, $editor->widget('synced')->props['items']); return $editor; } private static function assertInside(Widget $w, float $width, float $height, string $what): void { self::assertGreaterThanOrEqual(0, $w->y, "$what: top inside the window"); self::assertLessThanOrEqual($height + 0.5, $w->y + $w->h, "$what: bottom inside the window ({$w->y} + {$w->h} > $height)"); self::assertLessThanOrEqual($width + 0.5, $w->x + $w->w, "$what: right edge inside the window"); } /** @return list<array{0: int, 1: int}> */ public static function sizes(): array { return [[1200, 870], [800, 600]]; } #[\PHPUnit\Framework\Attributes\DataProvider('sizes')] public function testLongLyricsStayInsideTheWindowAndScroll(int $width, int $height): void { $editor = $this->openWithLongLyrics($width, $height); $text = $editor->widget('text'); $list = $editor->widget('synced'); self::assertInstanceOf(TextBox::class, $text); self::assertInstanceOf(ListBox::class, $list); $this->game->shot("lyrics-editor-long-{$width}x{$height}"); self::assertInside($text, $width, $height, 'the lyrics'); self::assertInside($list, $width, $height, 'the synchronisation list'); foreach (['start', 'stamp', 'quit', 'save', 'sylStamp', 'strip', 'status'] as $id) { self::assertInside($editor->widget($id), $width, $height, $id); } self::assertLessThanOrEqual($editor->widget('strip')->y, $list->y + $list->h, 'the list above the syllables'); // the buttons: each as wide as its text, none over another, all inside $buttons = ['sylStamp', 'm100', 'm10', 'p10', 'p100', 'replay', 'estimate', 'start', 'stamp', 'back', 'pause', 'clear', 'save', 'publish', 'quit']; foreach ($buttons as $i => $a) { $wa = $editor->widget($a); self::assertInside($wa, $width, $height, $a); self::assertGreaterThanOrEqual($wa->measure($editor->theme, $width, 'md')[0] - 0.5, $wa->w, "$a: its whole text"); foreach (array_slice($buttons, $i + 1) as $b) { $wb = $editor->widget($b); $apart = $wa->x + $wa->w <= $wb->x + 0.5 || $wb->x + $wb->w <= $wa->x + 0.5 || $wa->y + $wa->h <= $wb->y + 0.5 || $wb->y + $wb->h <= $wa->y + 0.5; self::assertTrue($apart, "$a and $b side by side, not one over the other"); } } self::assertGreaterThan($height * 0.25, $list->h, 'the list takes the room left'); // the list scrolls with the wheel $editor->wheelAt($list->x + $list->w / 2, $list->y + $list->h / 2, -3); self::assertGreaterThan(0, $list->scrollY, 'the wheel scrolls the list'); // the lyrics too $editor->wheelAt($text->x + $text->w / 2, $text->y + $text->h / 2, -3); $this->game->run(1); self::assertGreaterThan(0, $this->game->peek('firstShown', $text), 'the wheel scrolls the lyrics'); // the sync goes down the song: the line to give stays in sight $editor->click($editor->widget('start')); $this->game->run(1); $list->scrollY = 0; for ($i = 0; $i < 60; $i++) { $editor->click($editor->widget('stamp')); $this->game->run(1); } self::assertSame(60, $list->selected); $rh = $list->rowHeight($editor->theme); self::assertGreaterThanOrEqual(60 * $rh, $list->scrollY + $list->h, 'the line to give is not under the bottom edge'); self::assertLessThanOrEqual(60 * $rh, $list->scrollY, 'nor over the top edge'); $this->game->shot("lyrics-editor-long-synced-{$width}x{$height}"); $this->wz->stop(); }}