chip.py (3358B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\control\chip.py 2 import eveui 3 from carbonui import uiconst 4 from carbonui.text.color import TextColor 5 from carbonui.text.styles import TextBody 6 from eve.client.script.ui import eveThemeColor 7 8 class Chip(eveui.ContainerAutoSize): 9 default_state = uiconst.UI_NORMAL 10 default_align = uiconst.NOALIGN 11 default_alignMode = uiconst.Align.CENTERLEFT 12 default_height = 28 13 14 def __init__(self, label, icon = None, on_click = None, selected = False, value = None, inner_padding = (8, 2, 8, 2), color = eveThemeColor.THEME_FOCUSDARK, *args, **kwargs): 15 super(Chip, self).__init__(*args, **kwargs) 16 self._value = value 17 self._on_click = on_click 18 self._color = color 19 if icon: 20 eveui.Sprite(parent=self, align=uiconst.Align.CENTERLEFT, texturePath=icon, height=16, width=16, left=6, color=TextColor.NORMAL) 21 self._label = TextBody(parent=self, align=uiconst.Align.CENTERLEFT, text=label, padding=inner_padding, left=18 if icon else 0) 22 self._hover_frame = eveui.Frame(parent=self, align=uiconst.Align.TOALL, color=self._color, opacity=0, frameConst=uiconst.FRAME_FILLED_CORNER9) 23 if selected: 24 self._selected_frame = eveui.Frame(bgParent=self, color=self._color, opacity=1.5, frameConst=uiconst.FRAME_BORDER1_CORNER9) 25 else: 26 self._selected_frame = None 27 self._bg_frame = eveui.Frame(bgParent=self, color=self._color, opacity=0.3, frameConst=uiconst.FRAME_FILLED_CORNER9) 28 29 def OnClick(self, *args): 30 eveui.Sound.button_click.play() 31 self._on_click(self._value) 32 33 def OnMouseEnter(self, *args): 34 super(Chip, self).OnMouseEnter(*args) 35 eveui.Sound.button_hover.play() 36 eveui.fade_in(self._hover_frame, end_value=0.5, duration=0.2) 37 38 def OnMouseExit(self, *args): 39 super(Chip, self).OnMouseExit(*args) 40 eveui.fade(self._hover_frame, end_value=0, duration=0.2) 41 42 def OnColorThemeChanged(self): 43 super(Chip, self).OnColorThemeChanged() 44 color = self._color[:3] 45 self._hover_frame.rgb = color 46 self._bg_frame.rgb = color 47 if self._selected_frame: 48 self._selected_frame.rgb = color 49 50 51 class ContentTagChip(Chip): 52 53 def __init__(self, content_tag, show_icon = False, *args, **kwargs): 54 self._content_tag = content_tag 55 kwargs['name'] = u'{}_filter_chip'.format(content_tag.id) 56 kwargs['value'] = content_tag.id 57 kwargs['label'] = content_tag.title 58 if show_icon: 59 kwargs['icon'] = content_tag.icon 60 super(ContentTagChip, self).__init__(*args, **kwargs) 61 62 def LoadTooltipPanel(self, tooltip_panel, *args): 63 tooltip_panel.LoadStandardSpacing() 64 tooltip_panel.columns = 1 65 tooltip_panel.AddLabelSmall(text=self._content_tag.tag_type_title, color=TextColor.SECONDARY) 66 if self._content_tag.icon: 67 tooltip_panel.AddSpriteLabel(texturePath=self._content_tag.icon, label=self._content_tag.title, iconSize=16, iconColor=TextColor.NORMAL, iconOffset=0) 68 else: 69 tooltip_panel.AddLabelMedium(text=self._content_tag.title) 70 if self._content_tag.description: 71 tooltip_panel.AddLabelMedium(text=self._content_tag.description, wrapWidth=300)