NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

collapsibleContainer.py (4991B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\primitives\collapsibleContainer.py
      2 import eveicon
      3 from carbonui import Align, uiconst, TextColor
      4 from carbonui.text.styles import TextBody
      5 from carbonui.control.buttonIcon import ButtonIcon
      6 from carbonui.primitives.container import Container, Sprite
      7 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      8 from carbonui.primitives.line import Line
      9 from carbonui.util.color import Color
     10 from carbonui.uiconst import PickState
     11 
     12 class CollapsibleContainer(ContainerAutoSize):
     13     LINE_HEIGHT = 1
     14     LINE_TOP = 9
     15     default_collapsedHeight = 120
     16     default_maxFadeHeight = 20
     17     default_backgroundColor = None
     18     default_topSpacing = 0
     19     default_textClass = TextBody
     20 
     21     def ApplyAttributes(self, attributes):
     22         self.container_bottom_line_simple = None
     23         self.container_bottom_line_expander = None
     24         super(CollapsibleContainer, self).ApplyAttributes(attributes)
     25         self._collapsed_height = attributes.get('collapsedHeight', self.default_collapsedHeight)
     26         self._maxFadeHeight = attributes.get('maxFadeHeight', self.default_maxFadeHeight)
     27         self._backgroundColor = attributes.get('backgroundColor', self.default_backgroundColor)
     28         self._topSpacing = attributes.get('topSpacing', self.default_topSpacing)
     29         textCls = attributes.get('textClass', self.default_textClass)
     30         self._is_collapsed = True
     31         self._show_all = False
     32         self.sub_cont = ContainerAutoSize(parent=self, align=Align.TOTOP, clipChildren=True, padTop=self._topSpacing)
     33         self.lore = textCls(name='label_lore', parent=self.sub_cont, align=Align.TOTOP, state=uiconst.UI_NORMAL, color=Color.GRAY6)
     34         self._build_expander_bottom_line()
     35         self._build_simple_bottom_line()
     36         if self._backgroundColor:
     37             bgCont = Container(bgParent=self.sub_cont, align=Align.TOALL, bgColor=self._backgroundColor)
     38 
     39     def ToggleExpand(self):
     40         if self._is_collapsed:
     41             self.sub_cont.maxHeight = None
     42             self._is_collapsed = False
     43         else:
     44             self._is_collapsed = True
     45             self.sub_cont.maxHeight = self._collapsed_height
     46         self.update_collapse_display()
     47 
     48     def set_text(self, text, show_all = False):
     49         self._show_all = show_all
     50         self.lore.text = text
     51         self.update_collapse_display()
     52 
     53     def update_collapse_display(self):
     54         if not self.container_bottom_line_expander or not self.container_bottom_line_simple:
     55             return
     56         new_max_height = None
     57         if self.is_expander_needed() and not self._show_all:
     58             self.container_bottom_line_expander.Show()
     59             self.container_bottom_line_simple.Hide()
     60             if self._is_collapsed:
     61                 new_max_height = self._collapsed_height
     62         else:
     63             self.container_bottom_line_expander.Hide()
     64             self.container_bottom_line_simple.Show()
     65         self.sub_cont.maxHeight = new_max_height
     66         if self.sub_cont.maxHeight:
     67             self.lore.SetBottomAlphaFade(self._collapsed_height, self._maxFadeHeight)
     68             self.expander_icon.SetTexturePath(eveicon.chevron_down_double)
     69         else:
     70             self.lore.SetBottomAlphaFade()
     71             self.expander_icon.SetTexturePath(eveicon.chevron_up_double)
     72 
     73     def is_expander_needed(self):
     74         text_height = self.lore.textheight
     75         return text_height > self._collapsed_height + 6
     76 
     77     def _build_simple_bottom_line(self):
     78         self.container_bottom_line_simple = Container(name='container_bottom_line_simple', parent=self, align=uiconst.TOTOP, height=20, padTop=4)
     79         Line(name='simple_line', parent=self.container_bottom_line_simple, align=uiconst.TOTOP, weight=self.LINE_HEIGHT, top=self.LINE_TOP)
     80 
     81     def _build_expander_bottom_line(self):
     82         self.container_bottom_line_expander = Container(name='container_bottom_line_expander', parent=self, align=uiconst.TOTOP, pickState=PickState.ON, height=20, padTop=4)
     83         self.container_bottom_line_expander.OnClick = self.ToggleExpand
     84         left_cont = Container(name='left_cont', parent=self.container_bottom_line_expander, align=uiconst.TOLEFT_PROP, width=0.5, padRight=16)
     85         Line(name='bottom_line_left', parent=left_cont, align=uiconst.TOTOP, weight=self.LINE_HEIGHT, top=self.LINE_TOP)
     86         right_cont = Container(name='right_cont', parent=self.container_bottom_line_expander, align=uiconst.TORIGHT_PROP, width=0.5, padLeft=16)
     87         Line(name='bottom_line_right', parent=right_cont, align=uiconst.TOTOP, weight=self.LINE_HEIGHT, top=self.LINE_TOP)
     88         self.expander_icon = ButtonIcon(parent=self.container_bottom_line_expander, align=uiconst.CENTER, width=20, height=20, iconSize=16, texturePath=eveicon.chevron_down_double, func=self.ToggleExpand, iconColor=TextColor.SECONDARY)
     89         self.container_bottom_line_expander.Hide()
     90 
     91     def _OnResize(self, *args):
     92         self.update_collapse_display()