# 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 * 
# meter.py Extension to lcd160gui providing the Meter class

# Released under the MIT License (MIT). See LICENSE.
# Copyright (c) 2020 Peter Hinch

# Usage:
# from gui.widgets.meter import Meter



class Meter(NoTouch):
    def __init__(self, location, *, font=None, height=100, width=26,
                 fgcolor=None, bgcolor=None, pointercolor=None, fontcolor=None,
                 divisions=10, legends=None, value=0):
        border = 5 if font is None else 1 + font.height() / 2
        tft = self.tft
        bgcolor = tft.get_bgcolor() if bgcolor is None else bgcolor

# 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 * 

# meter.py Extension to lcd160gui providing the Meter class

# Released under the MIT License (MIT). See LICENSE.
# Copyright (c) 2020 Peter Hinch

# Usage:
# from gui.widgets.meter import Meter



class Meter(NoTouch):
    def __init__(self, location, *, font=None, height=100, width=26,
                 fgcolor=None, bgcolor=None, pointercolor=None, fontcolor=None,
                 divisions=10, legends=None, value=0):
        border = 5 if font is None else 1 + font.height() / 2
        tft = self.tft
        bgcolor = tft.get_bgcolor() if bgcolor is None else bgcolor

        NoTouch.__init__(self, location, font, height, width, fgcolor, bgcolor, fontcolor, border, value, None) # super() provoked Python bug