Skip to content

Commit

Permalink
optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
fdev31 committed May 23, 2024
1 parent e98a759 commit 53d4ae4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/wlr_layout_ui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class UI(pyglet.window.Window):
"""Main class for the GUI. Handles the layout of the screens and the widgets."""

def __init__(self, width, height):
super().__init__(width, height, PROG_NAME, resizable=True)
super().__init__(width, height, PROG_NAME, resizable=True, vsync=True)
self.selected_item = None
self.scale_factor = 1
self.cursor_coords = (0, 0)
Expand Down
3 changes: 3 additions & 0 deletions src/wlr_layout_ui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ class Rect: # {{{
width: int
height: int

def __hash__(self):
return int("%d%d%d%d" % self.asTuple())

@property
def topleft(self):
return (self.left, self.top)
Expand Down
10 changes: 6 additions & 4 deletions src/wlr_layout_ui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

from .factories import makeLabel, makeRectangle
from .settings import FONT, WIDGETS_RADIUS
from .shapes import RoundedRectangle
from .shapes import makeRoundedRectangle
from .utils import Rect, brighten


class Widget:
"""Base class for all widgets."""

def __init__(self, rect, style):
self.rect = rect
self.style = style if style else Style()
Expand Down Expand Up @@ -51,7 +53,7 @@ def draw(self, cursor):
raise NotImplementedError()

def draw_shadow(self, offX=3, offY=3, color=(0, 0, 0, 80), radius=0):
r = RoundedRectangle(
r = makeRoundedRectangle(
Rect(
self.rect.x + offX,
self.rect.y - offY,
Expand Down Expand Up @@ -218,7 +220,7 @@ def draw(self, cursor):
if is_hovered:
color = brighten(color)

r = RoundedRectangle(self.rect, self.radius, color)
r = makeRoundedRectangle(self.rect, self.radius, color)
r.draw()
rect = self.rect

Expand Down Expand Up @@ -386,7 +388,7 @@ def draw(self, cursor):
if self.rect.contains(*cursor):
color = brighten(color)

r = RoundedRectangle(self.rect, self.radius, color)
r = makeRoundedRectangle(self.rect, self.radius, tuple(color))
r.draw()
self.text.draw()

Expand Down

0 comments on commit 53d4ae4

Please sign in to comment.