Skip to content

Commit

Permalink
Fix up some Box code
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhamp committed Jan 15, 2024
1 parent ba1a78f commit 8e1f76a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
3 changes: 3 additions & 0 deletions src/Interfaces/Box.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

namespace SimonHamp\TheOg\Interfaces;

use Intervention\Image\Geometry\Point;
use Intervention\Image\Interfaces\ImageInterface;

interface Box
{
public function anchor(): Point;

public function name(string $name): static;

public function getName(): ?string;
Expand Down
21 changes: 9 additions & 12 deletions src/Layout/Box.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,32 @@

namespace SimonHamp\TheOg\Layout;

use Closure;
use Intervention\Image\Geometry\Point;
use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\Interfaces\ImageInterface;
use SimonHamp\TheOg\Interfaces\Box as BoxInterface;

readonly class Box implements BoxInterface
class Box implements BoxInterface
{
public Position $anchor;

public Rectangle $box;

public string $name;
public readonly string $name;

public Point $position;
public readonly Rectangle $renderedBox;

public readonly Point $position;

/**
* @var Closure<Box>
*/
public mixed $relativeTo;

public Position $relativeToPosition;

public Rectangle $renderedBox;
public readonly Closure $relativeTo;

public function box(int $width, int $height): self
public function box(int|float $width, int|float $height): self
{
$this->box = new Rectangle($width, $height);
$this->box = new Rectangle(intval(floor($width)), intval(floor($height)));
return $this;
}

Expand All @@ -39,15 +38,13 @@ public function position(
int $x,
int $y,
?callable $relativeTo = null,
Position $position = Position::TopLeft,
Position $anchor = Position::TopLeft
): self
{
$this->position = new Point($x, $y);

if ($relativeTo) {
$this->relativeTo = $relativeTo;
$this->relativeToPosition = $position;
}

$this->anchor = $anchor;
Expand Down
2 changes: 1 addition & 1 deletion src/Layout/TextBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use SimonHamp\TheOg\Interfaces\Font;
use SimonHamp\TheOg\Modifiers\TextModifier as CustomTextModifier;

readonly class TextBox extends Box
class TextBox extends Box
{
public ColorInterface $color;
public Font $font;
Expand Down

0 comments on commit 8e1f76a

Please sign in to comment.