<s> from pyglet_gui . sliders import Slider <EOL> class ScrollBar ( Slider ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , width , height ) : <EOL> Slider . __init__ ( self , width = width , height = height ) <EOL> self . _knob_size = <NUM_LIT:0.0> <EOL> self . _scrolled = <NUM_LIT:0> <EOL> def set_size ( self , width , height ) : <EOL> self . width = width <EOL> self . height = height <EOL> def re_layout ( self ) : <EOL> self . layout ( ) <EOL> if self . _scrolled > <NUM_LIT:2> : <EOL> self . parent . layout ( ) <EOL> self . _scrolled = <NUM_LIT:0> <EOL> def _get_bar_region ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . x , self . y , self . width , self . height <EOL> def _get_knob_region ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def get_knob_pos ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def set_knob_pos ( self , pos ) : <EOL> pos = max ( min ( pos , <NUM_LIT:1> - self . _knob_size / <NUM_LIT:2> ) , self . _knob_size / <NUM_LIT:2> ) <EOL> self . _value = self . _min_value + ( self . _max_value - self . _min_value ) * pos <EOL> def layout ( self ) : <EOL> self . _knob . update ( * self . _get_knob_region ( ) ) <EOL> self . _bar . update ( * self . _get_bar_region ( ) ) <EOL> def on_gain_focus ( self ) : <EOL> if self . _manager is not None : <EOL> self . _manager . set_wheel_target ( self ) <EOL> def on_lose_focus ( self ) : <EOL> self . _scrolled = <NUM_LIT:0> <EOL> if self . _manager is not None : <EOL> self . _manager . set_wheel_target ( None ) <EOL> class HScrollbar ( ScrollBar ) : <EOL> PATH = '<STR_LIT>' <EOL> def __init__ ( self , width ) : <EOL> ScrollBar . __init__ ( self , width = width , height = <NUM_LIT:0> ) <EOL> def _get_knob_region ( self ) : <EOL> return int ( self . x + ( self . _knob_pos ( ) - self . _knob_size / <NUM_LIT:2> ) * self . width ) , self . y , int ( self . _knob_size * self . width ) , self . height <EOL> def get_knob_pos ( self ) : <EOL> return int ( ( self . _knob_pos ( ) - self . _knob_size / <NUM_LIT:2> ) * self . width ) <EOL> def load_graphics ( self ) : <EOL> super ( HScrollbar , self ) . load_graphics ( ) <EOL> self . height = self . _bar . height <EOL> def on_mouse_drag ( self , x , y , dx , dy , buttons , modifiers ) : <EOL> bar_x , _ , bar_width , _ = self . _bar . get_content_region ( ) <EOL> absolute_distance = float ( x - bar_x ) <EOL> relative_distance = absolute_distance / bar_width <EOL> self . set_knob_pos ( relative_distance ) <EOL> self . _scrolled = <NUM_LIT:10> <EOL> self . re_layout ( ) <EOL> return True <EOL> def on_mouse_scroll ( self , x , y , scroll_x , scroll_y ) : <EOL> self . _scrolled += abs ( scroll_x ) <EOL> self . set_knob_pos ( self . _knob_pos ( ) - float ( scroll_x ) / self . width ) <EOL> self . re_layout ( ) <EOL> return True <EOL> def set_knob_size ( self , width , max_width ) : <EOL> self . _knob_size = float ( width ) / max_width <EOL> self . set_knob_pos ( self . _knob_pos ( ) ) <EOL> def compute_size ( self ) : <EOL> return self . width , self . _bar . height <EOL> class VScrollbar ( ScrollBar ) : <EOL> PATH = '<STR_LIT>' <EOL> def __init__ ( self , height ) : <EOL> ScrollBar . __init__ ( self , width = <NUM_LIT:0> , height = height ) <EOL> def _get_knob_region ( self ) : <EOL> top = self . y + self . height <EOL> return ( self . x , int ( top - ( self . _knob_pos ( ) + self . _knob_size / <NUM_LIT:2> ) * self . height ) , <EOL> self . width , int ( self . _knob_size * self . height ) ) <EOL> def get_knob_pos ( self ) : <EOL> return int ( ( self . _knob_pos ( ) - self . _knob_size / <NUM_LIT:2> ) * self . height / self . _knob_size ) <EOL> def load_graphics ( self ) : <EOL> super ( VScrollbar , self ) . load_graphics ( ) <EOL> self . width = self . _bar . width <EOL> def on_mouse_drag ( self , x , y , dx , dy , button , modifiers ) : <EOL> bar_x , bar_y , bar_width , bar_height = self . _bar . get_content_region ( ) <EOL> absolute_distance = float ( y - bar_y ) <EOL> relative_distance = absolute_distance / bar_height <EOL> self . set_knob_pos ( <NUM_LIT:1> - relative_distance ) <EOL> self . _scrolled = <NUM_LIT:10> <EOL> self . re_layout ( ) <EOL> return True <EOL> def on_mouse_scroll ( self , x , y , scroll_x , scroll_y ) : <EOL> self . _scrolled += abs ( scroll_y ) <EOL> self . set_knob_pos ( self . _knob_pos ( ) + float ( scroll_y ) / self . height ) <EOL> self . re_layout ( ) <EOL> return True <EOL> def set_knob_size ( self , height , max_height ) : <EOL> self . _knob_size = float ( height ) / max_height <EOL> self . set_knob_pos ( self . _knob_pos ( ) ) <EOL> def compute_size ( self ) : <EOL> return self . _bar . width , self . height </s>
