diff --git a/korman/ui/__init__.py b/korman/ui/__init__.py
index c334f8a..c1f3e3f 100644
--- a/korman/ui/__init__.py
+++ b/korman/ui/__init__.py
@@ -14,6 +14,7 @@
# along with Korman. If not, see .
from .ui_lamp import *
+from .ui_list import *
from .ui_menus import *
from .ui_modifiers import *
from .ui_object import *
diff --git a/korman/ui/ui_list.py b/korman/ui/ui_list.py
new file mode 100644
index 0000000..261c4dc
--- /dev/null
+++ b/korman/ui/ui_list.py
@@ -0,0 +1,46 @@
+# This file is part of Korman.
+#
+# Korman is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Korman is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Korman. If not, see .
+
+import bpy
+
+def draw_list(layout, listtype, context_attr, prop_base, collection_name, index_name, **kwargs):
+ """Draws a generic UI list, including add/remove buttons. Note that in order to use this,
+ the parent datablock must be available in the context provided to operators. This should
+ always be true, but this is Blender...
+ Arguments:
+ - layout: required
+ - listtype: bpy.types.UIList subclass
+ - context_attr: attribute name to get the properties from in the current context
+ - prop_base: property group owning the collection
+ - collection_name: name of the collection property
+ - index_name: name of the active element index property
+ *** any other arguments are passed as keyword arguments to the template_list call
+ """
+ prop_path = prop_base.path_from_id()
+ row = layout.row()
+ row.template_list(listtype, collection_name, prop_base, collection_name,
+ prop_base, index_name, **kwargs)
+ col = row.column(align=True)
+ op = col.operator("ui.plasma_collection_add", icon="ZOOMIN", text="")
+ op.context = context_attr
+ op.group_path = prop_path
+ op.collection_prop = collection_name
+ op.index_prop = index_name
+ op = col.operator("ui.plasma_collection_remove", icon="ZOOMOUT", text="")
+ op.context = context_attr
+ op.group_path = prop_path
+ op.collection_prop = collection_name
+ op.index_prop = index_name
+
diff --git a/korman/ui/ui_texture.py b/korman/ui/ui_texture.py
index 9821ca3..80b5d20 100644
--- a/korman/ui/ui_texture.py
+++ b/korman/ui/ui_texture.py
@@ -15,6 +15,8 @@
import bpy
+from . import ui_list
+
class TextureButtonsPanel:
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
@@ -42,20 +44,8 @@ class PlasmaEnvMapPanel(TextureButtonsPanel, bpy.types.Panel):
layout.separator()
layout.label("Visibility Sets:")
- row = layout.row()
- row.template_list("VisRegionListUI", "vis_regions", layer_props, "vis_regions", layer_props, "active_region_index",
- rows=2, maxrows=3)
- col = row.column(align=True)
- op = col.operator("ui.plasma_collection_add", icon="ZOOMIN", text="")
- op.context = "texture"
- op.group_path = "plasma_layer"
- op.collection_prop = "vis_regions"
- op.index_prop = "active_region_index"
- op = col.operator("ui.plasma_collection_remove", icon="ZOOMOUT", text="")
- op.context = "texture"
- op.group_path = "plasma_layer"
- op.collection_prop = "vis_regions"
- op.index_prop = "active_region_index"
+ ui_list.draw_list(layout, "VisRegionListUI", "texture", layer_props,
+ "vis_regions", "active_region_index", rows=2, maxrows=3)
rgns = layer_props.vis_regions
if layer_props.vis_regions:
layout.prop(rgns[layer_props.active_region_index], "control_region")