# Path: gui/core/lcd160_gui.py
# class NoTouch:
#     _greyed_out = False # Disabled by user code
#     def __init__(self, location, font, height, width, fgcolor, bgcolor, fontcolor, border, value, initial_value):
#         Screen.addobject(self)
#         self.screen = Screen.current_screen
#         self.redraw = True # Force drawing of static part of image
#         self.location = location
#         self._value = value
#         self._initial_value = initial_value # Optionally enables show() method to handle initialisation
#         self.fontcolor = WHITE if fontcolor is None else fontcolor
#         self.height = height
#         self.width = width
#         self.fill = bgcolor is not None
#         self.visible = True # Used by ButtonList class for invisible buttons
# #        self._greyed_out = False # Disabled by user code
#         tft = Screen.get_tft(False) # Not greyed out
#         if font is None:
#             self.font = tft.text_font
#         else:
#             self.font = font
# 
#         if fgcolor is None:
#             self.fgcolor = tft.get_fgcolor()
#             if bgcolor is None:
#                 self.bgcolor = tft.get_bgcolor()
#             else:
#                 self.bgcolor = bgcolor
#             self.fontbg = self.bgcolor
#         else:
#             self.fgcolor = fgcolor
#             if bgcolor is None:
#                 self.bgcolor = tft.get_bgcolor()  # black surround to circle button etc
#                 self.fontbg = fgcolor  # Fonts are drawn on bg of foreground color
#             else:
#                 self.bgcolor = bgcolor
#                 self.fontbg = bgcolor
# 
#         self.text_style = tft.text_style((self.fontcolor, self.fontbg, self.font))
#         self.border = 0 if border is None else int(max(border, 0)) # width
#         self.bdcolor = self.fgcolor  # Border is always drawn in original fgcolor
#         self.callback = dolittle # Value change callback
#         self.args = []
#         self.cb_end = dolittle # Touch release callbacks
#         self.cbe_args = []
# 
#     @property
#     def tft(self):
#         return Screen.get_tft(self._greyed_out)
# 
#     def greyed_out(self):
#         return self._greyed_out # Subclass may be greyed out
# 
#     def value(self, val=None, show=True): # User method to get or set value
#         if val is not None:
#             if type(val) is float:
#                 val = min(max(val, 0.0), 1.0)
#             if val != self._value:
#                 self._value = val
#                 self._value_change(show)
#         return self._value
# 
#     def _value_change(self, show): # Optional override in subclass
#         self.callback(self, *self.args) # CB is not a bound method. 1st arg is self
#         if show:
#             self.show_if_current()
# 
#     def show_if_current(self):
#         if self.screen is Screen.current_screen:
#             self.show()
# 
# # Called by Screen.show(). Draw background and bounding box if required
#     def draw_border(self):
#         if self.screen is Screen.current_screen:
#             tft = self.tft
#             x = self.location[0]
#             y = self.location[1]
#             if self.fill:
#                 tft.fill_rectangle(x, y, x + self.width, y + self.height, self.bgcolor)
#             if self.border > 0: # Draw a bounding box
#                 tft.draw_rectangle(x, y, x + self.width, y + self.height, self.bdcolor)
#         return self.border # border width in pixels
# 
#     def overlaps(self, xa, ya, xb, yb): # Args must be sorted: xb > xa and yb > ya
#         x0 = self.location[0]
#         y0 = self.location[1]
#         x1 = x0 + self.width
#         y1 = y0 + self.height
#         if (ya <= y1 and yb >= y0) and (xa <= x1 and xb >= x0):
#             return True
#         return False
# 
# def print_centered(tft, x, y, s, style):
#     font = style[2]
#     length, height = get_stringsize(s, font)
#     x, y = max(x - length // 2, 0), max(y - height // 2, 0)
#     if isinstance(font, IFont):
#         return font.render(tft, x, y, s, style)
#     tft.text_style(style)
#     tft.set_text_pos(x, y)
#     tft.print_string(s)


from gui.core.lcd160_gui import NoTouch, print_centered
from gui.core.constants import * 
        self.y0 = self.location[1] + border + 2
        self.y1 = self.location[1] + self.height - border
        self.divisions = divisions
        self.legends = legends
        self.pointercolor = pointercolor if pointercolor is not None else self.fgcolor
        self.ptr_y = None # Invalidate old position

    def show(self):
        tft = self.tft
        width = self.width
        dx = 5
        x0 = self.x0
        x1 = self.x1
        y0 = self.y0
        y1 = self.y1
        height = y1 - y0
        if self.divisions > 0:
            dy = height / (self.divisions) # Tick marks
            for tick in range(self.divisions + 1):
                ypos = int(y0 + dy * tick)
                tft.draw_hline(x0, ypos, dx, self.fgcolor)
                tft.draw_hline(x1 - dx, ypos, dx, self.fgcolor)

        if self.legends is not None and self.font is not None: # Legends
            if len(self.legends) <= 1:
                dy = 0
            else:
                dy = height / (len(self.legends) -1)
            yl = self.y1 # Start at bottom
            for legend in self.legends:

