Added entity filering support and fixed minor bug

This commit is contained in:
Mergul 2020-06-10 15:35:42 +02:00
parent 5018464a41
commit 8cba2626be
3 changed files with 48 additions and 12 deletions

View file

@ -27,6 +27,8 @@ struct GUIManager
Vector!ComponentGUI components;
Vector!TemplateGUI templates;
Vector!ComponentEditGUI edit_components;
Vector!bool filter;
Vector!ushort filter_list;
int selected_template = 0;
int selected_component = 0;
@ -62,8 +64,14 @@ struct GUIManager
if(comp.variables)Mallocator.dispose(comp.variables);
comp.variables = null;
comp.used = 0;
comp.name = null;
}
foreach(ref comp; filter)
{
comp = false;
}
filter_list.clear();
systems.clear();
templates.clear();
components.clear();
@ -384,16 +392,14 @@ struct GUIManager
{
if(igListBoxHeaderInt("Components",cast(int)components.length,cast(int)components.length))
{
foreach(i, comp; components)
{
foreach(i, comp; components)
if(igSelectable(comp.name,selected_component == i,0,ImVec2(0,0)))
{
if(igSelectable(comp.name,selected_component == i,0,ImVec2(0,0)))
{
selected_component = cast(uint)i;
}
selected_component = cast(uint)i;
}
igListBoxFooter();
}
igListBoxFooter();
}
if(igIsItemHovered(0))igSetTooltip("Select component to add/remove (SHIFT + Scroll)");
}
@ -407,26 +413,40 @@ struct GUIManager
style.Colors[ImGuiCol_Header] = col;
}
private void genFilterList()
{
filter_list.clear();
foreach(i, comp; filter)
{
if(comp)
{
filter_list.add(cast(ushort)i);
}
}
}
void filterGUI()
{
ImGuiStyle * style = igGetStyle();
ImVec4 col = style.Colors[ImGuiCol_Header];
style.Colors[ImGuiCol_Header] = style.Colors[ImGuiCol_TextSelectedBg];
if(filter.length < edit_components.length)filter.length(edit_components.length);
int length = 0;
foreach(comp; edit_components)
{
if(comp.name !is null)length++;
}
if(length && igListBoxHeaderInt("Components",cast(int)length,cast(int)length))
if(length && igListBoxHeaderInt("Components##FilterComponents",cast(int)length,cast(int)length))
{
foreach(i, comp; edit_components)
foreach(i, ref comp; edit_components)
{
if(comp.name is null)return;
if(igSelectable(comp.name,false,0,ImVec2(0,0)))
if(comp.name is null)continue;
if(igSelectableBoolPtr(comp.name,&filter[i],0,ImVec2(0,0)))
{
genFilterList();
}
}
igListBoxFooter();