Skip to content

Commit

Permalink
region attribute of Gadget made private.
Browse files Browse the repository at this point in the history
  • Loading branch information
salt-die committed Feb 21, 2024
1 parent d02a353 commit dbe52e6
Show file tree
Hide file tree
Showing 18 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion examples/advanced/hack/hack/effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Darken(Gadget):

def _render(self, canvas):
super()._render(canvas)
for rect in self.region.rects():
for rect in self._region.rects():
s = rect.to_slices()
canvas["fg_color"][s] >>= 1
canvas["bg_color"][s] >>= 1
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/minesweeper/minesweeper/minefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def _game_over(self, win: bool):

def _render(self, canvas):
abs_pos = self.absolute_pos
for rect in self.region.rects():
for rect in self._region.rects():
dst = rect.to_slices()
src = rect.to_slices(abs_pos)
visible = self.hidden[src] != 0
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/tetris/tetris/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _render(self, canvas):
super()._render(canvas)
glow = self._glow
abs_pos = self.absolute_pos
for rect in self.region.rects():
for rect in self._region.rects():
dst_y, dst_x = rect.to_slices()
src_y, src_x = rect.to_slices(abs_pos)

Expand Down
2 changes: 1 addition & 1 deletion src/batgrl/gadgets/_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, fg_color: Color = WHITE, bg_color: Color = BLACK, **kwargs):

def _render(self, canvas: NDArray[Cell]):
"""Render visible region of gadget."""
for rect in self.region.rects():
for rect in self._region.rects():
dst = rect.to_slices()
canvas[dst]["fg_color"] = self.fg_color
canvas[dst]["bg_color"] = self.bg_color
10 changes: 5 additions & 5 deletions src/batgrl/gadgets/_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ def _render(self):
# geometry has been static for some time.

with self._render_lock:
self.region = Region.from_rect(self.pos, self.size)
self._region = Region.from_rect(self.pos, self.size)

