Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a nice battery that is similar to the one in ios 16 #84

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
improve: the battery's positive term is now sharper.
  • Loading branch information
1fadi committed Apr 19, 2023
commit 39b417eedb87a22e9418004777593a1fee9c0c62
33 changes: 19 additions & 14 deletions ibattery.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,17 @@ def draw_battery(self, percent, charging):
y_margin,
width=self.BAR_WIDTH,
height=self.HEIGHT,
linewidth=1
linewidth=1,
aspect=0.8
)
self.drawer.set_source_rgb(self.foreground)
self._border(
1 + self.padding,
y_margin,
width=self.BAR_WIDTH,
height=self.HEIGHT,
linewidth=2.6
linewidth=2.6,
aspect=0.8
)
if percent <= self.warn_below:
self.drawer.set_source_rgb(self.low_foreground)
Expand All @@ -166,23 +168,26 @@ def draw_battery(self, percent, charging):
y_margin,
width=max(PERCENT, self.BAR_WIDTH / 100 * 10),
height=self.HEIGHT,
linewidth=1
linewidth=1,
aspect=0.8
)
self.drawer.set_source_rgb("000000")
self._border(
1 + self.padding,
y_margin,
width=self.BAR_WIDTH,
height=self.HEIGHT,
linewidth=0.6
linewidth=0.6,
aspect=0.8
)
self.drawer.set_source_rgb(self.foreground)
self._fill_body(
self.BAR_WIDTH - 2 + self.padding,
y_margin + 1,
width=8.3,
height=self.HEIGHT - 2,
linewidth=5
y_margin + 1.5,
width=7.5,
height=self.HEIGHT - 3,
linewidth=5,
aspect=5.0
)
self.drawer.ctx.select_font_face(
"sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD
Expand Down Expand Up @@ -213,8 +218,8 @@ def get_bat(self):
percent = int(battery.percent)
return (percent, plugged)

def _rounded_body(self, x, y, width, height, linewidth):
aspect = 0.8
def _rounded_body(self, x, y, width, height, linewidth, aspect):
aspect = aspect
corner_radius = height / 5.0
radius = corner_radius / aspect
degrees = math.pi / 180.0
Expand Down Expand Up @@ -252,13 +257,13 @@ def _rounded_body(self, x, y, width, height, linewidth):
)
self.drawer.ctx.close_path()

def _border(self, x, y, width, height, linewidth):
self._rounded_body(x, y, width, height, linewidth)
def _border(self, x, y, width, height, linewidth, aspect):
self._rounded_body(x, y, width, height, linewidth, aspect)
self.drawer.ctx.set_line_width(linewidth)
self.drawer.ctx.stroke()

def _fill_body(self, x, y, width, height, linewidth):
self._rounded_body(x, y, width, height, linewidth)
def _fill_body(self, x, y, width, height, linewidth, aspect):
self._rounded_body(x, y, width, height, linewidth, aspect)
self.drawer.ctx.fill()

def timer_setup(self):
Expand Down