# Path: gui/core/lcd160_gui.py
# class _A():
# class UguiException(Exception):
# class IFont:
# class LCD160CR_G(LCD160CR):
# class Screen:
# class Aperture(Screen):
# class NoTouch:
# class Touchable(NoTouch):
# async def _g():
#     def __init__(self, family, scale=0, bold_h=0, bold_v=0):
#     def stringsize(self, s):
#     def render(self, tft, x, y, s, style):
#     def height(self):
#     def max_width(self):
#     def hmap(self):
#     def reverse(self):
#     def monospaced(self):
# def get_stringsize(s, font):
# def print_centered(tft, x, y, s, style):
# def print_left(tft, x, y, s, style, tab=32):
#     def __init__(self, *args, **kwargs):
#     def get_fgcolor(self):
#     def get_bgcolor(self):
#     def _setcolor(self, color):
#     def desaturate(self, value=None):
#             def do_dim(color, factor): # Dim a color
#             def do_desat(color, factor): # Desaturate and dim
#     def dim(self, factor=None):
#     def usegrey(self, val): # tft.usegrey(True) sets greyed-out
#     def draw_rectangle(self, x1, y1, x2, y2, color):
#     def fill_rectangle(self, x1, y1, x2, y2, color):
#     def draw_clipped_rectangle(self, x1, y1, x2, y2, color):
#     def fill_clipped_rectangle(self, x1, y1, x2, y2, color):
#     def draw_circle(self, x, y, radius, color):
#     def fill_circle(self, x, y, radius, color):
#     def save_region(self, buf, x0, y0, x1, y1):
#     def restore_region(self, buf, x0, y0, x1, y1):
#     def set_text_pos(self, x, y):
#     def text_style(self, style=None):
#     def _newline(self, rows):
#     def print_char(self, c, wrap, fgcolor, bgcolor, tab=32):
#     def print_string(self, s, wrap=False, tab=32):
#     def draw_vline(self, x, y, l, color=None):
#     def draw_hline(self, x, y, l, color=None):
#     def draw_line(self, x1, y1, x2, y2, color=None):
#     def clr_scr(self):
#     def setup(cls, lcd):
#     def get_tft(cls, greyed_out=False):
#     def set_grey_style(cls, *, desaturate=True, factor=2):
#     def show(cls):
#     def change(cls, cls_new_screen, *, forward=True, args=[], kwargs={}):
#     async def monitor(cls):
#     def back(cls):
#     def addobject(cls, obj):
#     def shutdown(cls):
#     def __init__(self):
#     async def _touchtest(self): # Singleton coro tests all touchable instances
#     def _do_open(self, old_screen): # Aperture overrides
#     def on_open(self): # Optionally implemented in subclass
#     def after_open(self): # Optionally implemented in subclass
#     def on_hide(self): # Optionally implemented in subclass
#     def reg_task(self, task, on_change=False):  # May be passed a coro or a Task
#     async def _garbage_collect(self):
#     def __init__(self, location, height, width, *, draw_border=True, bgcolor=None, fgcolor=None):
#     def locn(self, x, y):
#     def _do_open(self, old_screen):
#     def _list_dims(self):
#     def value(cls, val=None):
#     def __init__(self, location, font, height, width, fgcolor, bgcolor, fontcolor, border, value, initial_value):
#     def tft(self):
#     def greyed_out(self):
#     def value(self, val=None, show=True): # User method to get or set value
#     def _value_change(self, show): # Optional override in subclass
#     def show_if_current(self):
#     def draw_border(self):
#     def overlaps(self, xa, ya, xb, yb): # Args must be sorted: xb > xa and yb > ya
#     def __init__(self, location, font, height, width, fgcolor, bgcolor, fontcolor, border, can_drag, value, initial_value):
#     def _set_callbacks(self, cb, args, cb_end=None, cbe_args=None):
#     def greyed_out(self, val=None):
#     def _trytouch(self, x, y): # If touched in bounding box, process it otherwise do nothing
#     def _untouched(self): # Default if not defined in subclass


import math
from gui.core.lcd160_gui import Touchable, dolittle
# knob.py Extension to lcd160gui providing the Knob class

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

# Usage:
# from gui.widgets.knob import Knob

TWOPI = 2 * math.pi


class Knob(Touchable):
    def __init__(self, location, *, height=50, arc=TWOPI, ticks=9, value=0.0,
                 fgcolor=None, bgcolor=None, color=None, border=None,
                 cb_end=dolittle, cbe_args=[], cb_move=dolittle, cbm_args=[]):

