def render(self): font_name = self.style_attr('font_name', ['Calibri', 'Arial']) font_size = self.style_attr('font_size', 12) font_color = self.style_attr('font_color', arcade.color.GRAY) font_color_hover = self.style_attr('font_color_hover', None) font_color_press = self.style_attr('font_color_press', None) if font_color_hover is None: font_color_hover = font_color if font_color_press is None: font_color_press = font_color_hover text_image_normal = get_text_image( text=self.text, font_color=font_color, font_size=font_size, font_name=font_name, align=self.align, width=int(self._target_width), ) text_image_mouse_over = get_text_image( text=self.text, font_color=font_color_hover, font_size=font_size, font_name=font_name, align=self.align, width=int(self._target_width), ) text_image_mouse_press = get_text_image( text=self.text, font_color=font_color_press, font_size=font_size, font_name=font_name, align=self.align, width=int(self._target_width), ) self.normal_texture = arcade.Texture(image=text_image_normal, name=str(uuid4()), hit_box_algorithm="None") self.press_texture = arcade.Texture(image=text_image_mouse_press, name=str(uuid4()), hit_box_algorithm="None") self.hover_texture = arcade.Texture(image=text_image_mouse_over, name=str(uuid4()), hit_box_algorithm="None")
def render(self): font_name = self.style_attr('font_name', ['Calibri', 'Arial']) font_size = self.style_attr('font_size', 22) font_color = self.style_attr('font_color', arcade.color.WHITE) font_color_hover = self.style_attr('font_color_hover', None) if font_color_hover is None: font_color_hover = font_color font_color_focus = self.style_attr('font_color_focus', None) if font_color_focus is None: font_color_focus = font_color_hover border_width = self.style_attr('border_width', 2) border_color = self.style_attr('border_color', arcade.color.WHITE) border_color_hover = self.style_attr('border_color_hover', arcade.color.WHITE) border_color_focus = self.style_attr('border_color_focus', arcade.color.WHITE) bg_color = self.style_attr('bg_color', arcade.color.GRAY) bg_color_hover = self.style_attr('bg_color_hover', arcade.color.GRAY) bg_color_focus = self.style_attr('bg_color_focus', arcade.color.GRAY) width = int(self.width) vmargin = self.style_attr('vmargin', 0) height = self.height if self.height else font_size + vmargin align = "left" margin_left = self.style_attr('margin_left', 10) # text text_image_normal = get_text_image(text=self.text, font_color=font_color, font_size=font_size, font_name=font_name, align=align, width=width, height=height, valign='middle', indent=margin_left, background_color=bg_color) text_image_hover = get_text_image(text=self.text, font_color=font_color_hover, font_size=font_size, font_name=font_name, align=align, width=width, height=height, valign='middle', indent=margin_left, background_color=bg_color_hover) text_to_show = self.text[:self.cursor_index] + self.symbol + self.text[ self.cursor_index:] text_image_focus = get_text_image(text=text_to_show, font_color=font_color_focus, font_size=font_size, font_name=font_name, align=align, width=width, height=height, valign='middle', indent=margin_left, background_color=bg_color_focus) # draw outline rect = [ 0, 0, text_image_normal.width - border_width / 2, text_image_normal.height - border_width / 2 ] if border_color and border_width: d = ImageDraw.Draw(text_image_normal) d.rectangle(rect, fill=None, outline=border_color, width=border_width) if border_color_hover: d = ImageDraw.Draw(text_image_hover) d.rectangle(rect, fill=None, outline=border_color_hover, width=border_width) if border_color_focus: d = ImageDraw.Draw(text_image_focus) d.rectangle(rect, fill=None, outline=border_color_focus, width=border_width) self.normal_texture = arcade.Texture(image=text_image_normal, name=str(uuid4())) self.hover_texture = arcade.Texture(image=text_image_hover, name=str(uuid4())) self.focus_texture = arcade.Texture(image=text_image_focus, name=str(uuid4()))