<?phpnamespace App\Gui;use JumPHP\Gui\ComboBox;use JumPHP\Gui\Theme;use JumPHP\Renderer\Renderer;/** * java.awt.Choice: a white field in a sunken bevel with a raised button and its arrow at the right; its list opens * under it (the engine's). `size`: the font in px (the applet's colour and size choices were in 10 pt). */final class AwtChoice extends ComboBox{ public const DEFAULTS = ['items' => [], 'selected' => -1, 'placeholder' => '', 'rows' => 12, 'size' => 12]; protected function content(Theme $t, float $maxWidth, string $breakpoint): array { $font = $t->font((float)$this->props['size']); $w = 0; foreach ((array)$this->props['items'] as $item) { $w = max($w, $font->width((string)$item)); } return [$w + $t->px(8 + 17), $t->px(21)]; } public function render(Renderer $r, Theme $t): void { $px = Awt::px($t); $r->fillRect($this->x, $this->y, $this->w, $this->h, $this->isEnabled() ? '#ffffff' : Awt::$face); Awt::sunken($r, $this->x, $this->y, $this->w, $this->h, $px); $font = $t->font((float)$this->props['size']); $value = (string)($this->value() ?? ''); $bw = $t->px(16); $inner = $this->h - 4 * $px; if ($this->focused && $this->isEnabled()) { $r->fillRect($this->x + 2 * $px, $this->y + 2 * $px, $this->w - $bw - 4 * $px, $inner, '#000080'); } $tx = $this->x + $t->px(4); $ty = $this->y + ($this->h - $font->height()) / 2; if ($this->isEnabled()) { $font->draw($r, $value, $tx, $ty, 1, $this->focused ? '#ffffff' : '#000000'); } else { Awt::disabledText($r, $t, $font, $value, $tx, $ty); } $bx = $this->x + $this->w - 2 * $px - $bw; Awt::raised($r, $bx, $this->y + 2 * $px, $bw, $inner, Awt::$face, $this->open, $px); Awt::arrow($r, $bx + $bw / 2 + ($this->open ? $px : 0), $this->y + $this->h / 2 + ($this->open ? $px : 0), 'down', $px, $this->isEnabled() ? Awt::DARK : Awt::SHADOW); }}