# Path: tft/driver/ugui.py
# class Touchable(NoTouch):
#     def __init__(self, location, font, height, width, fgcolor, bgcolor, fontcolor, border, can_drag, value, initial_value):
#         super().__init__(location, font, height, width, fgcolor, bgcolor, fontcolor, border, value, initial_value)
#         self.can_drag = can_drag
#         self.busy = False
#         self.was_touched = False
# 
#     def _set_callbacks(self, cb, args, cb_end=None, cbe_args=None):
#         self.callback = cb
#         self.args = args
#         if cb_end is not None:
#             self.cb_end = cb_end
#             self.cbe_args = cbe_args
# 
#     def greyed_out(self, val=None):
#         if val is not None and self._greyed_out != val:
#             self._greyed_out = val
#             self.draw_border()
#             self.redraw = True
#             self.show_if_current()
#         return self._greyed_out
# 
#     def _trytouch(self, x, y): # If touched in bounding box, process it otherwise do nothing
#         x0 = self.location[0]
#         x1 = self.location[0] + self.width
#         y0 = self.location[1]
#         y1 = self.location[1] + self.height
#         if x0 <= x <= x1 and y0 <= y <= y1:
#             self.was_touched = True
#             if not self.busy or self.can_drag:
#                 self._touched(x, y) # Called repeatedly for draggable objects
#                 self.busy = True # otherwise once only
# 
#     def _untouched(self): # Default if not defined in subclass
#         self.cb_end(self, *self.cbe_args) # Callback not a bound method so pass self
# 
# def dolittle(*_):
#     pass
# 
# def get_stringsize(s, font):
#     hor = 0
#     for c in s:
#         _, vert, cols = font.get_ch(c)
#         hor += cols
#     return hor, vert
# 
# Path: tft/driver/TFT_io.py
# RESET  = const(1 << 10)  ## Y9
# RD     = const(1 << 11)  ## Y10
# WR     = const(0x01)  ## Y11
# D_C    = const(0x02)  ## Y12
# LED    = const(1 << 8) ## Y3
# POWER  = const(1 << 9) ## Y4
# PORTRAIT = const(1)
# LANDSCAPE = const(0)
# def displaySCR_charbitmap(bits: ptr8, size: int, control: ptr8, bg_buf: ptr8):
# def displaySCR_bmp(data: ptr8, size: int, bits: int, colortable: ptr8):
# def setXY_L(r0, r1, r2, r3):  
# def setXY_P(r0, r1, r2, r3):  
# def drawPixel_L(r0, r1, r2):  
# def drawPixel_P(r0, r1, r2):  
# def fillSCR_AS(r0, r1):  # r0: ptr to data, r1: number of pixels (3 bytes/pixel)
# def displaySCR_AS(r0, r1):  # r0: ptr to data, r1: is number of pixels (3 bytes/pixel)
# def displaySCR565_AS(r0, r1):  # r0: ptr to data, r1: is number of pixels (3 bytes/pixel)
# def tft_cmd_data(cmd: int, data: ptr8, size: int):
# def tft_cmd_data_AS(r0, r1, r2):  # r0: command, r1: ptr to data, r2 is size in bytes
# def tft_cmd(cmd: int):
# def tft_write_data_AS(r0, r1):  # r0: ptr to data, r1: is size in Bytes
# def tft_read_cmd_data_AS(r0, r1, r2):  
# def swapbytes(r0, r1):               # bytearray, len(bytearray)
# def swapcolors(r0, r1):               # bytearray, len(bytearray)
# 
# Path: tft/widgets/label.py
# class Label(NoTouch):
#     def __init__(self, location, *, font, border=None, width=None, fgcolor=None, bgcolor=None, fontcolor=None, value=None):
#         if width is None:
#             if value is None:
#                 raise ValueError('If label value unspecified, must define the width')
#             width, _ = get_stringsize(value, font) 
#         super().__init__(location, font, None, width, fgcolor, bgcolor, fontcolor, border, value, None)
#         self.height = self.font.height()
#         self.height += 2 * self.border  # Height determined by font and border
# 
#     def show(self):
#         tft = self.tft
#         bw = self.border
#         x = self.location[0]
#         y = self.location[1]
#         tft.fill_rectangle(x + bw, y + bw, x + self.width - bw, y + self.height - bw, self.bgcolor)
#         if self._value is not None:
#             print_left(tft, x + bw, y + bw, self._value, self.fontcolor, self.font, self.width - 2 * bw)


from tft.driver.ugui import Touchable, dolittle, get_stringsize
from tft.driver import TFT_io
from tft.driver.constants import *
from tft.widgets.label import Label
# horiz_slider.py For TFT driver.
# Adapted for (and requires) uasyncio V3

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


