PopupButton.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:pythonista-scripts 作者: khilnani 项目源码 文件源码
def draw(self):
        # redraw button
        def darken(color):
            return tuple([0.5*x for x in color])


        #set up button size to fit.
        padding=10
        textsize=ui.measure_string(string=self.title,max_width=0,font=self.font,alignment=ui.ALIGN_CENTER)

        #draw border
        ui.set_color(self.border_color)
        path = ui.Path.rounded_rect(0, 0, self.width, self.height,self.corner_radius)
        path.line_width=self.border_width
        path.stroke()

        #fill button, depending on touch state
        if self.touched:
            if self.doing_longtouch:
                ui.set_color('blue')
            else:
                ui.set_color('grey')
        else :
            ui.set_color(self.bg_color)
        path.fill()

        # fill corner darker, if has children
        if self.flow.subviews:
            corner = ui.Path()
            corner.move_to(self.width-1.5*self.corner_radius,0)
            corner.line_to(self.width,0)
            corner.line_to(self.width,1.5*self.corner_radius)
            corner.line_to(self.width-1.5*self.corner_radius,0)
            ui.set_color(darken(darken(self.bg_color)))
            corner.stroke()
            corner.fill()

        # draw title, center vertically, horiz
        rect=list(self.bounds)
        rect[1]=(rect[3]-textsize[1])/2 #vert center
        rect[2]=max(rect[2],textsize[0]+10)
        ui.draw_string(self.title, rect=tuple(rect), font=self.font, color=self.tint_color, alignment=ui.ALIGN_CENTER, line_break_mode=ui.LB_WORD_WRAP)

        if textsize[0]>self.bounds[2]:
            self.width=textsize[0]+10
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号