/// <summary> /// create a UI data row /// </summary> /// <param name="top">top position</param> /// <param name="namePrefix">component name prefix</param> /// <param name="text">description text</param> /// <param name="dataRow">ouitput the UI data row</param> /// <returns>success status</returns> private bool CreateDataRow(float top, string namePrefix, string text, out DataRowUI dataRow) { // create new worker data dataRow = new DataRowUI(); // create label for description dataRow.description = AddUIComponent<UILabel>(); if (dataRow.description == null) { Debug.LogError($"Unable to create description label for [{namePrefix}] on panel [{name}]."); return false; } dataRow.description.name = namePrefix + "Description"; dataRow.description.font = _textFont; dataRow.description.text = text; dataRow.description.textAlignment = UIHorizontalAlignment.Left; dataRow.description.verticalAlignment = UIVerticalAlignment.Bottom; dataRow.description.textScale = 0.875f; dataRow.description.textColor = HeadingTextColor; dataRow.description.autoSize = false; dataRow.description.size = new Vector2(100f, TextHeight); dataRow.description.relativePosition = new Vector3(8f, top); dataRow.description.isVisible = true; // create count labels if (!CreateCountLabel(0f, top, namePrefix + "Level0", dataRow.description, out dataRow.eduLevel0)) return false; if (!CreateCountLabel(0f, top, namePrefix + "Level1", dataRow.eduLevel0, out dataRow.eduLevel1)) return false; if (!CreateCountLabel(0f, top, namePrefix + "Level2", dataRow.eduLevel1, out dataRow.eduLevel2)) return false; if (!CreateCountLabel(0f, top, namePrefix + "Level3", dataRow.eduLevel2, out dataRow.eduLevel3)) return false; if (!CreateCountLabel(0f, top, namePrefix + "Total", dataRow.eduLevel3, out dataRow.total )) return false; if (!CreateCountLabel(12f, top, namePrefix + "MovingIn", dataRow.total, out dataRow.movingIn )) return false; if (!CreateCountLabel(0f, top, namePrefix + "Deceased", dataRow.movingIn, out dataRow.deceased )) return false; // success return true; }
/// <summary> /// display a data row on the UI /// </summary> /// <param name="dataRowUI">the data row UI on which to display the data</param> /// <param name="dataRow">the data to be displayed</param> /// <param name="useRowTotalForPercent">whether or not education levels should be displayed as percent of total for that row</param> private void DisplayDataRow(DataRowUI dataRowUI, DataRow dataRow, bool useRowTotalForPercent) { // check if count or percent if (IsCheckBoxChecked(_countCheckBox)) { dataRowUI.eduLevel0.text = dataRow.eduLevel0.ToString("N0", LocaleManager.cultureInfo); dataRowUI.eduLevel1.text = dataRow.eduLevel1.ToString("N0", LocaleManager.cultureInfo); dataRowUI.eduLevel2.text = dataRow.eduLevel2.ToString("N0", LocaleManager.cultureInfo); dataRowUI.eduLevel3.text = dataRow.eduLevel3.ToString("N0", LocaleManager.cultureInfo); dataRowUI.total.text = dataRow.total.ToString("N0", LocaleManager.cultureInfo); dataRowUI.movingIn.text = dataRow.movingIn.ToString("N0", LocaleManager.cultureInfo); dataRowUI.deceased.text = dataRow.deceased.ToString("N0", LocaleManager.cultureInfo); } else { dataRowUI.eduLevel0.text = FormatPercent(dataRow.eduLevel0, (useRowTotalForPercent ? dataRow.total : _finalCount.total.total)); dataRowUI.eduLevel1.text = FormatPercent(dataRow.eduLevel1, (useRowTotalForPercent ? dataRow.total : _finalCount.total.total)); dataRowUI.eduLevel2.text = FormatPercent(dataRow.eduLevel2, (useRowTotalForPercent ? dataRow.total : _finalCount.total.total)); dataRowUI.eduLevel3.text = FormatPercent(dataRow.eduLevel3, (useRowTotalForPercent ? dataRow.total : _finalCount.total.total)); dataRowUI.total.text = FormatPercent(dataRow.total, (useRowTotalForPercent ? dataRow.total : _finalCount.total.total)); dataRowUI.movingIn.text = FormatPercent(dataRow.movingIn, _finalCount.movingIn.total); dataRowUI.deceased.text = FormatPercent(dataRow.deceased, _finalCount.deceased.total); } }