# 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 print_left(tft, x, y, s, color, font, clip=False, scroll=False):
#     old_style = tft.getTextStyle()
#     tft.setTextStyle(color, None, 2, font)
#     tft.setTextPos(x, y,  clip, scroll)
#     tft.printString(s)
#     tft.setTextStyle(*old_style)


from tft.driver.ugui import Touchable, dolittle, print_left
from tft.driver.constants import *
        self.select_color = select_color
        fail = False
        try:
            self.elements = [s for s in elements if type(s) is str]
        except:
            fail = True
        else:
            fail = len(self.elements) == 0
        if fail:
            raise ValueError('elements must be a list or tuple of one or more strings')
        if value >= len(self.elements):
            value = 0
        self._value = value # No callback until user touches

    def show(self):
        tft = self.tft
        bw = self.border
        clip = self.width - 2 * bw
        length = len(self.elements)
        x = self.location[0]
        y = self.location[1]
        xs = x + bw # start and end of text field
        xe = x + self.width - 2 * bw
        tft.fill_rectangle(xs, y + 1, xe, y - 1 + self.height - 2 * bw, self.bgcolor)
        for n in range(length):
            ye = y + n * self.entry_height
            if n == self._value:
                tft.fill_rectangle(xs, ye + 1, xe, ye + self.entry_height - 1, self.select_color)
            print_left(tft, xs, ye + 1, self.elements[n], self.fontcolor, self.font, clip)


# 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 print_left(tft, x, y, s, color, font, clip=False, scroll=False):
#     old_style = tft.getTextStyle()
#     tft.setTextStyle(color, None, 2, font)
#     tft.setTextPos(x, y,  clip, scroll)
#     tft.printString(s)
#     tft.setTextStyle(*old_style)


# Path: tft/widgets/listbox.py
from tft.driver.ugui import Touchable, dolittle, print_left
from tft.driver.constants import *

        self.select_color = select_color
        fail = False
        try:
            self.elements = [s for s in elements if type(s) is str]
        except:
            fail = True
        else:
            fail = len(self.elements) == 0
        if fail:
            raise ValueError('elements must be a list or tuple of one or more strings')
        if value >= len(self.elements):
            value = 0
        self._value = value # No callback until user touches

    def show(self):
        tft = self.tft
        bw = self.border
        clip = self.width - 2 * bw
        length = len(self.elements)
        x = self.location[0]
        y = self.location[1]
        xs = x + bw # start and end of text field
        xe = x + self.width - 2 * bw
        tft.fill_rectangle(xs, y + 1, xe, y - 1 + self.height - 2 * bw, self.bgcolor)
        for n in range(length):
            ye = y + n * self.entry_height
            if n == self._value:
                tft.fill_rectangle(xs, ye + 1, xe, ye + self.entry_height - 1, self.select_color)
            print_left(tft, xs, ye + 1, self.elements[n], self.fontcolor, self.font, clip)


    def textvalue(self, text=None): # if no arg return current text