ui_list.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import bpy
  2. class MESH_UL_mylist(bpy.types.UIList):
  3. # Constants (flags)
  4. # Be careful not to shadow FILTER_ITEM (i.e. UIList().bitflag_filter_item)!
  5. # E.g. VGROUP_EMPTY = 1 << 0
  6. # Custom properties, saved with .blend file. E.g.
  7. # use_filter_empty: bpy.props.BoolProperty(
  8. # name="Filter Empty", default=False, options=set(),
  9. # description="Whether to filter empty vertex groups",
  10. # )
  11. # Called for each drawn item.
  12. def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index, flt_flag):
  13. # 'DEFAULT' and 'COMPACT' layout types should usually use the same draw code.
  14. if self.layout_type in {'DEFAULT', 'COMPACT'}:
  15. pass
  16. # 'GRID' layout type should be as compact as possible (typically a single icon!).
  17. elif self.layout_type in {'GRID'}:
  18. pass
  19. # Called once to draw filtering/reordering options.
  20. def draw_filter(self, context, layout):
  21. # Nothing much to say here, it's usual UI code...
  22. pass
  23. # Called once to filter/reorder items.
  24. def filter_items(self, context, data, propname):
  25. # This function gets the collection property (as the usual tuple (data, propname)), and must return two lists:
  26. # * The first one is for filtering, it must contain 32bit integers were self.bitflag_filter_item marks the
  27. # matching item as filtered (i.e. to be shown), and 31 other bits are free for custom needs. Here we use the
  28. # first one to mark VGROUP_EMPTY.
  29. # * The second one is for reordering, it must return a list containing the new indices of the items (which
  30. # gives us a mapping org_idx -> new_idx).
  31. # Please note that the default UI_UL_list defines helper functions for common tasks (see its doc for more info).
  32. # If you do not make filtering and/or ordering, return empty list(s) (this will be more efficient than
  33. # returning full lists doing nothing!).
  34. # Default return values.
  35. flt_flags = []
  36. flt_neworder = []
  37. # Do filtering/reordering here...
  38. return flt_flags, flt_neworder