public static LegendItem AddLegendItem(Legend legend, int i, string legendName, Transform parent, ThemeInfo themeInfo,
                                               string content, Color itemColor, bool active)
        {
            var objName       = i + "_" + legendName;
            var anchorMin     = new Vector2(0, 0.5f);
            var anchorMax     = new Vector2(0, 0.5f);
            var pivot         = new Vector2(0, 0.5f);
            var sizeDelta     = new Vector2(100, 30);
            var iconSizeDelta = new Vector2(legend.itemWidth, legend.itemHeight);
            var textStyle     = legend.textStyle;
            var font          = textStyle.font ? textStyle.font : themeInfo.font;
            var contentColor  = GetContentColor(legend, themeInfo, active);

            var objAnchorMin = legend.location.runtimeAnchorMin;
            var objAnchorMax = legend.location.runtimeAnchorMax;
            var objPivot     = legend.location.runtimePivot;

            var btnObj     = ChartHelper.AddObject(objName, parent, objAnchorMin, objAnchorMax, objPivot, sizeDelta);
            var iconObj    = ChartHelper.AddObject("icon", btnObj.transform, anchorMin, anchorMax, pivot, iconSizeDelta);
            var contentObj = ChartHelper.AddObject("content", btnObj.transform, anchorMin, anchorMax, pivot, sizeDelta);
            var img        = ChartHelper.GetOrAddComponent <Image>(btnObj);

            img.color = Color.clear;
            ChartHelper.GetOrAddComponent <Button>(btnObj);
            ChartHelper.GetOrAddComponent <Image>(iconObj);
            ChartHelper.GetOrAddComponent <Image>(contentObj);
            Text txt = ChartHelper.AddTextObject("Text", contentObj.transform, font, contentColor,
                                                 TextAnchor.MiddleLeft, anchorMin, anchorMax, pivot, sizeDelta, textStyle.fontSize,
                                                 textStyle.rotate, textStyle.fontStyle, textStyle.lineSpacing);
            var item = new LegendItem();

            item.index      = i;
            item.name       = objName;
            item.legendName = legendName;
            item.SetObject(btnObj);
            item.SetIconSize(legend.itemWidth, legend.itemHeight);
            item.SetIconColor(itemColor);
            item.SetIconImage(legend.GetIcon(i));
            item.SetContentPosition(textStyle.offsetv3);
            item.SetContent(content);
            item.SetContentBackgroundColor(textStyle.backgroundColor);
            return(item);
        }
Ejemplo n.º 2
0
        public static LegendItem AddLegendItem(Legend legend, int i, string legendName, Transform parent,
                                               ChartTheme theme, string content, Color itemColor, bool active, int legendIndex)
        {
            var objName       = i + "_" + legendName;
            var anchorMin     = new Vector2(0, 0.5f);
            var anchorMax     = new Vector2(0, 0.5f);
            var pivot         = new Vector2(0, 0.5f);
            var sizeDelta     = new Vector2(100, 30);
            var iconSizeDelta = new Vector2(legend.itemWidth, legend.itemHeight);
            var textStyle     = legend.textStyle;
            var contentColor  = GetContentColor(legendIndex, legend, theme, active);

            var objAnchorMin = new Vector2(0, 1);
            var objAnchorMax = new Vector2(0, 1);
            var objPivot     = new Vector2(0, 1);
            var btnObj       = ChartHelper.AddObject(objName, parent, objAnchorMin, objAnchorMax, objPivot, sizeDelta, i);
            var iconObj      = ChartHelper.AddObject("icon", btnObj.transform, anchorMin, anchorMax, pivot, iconSizeDelta);
            var contentObj   = ChartHelper.AddObject("content", btnObj.transform, anchorMin, anchorMax, pivot, sizeDelta);
            var img          = ChartHelper.GetOrAddComponent <Image>(btnObj);

            img.color = Color.clear;
            ChartHelper.GetOrAddComponent <Button>(btnObj);
            ChartHelper.GetOrAddComponent <Image>(iconObj);
            ChartHelper.GetOrAddComponent <Image>(contentObj);
            var txt = ChartHelper.AddTextObject("Text", contentObj.transform, anchorMin, anchorMax, pivot, sizeDelta,
                                                textStyle, theme.legend);

            txt.SetAlignment(textStyle.GetAlignment(TextAnchor.MiddleLeft));
            txt.SetColor(contentColor);
            var item = new LegendItem();

            item.index      = i;
            item.name       = objName;
            item.legendName = legendName;
            item.SetObject(btnObj);
            item.SetIconSize(legend.itemWidth, legend.itemHeight);
            item.SetIconColor(itemColor);
            item.SetIconImage(legend.GetIcon(i));
            item.SetContentPosition(textStyle.offsetv3);
            item.SetContent(content);
            item.SetContentBackgroundColor(textStyle.backgroundColor);
            return(item);
        }