Exemple #1
0
    private void RenderTableHeadings()
    {
        KGFGUIUtility.BeginHorizontalBox(KGFGUIUtility.eStyleBox.eBoxDarkTop, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(false));
        {
            foreach (KGFDataColumn aColumn in itsDataTable.Columns)
            {
                // check if visible is set to true
                if (itsColumnVisible[aColumn])
                {
                    // check if the width is fixed size
                    if (itsColumnWidth[aColumn] != 0)
                    {
                        KGFGUIUtility.Label(aColumn.ColumnName, KGFGUIUtility.eStyleLabel.eLabelFitIntoBox, GUILayout.Width(itsColumnWidth[aColumn]));
                    }
                    else
                    {
                        KGFGUIUtility.Label(aColumn.ColumnName, KGFGUIUtility.eStyleLabel.eLabelFitIntoBox, GUILayout.ExpandWidth(true));
                    }

                    KGFGUIUtility.Separator(KGFGUIUtility.eStyleSeparator.eSeparatorVerticalFitInBox);
                }
            }
        }
        KGFGUIUtility.EndHorizontalBox();
    }
    private void RenderTableHeadings()
    {
        if (itsTextureArrowDown == null)
        {
            LoadTextures();
        }

        KGFGUIUtility.BeginHorizontalBox(KGFGUIUtility.eStyleBox.eBoxDarkTop, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(false));
        {
            foreach (KGFDataColumn aColumn in itsDataTable.Columns)
            {
                // check if visible is set to true
                if (itsColumnVisible[aColumn])
                {
                    GUILayoutOption[] anOptions;

                    // check if the width is fixed size
                    if (itsColumnWidth[aColumn] != 0)
                    {
                        anOptions = new GUILayoutOption[] { GUILayout.Width(itsColumnWidth[aColumn]) };
                    }
                    else
                    {
                        anOptions = new GUILayoutOption[] { GUILayout.ExpandWidth(true) };
                    }

                    GUILayout.BeginHorizontal(anOptions);
                    {
                        KGFGUIUtility.Label(aColumn.ColumnName, KGFGUIUtility.eStyleLabel.eLabelFitIntoBox);

                        if (aColumn == itsSortColumn)
                        {
                            if (itsSortDirection)
                            {
                                KGFGUIUtility.Label("", itsTextureArrowDown, KGFGUIUtility.eStyleLabel.eLabelFitIntoBox, GUILayout.Width(14));
                            }
                            else
                            {
                                KGFGUIUtility.Label("", itsTextureArrowUp, KGFGUIUtility.eStyleLabel.eLabelFitIntoBox, GUILayout.Width(14));
                            }
                        }
                    }
                    GUILayout.EndHorizontal();

                    if (Event.current.type == EventType.MouseUp &&
                        GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
                    {
                        SortColumn(aColumn);
                    }

                    KGFGUIUtility.Separator(KGFGUIUtility.eStyleSeparator.eSeparatorVerticalFitInBox);
                }
            }
        }
        KGFGUIUtility.EndHorizontalBox();
    }
    /// <summary>
    /// Render this control
    /// </summary>
    public void Render()
    {
        if (itsUpdateWish)
        {
            UpdateList();
        }

        int itsNumberOfPages = (int)Math.Ceiling((float)itsData.Rows.Count / (float)itsItemsPerPage);

        if (itsCurrentPage >= itsNumberOfPages)
        {
            itsCurrentPage = 0;
        }

        itsRepaintWish = false;
        itsGuiData.SetDisplayRowCount((uint)itsItemsPerPage);

        KGFGUIUtility.BeginHorizontalBox(KGFGUIUtility.eStyleBox.eBoxDecorated);
        {
            // categories view
            GUILayout.BeginVertical(GUILayout.Width(180));
            {
                itsListViewCategories.Render();
            }
            GUILayout.EndVertical();

            KGFGUIUtility.SpaceSmall();

            GUILayout.BeginVertical();
            {
                // item table
                itsGuiData.SetStartRow((uint)(itsCurrentPage * (uint)itsItemsPerPage));
                itsGuiData.Render();

                KGFGUIUtility.BeginHorizontalBox(KGFGUIUtility.eStyleBox.eBoxMiddleVerticalInteractive);
                {
                    // enum filter boxes
                    int aColumnNo = 0;
//						KGFGUIUtility.SpaceSmall();
                    foreach (KGFObjectListColumnItem anItem in itsListFieldCache)
                    {
                        aColumnNo++;

                        if (!anItem.itsDisplay)
                        {
                            continue;
                        }
                        if (!itsGuiData.GetColumnVisible(aColumnNo))
                        {
                            continue;
                        }

                        if (anItem.itsSearchable && (anItem.GetReturnType().IsEnum ||
                                                     anItem.GetReturnType() == typeof(bool) ||
                                                     anItem.GetReturnType() == typeof(string)))
                        {
                            GUILayout.BeginHorizontal(GUILayout.Width(itsGuiData.GetColumnWidth(aColumnNo)));
                            {
                                KGFGUIUtility.BeginVerticalBox(KGFGUIUtility.eStyleBox.eBoxInvisible);
                                DrawFilterBox(anItem, itsGuiData.GetColumnWidth(aColumnNo) - 4);
                                KGFGUIUtility.EndVerticalBox();
                            }
                            GUILayout.EndHorizontal();
                            KGFGUIUtility.Separator(KGFGUIUtility.eStyleSeparator.eSeparatorVerticalFitInBox);
                        }
                        else
                        {
                            GUILayout.BeginHorizontal(GUILayout.Width(itsGuiData.GetColumnWidth(aColumnNo)));
                            {
                                GUILayout.Label(" ");
                            }
                            GUILayout.EndHorizontal();
                            KGFGUIUtility.Separator(KGFGUIUtility.eStyleSeparator.eSeparatorVerticalFitInBox);
                            continue;
                        }
                    }
                    GUILayout.FlexibleSpace();
                }
                KGFGUIUtility.EndHorizontalBox();

                KGFGUIUtility.BeginHorizontalBox(KGFGUIUtility.eStyleBox.eBoxDarkMiddleVertical);
                {
                    GUILayout.Label("");
                    GUILayout.FlexibleSpace();
                }
                KGFGUIUtility.EndHorizontalBox();

                KGFGUIUtility.BeginVerticalBox(KGFGUIUtility.eStyleBox.eBoxDarkBottom);
                {
                    GUILayout.BeginHorizontal();
                    {
                        if (!Application.isPlaying)
                        {
                            if (EventNew != null)
                            {
                                if (KGFGUIUtility.Button("New", KGFGUIUtility.eStyleButton.eButton, GUILayout.Width(75)))
                                {
                                    EventNew(this, null);
                                }
                            }
                            if (EventDelete != null)
                            {
                                if (KGFGUIUtility.Button("Delete", KGFGUIUtility.eStyleButton.eButton, GUILayout.Width(75)))
                                {
                                    EventDelete(this, null);
                                }
                            }

                            GUILayout.FlexibleSpace();
                        }

                        // full text search box
                        if (itsDisplayFullTextSearch)
                        {
                            GUI.SetNextControlName(itsControlSearchName);
                            string aNewString = KGFGUIUtility.TextField(itsFulltextSearch, KGFGUIUtility.eStyleTextField.eTextField, GUILayout.Width(200));
                            if (aNewString != itsFulltextSearch)
                            {
                                itsFulltextSearch = aNewString;
                                UpdateList();
                            }
                        }

                        KGFGUIUtility.Space();

                        bool anIncludeAll = KGFGUIUtility.Toggle(itsIncludeAll, "all Tags", KGFGUIUtility.eStyleToggl.eTogglSuperCompact, GUILayout.Width(70));
                        if (anIncludeAll != itsIncludeAll)
                        {
                            itsIncludeAll = anIncludeAll;
                            UpdateList();
                        }

                        if (KGFGUIUtility.Button("clear filters", KGFGUIUtility.eStyleButton.eButton, GUILayout.Width(100)))
                        {
                            itsFulltextSearch = "";
                            ClearFilters();
                            UpdateList();
                        }

                        GUILayout.FlexibleSpace();

                        KGFGUIUtility.BeginHorizontalBox(KGFGUIUtility.eStyleBox.eBoxInvisible);
                        {
                            if (GetDisplayEntriesPerPage())
                            {
                                //number of items in List
                                if (KGFGUIUtility.Button("<", KGFGUIUtility.eStyleButton.eButtonLeft, GUILayout.Width(25)))
                                {
                                    switch (itsItemsPerPage)
                                    {
                                    case KGFeItemsPerPage.e25:
                                        itsItemsPerPage = KGFeItemsPerPage.e10;
                                        break;

                                    case KGFeItemsPerPage.e50:
                                        itsItemsPerPage = KGFeItemsPerPage.e25;
                                        break;

                                    case KGFeItemsPerPage.e100:
                                        itsItemsPerPage = KGFeItemsPerPage.e50;
                                        break;

                                    case KGFeItemsPerPage.e250:
                                        itsItemsPerPage = KGFeItemsPerPage.e100;
                                        break;

                                    case KGFeItemsPerPage.e500:
                                        itsItemsPerPage = KGFeItemsPerPage.e250;
                                        break;

                                    default:
                                        break;
                                    }
                                }

                                KGFGUIUtility.BeginVerticalBox(KGFGUIUtility.eStyleBox.eBoxMiddleHorizontal);
                                {
                                    string aLogsPerPageString = itsItemsPerPage.ToString().Substring(1) + " entries per page";
                                    KGFGUIUtility.Label(aLogsPerPageString, KGFGUIUtility.eStyleLabel.eLabelFitIntoBox);
                                }
                                KGFGUIUtility.EndVerticalBox();

                                if (KGFGUIUtility.Button(">", KGFGUIUtility.eStyleButton.eButtonRight, GUILayout.Width(25)))
                                {
                                    switch (itsItemsPerPage)
                                    {
                                    case KGFeItemsPerPage.e10:
                                        itsItemsPerPage = KGFeItemsPerPage.e25;
                                        break;

                                    case KGFeItemsPerPage.e25:
                                        itsItemsPerPage = KGFeItemsPerPage.e50;
                                        break;

                                    case KGFeItemsPerPage.e50:
                                        itsItemsPerPage = KGFeItemsPerPage.e100;
                                        break;

                                    case KGFeItemsPerPage.e100:
                                        itsItemsPerPage = KGFeItemsPerPage.e250;
                                        break;

                                    case KGFeItemsPerPage.e250:
                                        itsItemsPerPage = KGFeItemsPerPage.e500;
                                        break;

                                    default:
                                        break;
                                    }
                                }
                            }

                            GUILayout.Space(10.0f);

                            // page control
                            if (KGFGUIUtility.Button("<", KGFGUIUtility.eStyleButton.eButtonLeft, GUILayout.Width(25)) && itsCurrentPage > 0)
                            {
                                itsCurrentPage--;
                            }

                            KGFGUIUtility.BeginVerticalBox(KGFGUIUtility.eStyleBox.eBoxMiddleHorizontal);
                            {
                                string aString = string.Format("page {0}/{1}", itsCurrentPage + 1, Math.Max(itsNumberOfPages, 1));
                                KGFGUIUtility.Label(aString, KGFGUIUtility.eStyleLabel.eLabelFitIntoBox);
                            }
                            KGFGUIUtility.EndVerticalBox();

                            if (KGFGUIUtility.Button(">", KGFGUIUtility.eStyleButton.eButtonRight, GUILayout.Width(25)) && itsData.Rows.Count > ((itsCurrentPage + 1) * (int)itsItemsPerPage))
                            {
                                itsCurrentPage++;
                            }
                        }
                        KGFGUIUtility.EndHorizontalBox();
                    }
                    GUILayout.EndHorizontal();
                }
                KGFGUIUtility.EndVerticalBox();
            }
            GUILayout.EndVertical();
        }
        KGFGUIUtility.EndHorizontalBox();

        if (GUI.GetNameOfFocusedControl().Equals(itsControlSearchName))
        {
            if (itsFulltextSearch.Equals(itsTextSearch))
            {
                itsFulltextSearch = string.Empty;
            }
        }

        if (!GUI.GetNameOfFocusedControl().Equals(itsControlSearchName))
        {
            if (itsFulltextSearch.Equals(string.Empty))
            {
                itsFulltextSearch = itsTextSearch;
            }
        }
    }
Exemple #4
0
    private void RenderTableRows()
    {
        itsDataTableScrollViewPosition = KGFGUIUtility.BeginScrollView(itsDataTableScrollViewPosition, false, itsForceDisplayVerticalSlider, GUILayout.ExpandHeight(true));
        {
            //Log List Heading
            RenderTableHeadings();

            if (itsDataTable.Rows.Count > 0)
            {
                GUILayout.BeginVertical();
                {
                    Color aDefaultColor = GUI.color;

                    for (int aRowIndex = (int)itsStartRow; aRowIndex < itsStartRow + itsDisplayRowCount && aRowIndex < itsDataTable.Rows.Count; aRowIndex++)
                    {
                        KGFDataRow aRow = itsDataTable.Rows[aRowIndex];

                        //Pre Row Hook
                        if (PreRenderRow != null)
                        {
                            PreRenderRow(aRow, EventArgs.Empty);
                        }

                        if (aRow == itsCurrentSelected)
                        {
                            KGFGUIUtility.BeginHorizontalBox(KGFGUIUtility.eStyleBox.eBoxDarkTopInteractive, GUILayout.ExpandWidth(true));
                        }
                        else
                        {
                            KGFGUIUtility.BeginHorizontalBox(KGFGUIUtility.eStyleBox.eBoxMiddleVerticalInteractive, GUILayout.ExpandWidth(true));
                        }

                        //Row
                        {
                            foreach (KGFDataColumn aColumn in itsDataTable.Columns)
                            {
                                //check if the column is visible
                                if (itsColumnVisible[aColumn])
                                {
                                    //Pre Column Hook
                                    if (PreRenderColumn != null)
                                    {
                                        PreRenderColumn(aColumn, EventArgs.Empty);
                                    }

                                    bool aCustomDrawer = false;
                                    if (PreCellContentHandler != null)
                                    {
                                        aCustomDrawer = PreCellContentHandler(aRow, aColumn);
                                    }

                                    if (!aCustomDrawer)
                                    {
                                        // crate the string
                                        int    itsStringMaxLenght = 85;
                                        string aString            = aRow[aColumn].ToString().Substring(0, Math.Min(itsStringMaxLenght, aRow[aColumn].ToString().Length));

                                        if (aString.Length == itsStringMaxLenght)
                                        {
                                            aString += "...";
                                        }

                                        if (itsColumnWidth[aColumn] > 0)
                                        {
                                            KGFGUIUtility.Label(aString, KGFGUIUtility.eStyleLabel.eLabelFitIntoBox, GUILayout.Width(itsColumnWidth[aColumn]));
                                        }
                                        else
                                        {
                                            KGFGUIUtility.Label(aString, KGFGUIUtility.eStyleLabel.eLabelFitIntoBox, GUILayout.ExpandWidth(true));
                                        }
                                    }

                                    KGFGUIUtility.Separator(KGFGUIUtility.eStyleSeparator.eSeparatorVerticalFitInBox);

                                    //Post Column Hook
                                    if (PostRenderColumn != null)
                                    {
                                        PostRenderColumn(aColumn, EventArgs.Empty);
                                    }
                                }
                            }
                        }
                        KGFGUIUtility.EndHorizontalBox();

                        //check if the rect contains the mouse and the pressed mouse button is the left mouse button
                        if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition) && Event.current.type == EventType.MouseDown && Event.current.button == 0)
                        {
                            itsClickedRow = aRow;
                        }

                        //only send this event on layouting
                        if (OnClickRow != null && itsClickedRow != null && Event.current.type == EventType.Layout)
                        {
                            if (itsCurrentSelected != itsClickedRow)
                            {
                                itsCurrentSelected = itsClickedRow;
                                //Debug.Log("itsCurrentSelected is set");
                            }
                            else
                            {
                                itsCurrentSelected = null;
                            }

                            OnClickRow(itsClickedRow, EventArgs.Empty);
                            itsClickedRow = null;
                            //Debug.Log("itsClickedRow is set to null");
                        }

                        //Post Row Hook
                        if (PostRenderRow != null)
                        {
                            PostRenderRow(aRow, EventArgs.Empty);
                        }
                    }
                    GUI.color = aDefaultColor;
                    GUILayout.FlexibleSpace();
                }
                GUILayout.EndVertical();
            }
            else
            {
                GUILayout.Label("no items found");
                GUILayout.FlexibleSpace();
            }
        }
        GUILayout.EndScrollView();
    }