# Path: gui/core/lcd160_gui.py
# class NoTouch:
#     _greyed_out = False # Disabled by user code
#     def __init__(self, location, font, height, width, fgcolor, bgcolor, fontcolor, border, value, initial_value):
#         Screen.addobject(self)
#         self.screen = Screen.current_screen
#         self.redraw = True # Force drawing of static part of image
#         self.location = location
#         self._value = value
#         self._initial_value = initial_value # Optionally enables show() method to handle initialisation
#         self.fontcolor = WHITE if fontcolor is None else fontcolor
#         self.height = height
#         self.width = width
#         self.fill = bgcolor is not None
#         self.visible = True # Used by ButtonList class for invisible buttons
# #        self._greyed_out = False # Disabled by user code
#         tft = Screen.get_tft(False) # Not greyed out
#         if font is None:
#             self.font = tft.text_font
#         else:
#             self.font = font
# 
#         if fgcolor is None:
#             self.fgcolor = tft.get_fgcolor()
#             if bgcolor is None:
#                 self.bgcolor = tft.get_bgcolor()
#             else:
#                 self.bgcolor = bgcolor
#             self.fontbg = self.bgcolor
#         else:
#             self.fgcolor = fgcolor
#             if bgcolor is None:
#                 self.bgcolor = tft.get_bgcolor()  # black surround to circle button etc
#                 self.fontbg = fgcolor  # Fonts are drawn on bg of foreground color
#             else:
#                 self.bgcolor = bgcolor
#                 self.fontbg = bgcolor
# 
#         self.text_style = tft.text_style((self.fontcolor, self.fontbg, self.font))
#         self.border = 0 if border is None else int(max(border, 0)) # width
#         self.bdcolor = self.fgcolor  # Border is always drawn in original fgcolor
#         self.callback = dolittle # Value change callback
#         self.args = []
#         self.cb_end = dolittle # Touch release callbacks
#         self.cbe_args = []
# 
#     @property
#     def tft(self):
#         return Screen.get_tft(self._greyed_out)
# 
#     def greyed_out(self):
#         return self._greyed_out # Subclass may be greyed out
# 
#     def value(self, val=None, show=True): # User method to get or set value
#         if val is not None:
#             if type(val) is float:
#                 val = min(max(val, 0.0), 1.0)
#             if val != self._value:
#                 self._value = val
#                 self._value_change(show)
#         return self._value
# 
#     def _value_change(self, show): # Optional override in subclass
#         self.callback(self, *self.args) # CB is not a bound method. 1st arg is self
#         if show:
#             self.show_if_current()
# 
#     def show_if_current(self):
#         if self.screen is Screen.current_screen:
#             self.show()
# 
# # Called by Screen.show(). Draw background and bounding box if required
#     def draw_border(self):
#         if self.screen is Screen.current_screen:
#             tft = self.tft
#             x = self.location[0]
#             y = self.location[1]
#             if self.fill:
#                 tft.fill_rectangle(x, y, x + self.width, y + self.height, self.bgcolor)
#             if self.border > 0: # Draw a bounding box
#                 tft.draw_rectangle(x, y, x + self.width, y + self.height, self.bdcolor)
#         return self.border # border width in pixels
# 
#     def overlaps(self, xa, ya, xb, yb): # Args must be sorted: xb > xa and yb > ya
#         x0 = self.location[0]
#         y0 = self.location[1]
#         x1 = x0 + self.width
#         y1 = y0 + self.height
#         if (ya <= y1 and yb >= y0) and (xa <= x1 and xb >= x0):
#             return True
#         return False
# 
# def print_centered(tft, x, y, s, style):
#     font = style[2]
#     length, height = get_stringsize(s, font)
#     x, y = max(x - length // 2, 0), max(y - height // 2, 0)
#     if isinstance(font, IFont):
#         return font.render(tft, x, y, s, style)
#     tft.text_style(style)
#     tft.set_text_pos(x, y)
#     tft.print_string(s)


# Path: gui/widgets/meter.py
from gui.core.lcd160_gui import NoTouch, print_centered
from gui.core.constants import * 

        self.y0 = self.location[1] + border + 2
        self.y1 = self.location[1] + self.height - border
        self.divisions = divisions
        self.legends = legends
        self.pointercolor = pointercolor if pointercolor is not None else self.fgcolor
        self.ptr_y = None # Invalidate old position

    def show(self):
        tft = self.tft
        width = self.width
        dx = 5
        x0 = self.x0
        x1 = self.x1
        y0 = self.y0
        y1 = self.y1
        height = y1 - y0
        if self.divisions > 0:
            dy = height / (self.divisions) # Tick marks
            for tick in range(self.divisions + 1):
                ypos = int(y0 + dy * tick)
                tft.draw_hline(x0, ypos, dx, self.fgcolor)
                tft.draw_hline(x1 - dx, ypos, dx, self.fgcolor)

        if self.legends is not None and self.font is not None: # Legends
            if len(self.legends) <= 1:
                dy = 0
            else:
                dy = height / (len(self.legends) -1)
            yl = self.y1 # Start at bottom
            for legend in self.legends:

                print_centered(tft, int(self.x0 + self.width /2), int(yl), legend, self.text_style)