<?phpnamespace App\Gui;use JumPHP\Gui\Container;use JumPHP\Gui\Theme;use JumPHP\Renderer\Renderer;/** * The applet's titled panel (net.spray.chat.a.a): an etched line around, its title in Helvetica 12 cut into the top * line ("Dialogue", "Membres du salon"...). A column (or row) container: its children are laid out inside. */final class Etched extends Container{ public const DEFAULTS = ['layout' => 'column', 'gap' => 4, 'padding' => 6, 'justify' => 'start', 'wrap' => false, 'columns' => 12, 'title' => '', 'caption' => '', 'border' => false, 'background' => '', 'scroll' => false, 'items' => 'stretch']; /** The room the title takes above the padding (the applet's insets: 16 on top, 6 around). */ private const TOP = 10; public function __construct(array $props = []) { // the title is drawn here, not by the container (which would keep a whole line for it) $props['caption'] = $props['caption'] ?? ($props['title'] ?? ''); $props['title'] = ''; parent::__construct($props); } protected function content(Theme $t, float $maxWidth, string $breakpoint): array { [$w, $h] = parent::content($t, $maxWidth, $breakpoint); return [$w, $h + $t->px(self::TOP)]; } public function layout(Theme $t, float $x, float $y, float $w, float $h, string $breakpoint): void { parent::layout($t, $x, $y + $t->px(self::TOP), $w, $h - $t->px(self::TOP), $breakpoint); $this->y = $y; $this->h = $h; } public function render(Renderer $r, Theme $t): void { $px = Awt::px($t); $font = $t->font(12); $title = $this->tr((string)$this->props['caption']); $lineY = $this->y + ($title === '' ? 0 : $font->height() / 2); Awt::etched($r, $this->x, $lineY, $this->w, $this->y + $this->h - $lineY, $px); if ($title !== '') { $r->fillRect($this->x + $t->px(8), $lineY - $t->px(1), $font->width($title) + $t->px(6), $t->px(3), Awt::$face); $font->draw($r, $title, $this->x + $t->px(11), $this->y, 1, '#000000'); } foreach ($this->children as $child) { if ($child->props['visible']) { $child->render($r, $t); } } } public function renderOverlay(Renderer $r, Theme $t): void { foreach ($this->children as $child) { if ($child->props['visible']) { $child->renderOverlay($r, $t); } } }}