L3-Bataille-Navale/source/gui/widget/base/BaseBoxWidget.py

48 lines
1 KiB
Python

from source.gui.widget.base import BaseWidget
from source.type import BBox
class BaseBoxWidget(BaseWidget):
def __init__(self, x: int, y: int, width: int, height: int):
self._x = x
self._y = y
self._width = width
self._height = height
# getter and setter, allow subclass to react when one of these value is changed
@property
def x(self):
return self._x
@x.setter
def x(self, x: int) -> None:
self._x = x
@property
def y(self):
return self._y
@y.setter
def y(self, y: int) -> None:
self._y = y
@property
def width(self):
return self._width
@width.setter
def width(self, width: int) -> None:
self._width = width
@property
def height(self):
return self._height
@height.setter
def height(self, height: int) -> None:
self._height = height
@property
def bbox(self) -> BBox:
return self.x, self.y, self.x + self.width, self.y + self.height