use const for default values, use namespace

This commit is contained in:
yggverse 2024-07-21 19:35:41 +03:00
parent 8a622ec335
commit c985cf20af
20 changed files with 157 additions and 130 deletions

View file

@ -24,7 +24,7 @@ class Content
public Viewport $viewport;
// Defaults
private int $_margin = 8;
public const MARGIN = 8;
// Extras
private ?string $_source = null;
@ -38,15 +38,15 @@ class Content
$this->gtk = new \GtkScrolledWindow;
$this->gtk->set_margin_start(
$this->_margin
$this::MARGIN
);
$this->gtk->set_margin_end(
$this->_margin
$this::MARGIN
);
$this->gtk->set_margin_bottom(
$this->_margin
$this::MARGIN
);
// Init scrolled window viewport

View file

@ -25,7 +25,7 @@ class Navbar
public Request $request;
// Defaults
private int $_margin = 8;
public const MARGIN = 8;
public function __construct(
Page $page
@ -39,23 +39,23 @@ class Navbar
);
$this->gtk->set_margin_top(
$this->_margin
$this::MARGIN
);
$this->gtk->set_margin_bottom(
$this->_margin
$this::MARGIN
);
$this->gtk->set_margin_start(
$this->_margin
$this::MARGIN
);
$this->gtk->set_margin_end(
$this->_margin
$this::MARGIN
);
$this->gtk->set_spacing(
$this->_margin
$this::MARGIN
);
// Append base button

View file

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace Yggverse\Yoda\Entity\Browser\Container\Page;
use \Yggverse\Yoda\Entity\Browser\Container\Page;
use \Yggverse\Yoda\Entity\Browser\Container\Page\Response\Query;
use \Yggverse\Yoda\Entity\Browser\Container\Page\Response\Send;
@ -14,17 +16,18 @@ class Response
public \GtkBox $gtk;
// Dependencies
public \Yggverse\Yoda\Entity\Browser\Container\Page $page;
public Page $page;
// Requirements
public \Yggverse\Yoda\Entity\Browser\Container\Page\Response\Query $query;
public \Yggverse\Yoda\Entity\Browser\Container\Page\Response\Send $send;
public Query $query;
public Send $send;
// Defaults
private int $_margin = 8;
public const MARGIN = 8;
public const SPACING = 8;
public function __construct(
\Yggverse\Yoda\Entity\Browser\Container\Page $page
Page $page
) {
// Init dependencies
$this->page = $page;
@ -35,23 +38,23 @@ class Response
);
$this->gtk->set_margin_top(
$this->_margin
$this::MARGIN
);
$this->gtk->set_margin_bottom(
$this->_margin
$this::MARGIN
);
$this->gtk->set_margin_start(
$this->_margin
$this::MARGIN
);
$this->gtk->set_margin_end(
$this->_margin
$this::MARGIN
);
$this->gtk->set_spacing(
$this->_margin
$this::SPACING
);
// Init query field

View file

@ -17,11 +17,11 @@ class Title
public Page $page;
// Defaults
private int $_ellipsize = 3;
private int $_length = 16;
private string $_value = 'New page';
private string $_subtitle = '';
private string $_tooltip = '';
public const ELLIPSIZE = 3;
public const LENGTH = 16;
public const VALUE = 'New page';
public const SUBTITLE = '';
public const TOOLTIP = '';
public function __construct(
Page $page,
@ -31,15 +31,15 @@ class Title
// Init container
$this->gtk = new \GtkLabel(
$this->_value
$this::VALUE
);
$this->gtk->set_width_chars(
$this->_length
$this::LENGTH
);
$this->gtk->set_ellipsize(
$this->_ellipsize
$this::ELLIPSIZE
);
}
@ -58,7 +58,7 @@ class Title
);
$this->setTooltip(
is_null($tooltip) ? (mb_strlen(strval($value)) > $this->_length ? $value : null)
is_null($tooltip) ? (mb_strlen(strval($value)) > $this::LENGTH ? $value : null)
: $tooltip
);
}
@ -68,7 +68,7 @@ class Title
): void
{
$this->gtk->set_text(
is_null($value) ? _($this->_value) : trim(
is_null($value) ? _($this::VALUE) : trim(
$value
)
);
@ -78,7 +78,7 @@ class Title
?string $subtitle = null
): void
{
$this->subtitle = is_null($subtitle) ? _($this->_subtitle) : strtolower(
$this->subtitle = is_null($subtitle) ? _($this::SUBTITLE) : strtolower(
trim(
$subtitle
)
@ -90,7 +90,7 @@ class Title
): void
{
$this->gtk->set_tooltip_text(
is_null($tooltip) ? _($this->_tooltip) : trim(
is_null($tooltip) ? _($this::TOOLTIP) : trim(
$tooltip
)
);