krakjoe / ui

Cross platform UI development in PHP
Other
518 stars 39 forks source link

Sets/gets background/foreground color of element, interface UI\Colourable #61

Closed WinterSilence closed 5 years ago

WinterSilence commented 5 years ago

interface UI\Colourable:

namespace UI;
use UI\Draw\Color;
interface Colourable
{
    public function setBackgroundColor(Color $color): self;
    public function getBackgroundColor(): Color;
    public function setForegroundColor(Color $color): self;
    public function getForegroundColor(): Color;
}

Class UI\Control:

namespace UI;
use UI\Draw\Color;
class Control implements Colourable
{
    protected $backgroundColor = 0x000000;
    protected $foregroundColor = 0xFFFFFF;

    public function setBackgroundColor(Color $color): self
    {
        $this->backgroundColor = $color;
        return $this;
    }
    public function getBackgroundColor()
    {
        if (is_int($this->backgroundColor)) {
            $this->backgroundColor = new Color($this->backgroundColor);
        }
        return $this->backgroundColor;
    }
    public function setForegroundColor(Color $color): self
    {
        $this->foregroundColor = $color;
        return $this;
    }
    public function getForegroundColor()
    {
        if (is_int($this->foregroundColor)) {
            $this->foregroundColor = new Color($this->foregroundColor);
        }
        return $this->foregroundColor;
    }
}

Class UI\Menu:

namespace UI;
use UI\Draw\Color;
class Menu implements Colourable
{
    protected $backgroundColor = 0x000000;
    protected $foregroundColor = 0xFFFFFF;

    public function setBackgroundColor(Color $color): self
    {
        $this->backgroundColor = $color;
        return $this;
    }
    public function getBackgroundColor()
    {
        if (is_int($this->backgroundColor)) {
            $this->backgroundColor = new Color($this->backgroundColor);
        }
        return $this->backgroundColor;
    }
    public function setForegroundColor(Color $color): self
    {
        $this->foregroundColor = $color;
        return $this;
    }
    public function getForegroundColor()
    {
        if (is_int($this->foregroundColor)) {
            $this->foregroundColor = new Color($this->foregroundColor);
        }
        return $this->foregroundColor;
    }
}