def place(self, selected=None, active=None):

        if active == None:
            self.active = 1
            active = 1  # turn on button

        if active:
            if selected == None:
                selected = self.selected

            if selected:
                cur_color = self.color_sel
                cur_text = self.text_color_sel
            else:
                cur_color = self.color
                cur_text = self.text_color

            #place base shape for button
            io.if_rect(self.x, self.y, self.width, self.height, self.radius,
                       cur_color)

            if self.text != ' ':
                #find/calc text dimension and location
                text_dim = io.text_dimensions(self.x, self.y, self.text)
                text_x = int(self.x + self.x_offset +
                             (self.width - text_dim[0]) / 2) - 1
                text_y = int(self.y + self.y_offset +
                             (self.height - text_dim[1]) / 2) - 1

                #place text
                io.text(text_x, text_y, self.text, cur_text, cur_color)
Ejemplo n.º 2
0
 def sub_place(self):
     #width = io.text_dimensions(self.x+self.border,self.y+self.border,self.value)
     #io.rect(self.x+self.border + width,self.y+self.border, self.width - width, self.height)
     
     #place  rect to clear any place where new text won't go
     minx = self.width
     for line in self.value.split('\n'):
         minx = min(minx, io.text_dimensions(self.x,self.y,line)[0] )
     
     io.rect(self.x+self.border + minx, self.y+self.border, 
             self.width - self.border*2 - minx,
             self.height - self.border*2,
             self.background)
 
     io.text(self.x + self.border,self.y + 1 + self.border, self.value, color = self.color,
             background = self.background)
Ejemplo n.º 3
0
 def __init__(self,x,y,width,height, value , color = io.white, size = 1, border = 0, place = 1,
             top_down = 1, clip_top = 1, color_clear = io.background_color, background = io.black):
     self._set_id()
     self.x = x
     self.y = y
     self.width = width
     self.height = height
     
     self.color_clear = color_clear
     self.background = background
     
     self.size = size
     self.border = border
     
     self.active = 0
     
     self.top_down = top_down
     self.clip_top = clip_top
     
     dims = io.text_dimensions(0,0,' \n ', size)
     self.char_width = dims[0]
     self.char_height = dims[1]/2
     
     #set initial value as color
     self._value = ' '
     self._color = color
     
     #define possbile cols and chars of text
     self.textx = self.x + self.border
     self.texty = self.y + self.border
     
     self.text_cols = floor((self.width - self.border*2 - 1)/self.char_width)
     self.text_rows = floor((self.height - self.border*2 -1 )/self.char_height) -1
     #print(self.text_cols)
     
     # configureing value
     self.value = value
     '''# this defines internal vars like text len, height etc
     self.value = value'''
     
     if place:
         self.place()