class HorizSlider(Touchable):
    def __init__(self, location, *, font=None, height=30, width=200, divisions=10, legends=None,
                 fgcolor=None, bgcolor=None, fontcolor=None, slidecolor=None, border=None, 

# Path: tft/driver/ugui.py
# class Touchable(NoTouch):
#     def __init__(self, location, font, height, width, fgcolor, bgcolor, fontcolor, border, can_drag, value, initial_value):
#         super().__init__(location, font, height, width, fgcolor, bgcolor, fontcolor, border, value, initial_value)
#         self.can_drag = can_drag
#         self.busy = False
#         self.was_touched = False
# 
#     def _set_callbacks(self, cb, args, cb_end=None, cbe_args=None):
#         self.callback = cb
#         self.args = args
#         if cb_end is not None:
#             self.cb_end = cb_end
#             self.cbe_args = cbe_args
# 
#     def greyed_out(self, val=None):
#         if val is not None and self._greyed_out != val:
#             self._greyed_out = val
#             self.draw_border()
#             self.redraw = True
#             self.show_if_current()
#         return self._greyed_out
# 
#     def _trytouch(self, x, y): # If touched in bounding box, process it otherwise do nothing
#         x0 = self.location[0]
#         x1 = self.location[0] + self.width
#         y0 = self.location[1]
#         y1 = self.location[1] + self.height
#         if x0 <= x <= x1 and y0 <= y <= y1:
#             self.was_touched = True
#             if not self.busy or self.can_drag:
#                 self._touched(x, y) # Called repeatedly for draggable objects
#                 self.busy = True # otherwise once only
# 
#     def _untouched(self): # Default if not defined in subclass
#         self.cb_end(self, *self.cbe_args) # Callback not a bound method so pass self
# 
# def dolittle(*_):
#     pass
# 
# def get_stringsize(s, font):
#     hor = 0
#     for c in s:
#         _, vert, cols = font.get_ch(c)
#         hor += cols
#     return hor, vert
# 
# Path: tft/driver/TFT_io.py
# RESET  = const(1 << 10)  ## Y9
# RD     = const(1 << 11)  ## Y10
# WR     = const(0x01)  ## Y11
# D_C    = const(0x02)  ## Y12
# LED    = const(1 << 8) ## Y3
# POWER  = const(1 << 9) ## Y4
# PORTRAIT = const(1)
# LANDSCAPE = const(0)
# def displaySCR_charbitmap(bits: ptr8, size: int, control: ptr8, bg_buf: ptr8):
# def displaySCR_bmp(data: ptr8, size: int, bits: int, colortable: ptr8):
# def setXY_L(r0, r1, r2, r3):  
# def setXY_P(r0, r1, r2, r3):  
# def drawPixel_L(r0, r1, r2):  
# def drawPixel_P(r0, r1, r2):  
# def fillSCR_AS(r0, r1):  # r0: ptr to data, r1: number of pixels (3 bytes/pixel)
# def displaySCR_AS(r0, r1):  # r0: ptr to data, r1: is number of pixels (3 bytes/pixel)
# def displaySCR565_AS(r0, r1):  # r0: ptr to data, r1: is number of pixels (3 bytes/pixel)
# def tft_cmd_data(cmd: int, data: ptr8, size: int):
# def tft_cmd_data_AS(r0, r1, r2):  # r0: command, r1: ptr to data, r2 is size in bytes
# def tft_cmd(cmd: int):
# def tft_write_data_AS(r0, r1):  # r0: ptr to data, r1: is size in Bytes
# def tft_read_cmd_data_AS(r0, r1, r2):  
# def swapbytes(r0, r1):               # bytearray, len(bytearray)
# def swapcolors(r0, r1):               # bytearray, len(bytearray)
# 
# Path: tft/widgets/label.py
# class Label(NoTouch):
#     def __init__(self, location, *, font, border=None, width=None, fgcolor=None, bgcolor=None, fontcolor=None, value=None):
#         if width is None:
#             if value is None:
#                 raise ValueError('If label value unspecified, must define the width')
#             width, _ = get_stringsize(value, font) 
#         super().__init__(location, font, None, width, fgcolor, bgcolor, fontcolor, border, value, None)
#         self.height = self.font.height()
#         self.height += 2 * self.border  # Height determined by font and border
# 
#     def show(self):
#         tft = self.tft
#         bw = self.border
#         x = self.location[0]
#         y = self.location[1]
#         tft.fill_rectangle(x + bw, y + bw, x + self.width - bw, y + self.height - bw, self.bgcolor)
#         if self._value is not None:
#             print_left(tft, x + bw, y + bw, self._value, self.fontcolor, self.font, self.width - 2 * bw)


# Path: tft/widgets/horiz_slider.py
from tft.driver.ugui import Touchable, dolittle, get_stringsize
from tft.driver import TFT_io
from tft.driver.constants import *
from tft.widgets.label import Label

# horiz_slider.py For TFT driver.
# Adapted for (and requires) uasyncio V3

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


class HorizSlider(Touchable):
    def __init__(self, location, *, font=None, height=30, width=200, divisions=10, legends=None,
                 fgcolor=None, bgcolor=None, fontcolor=None, slidecolor=None, border=None, 

                 cb_end=dolittle, cbe_args=[], cb_move=dolittle, cbm_args=[], value=0.0):