Entrar
PT
apps/caramail-chat / src / Gui / AwtButton.php · commit 6eebcdb
<?phpnamespace App\Gui;use JumPHP\Gui\Button;use JumPHP\Gui\Theme;use JumPHP\Renderer\Renderer;/** java.awt.Button: grey and raised, pressed in when held, the text greyed and embossed when disabled. `background`: '#ffc800'... */final class AwtButton extends Button{    public const DEFAULTS = ['text' => 'Button', 'style' => 'default', 'image' => '', 'size' => null, 'background' => ''];    protected function content(Theme $t, float $maxWidth, string $breakpoint): array    {        $font = $t->font(12);        return [$font->width($this->tr((string)$this->props['text'])) + $t->px(24), $t->px(23)];    }    public function render(Renderer $r, Theme $t): void    {        $px = Awt::px($t);        $fill = $this->props['background'] !== '' ? (string)$this->props['background'] : Awt::$face;        $down = $this->pressed && $this->hovered && $this->isEnabled();        if ($this->focused && $this->isEnabled()) {            // the focused button of Windows: one more black line around            $r->drawRect($this->x, $this->y, $this->w, $this->h, Awt::DARK, $px);            Awt::raised($r, $this->x + $px, $this->y + $px, $this->w - 2 * $px, $this->h - 2 * $px, $fill, $down, $px);        } else {            Awt::raised($r, $this->x, $this->y, $this->w, $this->h, $fill, $down, $px);        }        $font = $t->font(12);        $text = $this->tr((string)$this->props['text']);        $x = $this->x + ($this->w - $font->width($text)) / 2 + ($down ? $px : 0);        $y = $this->y + ($this->h - $font->height()) / 2 + ($down ? $px : 0);        if ($this->isEnabled()) {            $font->draw($r, $text, $x, $y, 1, '#000000');        } else {            Awt::disabledText($r, $t, $font, $text, $x, $y);        }    }}