for child in self.walk():
child.region = (
child.parent.region
child._region = (
child.parent._region
& Region.from_rect(child.absolute_pos, child.size)
if child.is_enabled and child.is_visible
else Region()
Expand All @@ -102,9 +102,9 @@ def _render(self):
if self.render_mode == "regions":
for child in self.walk_reverse():
if child.is_enabled:
child.region &= self.region
child._region &= self._region
if child.is_visible and not child.is_transparent:
self.region -= child.region
self._region -= child._region

self.canvas, self._last_canvas = self._last_canvas, self.canvas

Expand Down
12 changes: 6 additions & 6 deletions src/batgrl/gadgets/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,15 @@ def __init__(
self._animation_task = None

@property
def region(self) -> Region:
def _region(self) -> Region:
"""The visible portion of the gadget on the screen."""
return self._region
return self._region_value

@region.setter
def region(self, region: Region):
self._region = region
@_region.setter
def _region(self, region: Region):
self._region_value = region
for frame in self.frames:
frame.region = region
frame._region = region

def on_remove(self):
"""Pause animation."""
Expand Down
2 changes: 1 addition & 1 deletion src/batgrl/gadgets/bar_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def __init__(

@property
def is_transparent(self) -> bool:
"""A transparent gadget allows regions beneath it to be painted."""
"""Whether gadget is transparent."""
return self._container.is_transparent

@is_transparent.setter
Expand Down
2 changes: 1 addition & 1 deletion src/batgrl/gadgets/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def set_text(self, text: str, **kwargs):
class _AlmostPane(Pane):
def _render(self, canvas):
console: Console = self.parent.parent
self.region -= console._input.region
self._region -= console._input._region
super()._render(canvas)


Expand Down
2 changes: 1 addition & 1 deletion src/batgrl/gadgets/data_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def on_release(self):
class _FauxPane(Pane):
def _render(self, canvas):
data_table: DataTable = self.parent.parent
self.region -= data_table._table.region
self._region -= data_table._table._region
super()._render(canvas)


Expand Down
6 changes: 3 additions & 3 deletions src/batgrl/gadgets/gadget.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def __init__(
self.is_visible = is_visible
self.is_enabled = is_enabled

self.region: Region = Region()
self._region: Region = Region()
"""The visible portion of the gadget on the screen."""

def __repr__(self):
Expand Down Expand Up @@ -866,8 +866,8 @@ def collides_point(self, point: Point) -> bool:
if not self.is_visible or not self.is_enabled:
return False

return point in self.region or any(
point in child.region
return point in self._region or any(
point in child._region
for child in self.walk()
if child.is_visible or child.is_enabled
)
Expand Down
2 changes: 1 addition & 1 deletion src/batgrl/gadgets/graphic_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def _render(self, canvas: NDArray[Cell]):
offy, offx = self.absolute_pos
ppos = self.particle_positions
pcolors = self.particle_colors
for rect in self.region.rects():
for rect in self._region.rects():
height = rect.bottom - rect.top
width = rect.right - rect.left
pos = ppos - (rect.top - offy, rect.left - offx)
Expand Down
2 changes: 1 addition & 1 deletion src/batgrl/gadgets/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def _render(self, canvas: NDArray[Cell]):
background = canvas["bg_color"]
abs_pos = self.absolute_pos
alpha = self.alpha
for rect in self.region.rects():
for rect in self._region.rects():
dst = rect.to_slices()
src_y, src_x = rect.to_slices(abs_pos)
fg_rect = foreground[dst]
Expand Down
2 changes: 1 addition & 1 deletion src/batgrl/gadgets/pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def _render(self, canvas: NDArray[Cell]):
styles = canvas[["bold", "italic", "underline", "strikethrough", "overline"]]
foreground = canvas["fg_color"]
background = canvas["bg_color"]
for rect in self.region.rects():
for rect in self._region.rects():
dst = rect.to_slices()
fg_rect = foreground[dst]
bg_rect = background[dst]
Expand Down
12 changes: 6 additions & 6 deletions src/batgrl/gadgets/parallax.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,15 @@ def __init__(
self._vertical_offset = self._horizontal_offset = 0.0

@property
def region(self) -> Region:
def _region(self) -> Region:
"""The visible portion of the gadget on the screen."""
return self._region
return self._region_value

@region.setter
def region(self, region: Region):
self._region = region
@_region.setter
def _region(self, region: Region):
self._region_value = region
for layer in self.layers:
layer.region = region
layer._region = region

def on_size(self):
"""Resize parallax layers."""
Expand Down
2 changes: 1 addition & 1 deletion src/batgrl/gadgets/scroll_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def alpha(self, alpha: float):

@property
def is_transparent(self) -> bool:
"""A transparent gadget allows regions beneath it to be painted."""
"""Whether gadget is transparent."""
return self._background.is_transparent

@is_transparent.setter
Expand Down
2 changes: 1 addition & 1 deletion src/batgrl/gadgets/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def _render(self, canvas: NDArray[Cell]):
text_bg = self.canvas["bg_color"]
abs_pos = self.absolute_pos
alpha = self.alpha
for rect in self.region.rects():
for rect in self._region.rects():
dst = rect.to_slices()
src = rect.to_slices(abs_pos)
if self.is_transparent:
Expand Down
2 changes: 1 addition & 1 deletion src/batgrl/gadgets/text_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def _render(self, canvas: NDArray[Cell]):
ppos = self.particle_positions
pchars = self.particle_cells[cell_sans("bg_color")]
pbg_color = self.particle_cells["bg_color"]
for rect in self.region.rects():
for rect in self._region.rects():
height = rect.bottom - rect.top
width = rect.right - rect.left
pos = ppos - (rect.top - offy, rect.left - offx)
Expand Down
2 changes: 1 addition & 1 deletion src/batgrl/gadgets/textbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _render(self, canvas):
textbox: Textbox = self.parent
if textbox.hide_input:
hider_rect = Region.from_rect(self.absolute_pos, (1, textbox._line_length))
hider_region = self.region & hider_rect
hider_region = self._region & hider_rect
for rect in hider_region.rects():
canvas["char"][rect.to_slices()] = textbox.hide_char

Expand Down

0 comments on commit dbe52e6

Please sign in to comment.