# Path: gui/core/lcd160_gui.py
# class _A():
# class UguiException(Exception):
# class IFont:
# class LCD160CR_G(LCD160CR):
# class Screen:
# class Aperture(Screen):
# class NoTouch:
# class Touchable(NoTouch):
# async def _g():
#     def __init__(self, family, scale=0, bold_h=0, bold_v=0):
#     def stringsize(self, s):
#     def render(self, tft, x, y, s, style):
#     def height(self):
#     def max_width(self):
#     def hmap(self):
#     def reverse(self):
#     def monospaced(self):
# def get_stringsize(s, font):
# def print_centered(tft, x, y, s, style):
# def print_left(tft, x, y, s, style, tab=32):
#     def __init__(self, *args, **kwargs):
#     def get_fgcolor(self):
#     def get_bgcolor(self):
#     def _setcolor(self, color):
#     def desaturate(self, value=None):
#             def do_dim(color, factor): # Dim a color
#             def do_desat(color, factor): # Desaturate and dim
#     def dim(self, factor=None):
#     def usegrey(self, val): # tft.usegrey(True) sets greyed-out
#     def draw_rectangle(self, x1, y1, x2, y2, color):
#     def fill_rectangle(self, x1, y1, x2, y2, color):
#     def draw_clipped_rectangle(self, x1, y1, x2, y2, color):
#     def fill_clipped_rectangle(self, x1, y1, x2, y2, color):
#     def draw_circle(self, x, y, radius, color):
#     def fill_circle(self, x, y, radius, color):
#     def save_region(self, buf, x0, y0, x1, y1):
#     def restore_region(self, buf, x0, y0, x1, y1):
#     def set_text_pos(self, x, y):
#     def text_style(self, style=None):
#     def _newline(self, rows):
#     def print_char(self, c, wrap, fgcolor, bgcolor, tab=32):
#     def print_string(self, s, wrap=False, tab=32):
#     def draw_vline(self, x, y, l, color=None):
#     def draw_hline(self, x, y, l, color=None):
#     def draw_line(self, x1, y1, x2, y2, color=None):
#     def clr_scr(self):
#     def setup(cls, lcd):
#     def get_tft(cls, greyed_out=False):
#     def set_grey_style(cls, *, desaturate=True, factor=2):
#     def show(cls):
#     def change(cls, cls_new_screen, *, forward=True, args=[], kwargs={}):
#     async def monitor(cls):
#     def back(cls):
#     def addobject(cls, obj):
#     def shutdown(cls):
#     def __init__(self):
#     async def _touchtest(self): # Singleton coro tests all touchable instances
#     def _do_open(self, old_screen): # Aperture overrides
#     def on_open(self): # Optionally implemented in subclass
#     def after_open(self): # Optionally implemented in subclass
#     def on_hide(self): # Optionally implemented in subclass
#     def reg_task(self, task, on_change=False):  # May be passed a coro or a Task
#     async def _garbage_collect(self):
#     def __init__(self, location, height, width, *, draw_border=True, bgcolor=None, fgcolor=None):
#     def locn(self, x, y):
#     def _do_open(self, old_screen):
#     def _list_dims(self):
#     def value(cls, val=None):
#     def __init__(self, location, font, height, width, fgcolor, bgcolor, fontcolor, border, value, initial_value):
#     def tft(self):
#     def greyed_out(self):
#     def value(self, val=None, show=True): # User method to get or set value
#     def _value_change(self, show): # Optional override in subclass
#     def show_if_current(self):
#     def draw_border(self):
#     def overlaps(self, xa, ya, xb, yb): # Args must be sorted: xb > xa and yb > ya
#     def __init__(self, location, font, height, width, fgcolor, bgcolor, fontcolor, border, can_drag, value, initial_value):
#     def _set_callbacks(self, cb, args, cb_end=None, cbe_args=None):
#     def greyed_out(self, val=None):
#     def _trytouch(self, x, y): # If touched in bounding box, process it otherwise do nothing
#     def _untouched(self): # Default if not defined in subclass


# Path: gui/widgets/knob.py
import math
from gui.core.lcd160_gui import Touchable, dolittle

# knob.py Extension to lcd160gui providing the Knob class

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

# Usage:
# from gui.widgets.knob import Knob

TWOPI = 2 * math.pi


class Knob(Touchable):
    def __init__(self, location, *, height=50, arc=TWOPI, ticks=9, value=0.0,
                 fgcolor=None, bgcolor=None, color=None, border=None,
                 cb_end=dolittle, cbe_args=[], cb_move=dolittle, cbm_args=[]):

        Touchable.__init__(self, location, None, height, height, fgcolor, bgcolor, None, border, True,  None, value)