Render cold icon next to outside thermometer
This commit is contained in:
parent
4e8df79c5b
commit
5c1ea2face
1 changed files with 48 additions and 1 deletions
|
@ -11,7 +11,7 @@ from hexagram.speedo import Speedo
|
||||||
from hexagram.tacho import Tacho
|
from hexagram.tacho import Tacho
|
||||||
from hexagram.fuel import FuelGauge
|
from hexagram.fuel import FuelGauge
|
||||||
from hexagram.thermo import Thermometer
|
from hexagram.thermo import Thermometer
|
||||||
from hexagram.status import StatusIconBox
|
from hexagram.status import VehicleStatus, StatusIcon, StatusIconBox
|
||||||
|
|
||||||
class ShiftIndicator(Gauge):
|
class ShiftIndicator(Gauge):
|
||||||
__slots__ = 'x', 'y', 'rpm_min', 'rpm_redline', 'rpm_max',
|
__slots__ = 'x', 'y', 'rpm_min', 'rpm_redline', 'rpm_max',
|
||||||
|
@ -95,14 +95,61 @@ class Odometer(TextGauge):
|
||||||
return "%.1f mi" % self.value
|
return "%.1f mi" % self.value
|
||||||
|
|
||||||
class AmbientTemp(TextGauge):
|
class AmbientTemp(TextGauge):
|
||||||
|
__slots__ = 'icon',
|
||||||
|
|
||||||
|
ICON_WIDTH = 40
|
||||||
|
ICON_HEIGHT = 40
|
||||||
|
ICON_PADDING = 16
|
||||||
|
ICON_COLOR = '#fff'
|
||||||
|
|
||||||
|
COLD_THRESHOLD = 4.0 # °C
|
||||||
|
|
||||||
def __init__(self, x: float, y: float, align: Align):
|
def __init__(self, x: float, y: float, align: Align):
|
||||||
super().__init__(x, y, -100, 100, align)
|
super().__init__(x, y, -100, 100, align)
|
||||||
|
|
||||||
self.value = 0
|
self.value = 0
|
||||||
|
self.icon = StatusIcon(VehicleStatus.COLD,
|
||||||
|
'cold',
|
||||||
|
self.ICON_WIDTH,
|
||||||
|
self.ICON_HEIGHT,
|
||||||
|
self.ICON_COLOR,
|
||||||
|
'path {stroke: %(s)s;stroke-width: 8}')
|
||||||
|
|
||||||
def format_text(self):
|
def format_text(self):
|
||||||
return "%.1f°C" % self.value
|
return "%.1f°C" % self.value
|
||||||
|
|
||||||
|
def draw_fg(self, cr: cairo.Context):
|
||||||
|
cr.select_font_face(self.FONT_FACE,
|
||||||
|
self.FONT_SLANT,
|
||||||
|
self.FONT_WEIGHT)
|
||||||
|
|
||||||
|
text = self.format_text()
|
||||||
|
|
||||||
|
cr.set_font_size(self.FONT_SIZE)
|
||||||
|
|
||||||
|
extents = cr.text_extents(text)
|
||||||
|
width = extents[2] - extents[0]
|
||||||
|
|
||||||
|
if self.value <= self.COLD_THRESHOLD:
|
||||||
|
width += self.icon.width + self.ICON_PADDING
|
||||||
|
|
||||||
|
if self.align is Align.LEFT:
|
||||||
|
text_x_offset = 0.0
|
||||||
|
elif self.align is Align.MIDDLE:
|
||||||
|
text_x_offset = self.x - width / 2.0
|
||||||
|
elif self.align is Align.RIGHT:
|
||||||
|
text_x_offset = self.x - width
|
||||||
|
|
||||||
|
cr.set_source_rgb(1, 1, 1)
|
||||||
|
cr.move_to(text_x_offset, self.y)
|
||||||
|
cr.show_text(text)
|
||||||
|
|
||||||
|
icon_y_offset = abs(self.icon.height - self.FONT_SIZE) * 2
|
||||||
|
|
||||||
|
self.icon.draw(cr,
|
||||||
|
text_x_offset + width - self.icon.width,
|
||||||
|
self.y - icon_y_offset)
|
||||||
|
|
||||||
class Clock(TextGauge):
|
class Clock(TextGauge):
|
||||||
def __init__(self, x: float, y: float, align: Align):
|
def __init__(self, x: float, y: float, align: Align):
|
||||||
super().__init__(x, y, 0, 9999, align)
|
super().__init__(x, y, 0, 9999, align)
|
||||||
|
|
Loading…
Add table
Reference in a new issue