private void OnPortGUI(Rect portPosition, IUnitPort port)
        {
            var portDescription = port.Description <UnitPortDescription>();

            var labelWidth = portPosition.width - Styles.portIcon.fixedWidth - Styles.portIcon.margin.right;

            var iconPosition = new Rect
                               (
                portPosition.x,
                portPosition.y,
                Styles.portIcon.fixedWidth,
                Styles.portIcon.fixedHeight
                               );

            var icon = portDescription.icon?[IconSize.Small];

            if (icon != null)
            {
                GUI.DrawTexture(iconPosition, icon);
            }

            var labelContent = GetLabelContent(port);

            var labelPosition = new Rect
                                (
                iconPosition.xMax + Styles.portIcon.margin.right,
                portPosition.y,
                labelWidth,
                Styles.portLabel.CalcHeight(labelContent, labelWidth)
                                );

            GUI.Label(labelPosition, labelContent, Styles.portLabel);

            var summary = portDescription.summary;

            if (!StringUtility.IsNullOrWhiteSpace(summary))
            {
                var descriptionContent = new GUIContent(summary);

                var descriptionPosition = new Rect
                                          (
                    labelPosition.x,
                    labelPosition.yMax,
                    labelWidth,
                    Styles.portDescription.CalcHeight(descriptionContent, labelWidth)
                                          );

                GUI.Label(descriptionPosition, descriptionContent, Styles.portDescription);
            }
        }
        private float GetPortHeight(float paddedWidth, IUnitPort port)
        {
            var portDescription = port.Description <UnitPortDescription>();

            var labelWidth = paddedWidth - Styles.portIcon.fixedWidth - Styles.portIcon.margin.right;

            var height = 0f;

            height += Styles.portLabel.CalcHeight(GetLabelContent(port), labelWidth);

            var summary = portDescription.summary;

            if (!StringUtility.IsNullOrWhiteSpace(summary))
            {
                height += Styles.portDescription.CalcHeight(new GUIContent(summary), labelWidth);
            }

            return(height);
        }
        private GUIContent GetLabelContent(IUnitPort port)
        {
            string type;

            if (port is IUnitControlPort)
            {
                type = "Flow";
            }
            else if (port is IUnitValuePort)
            {
                type = ((IUnitValuePort)port).type.DisplayName();
            }
            else if (port is IUnitInvalidPort)
            {
                type = "Invalid";
            }
            else
            {
                throw new NotSupportedException();
            }

            return(new GUIContent(string.Format($"<b>{port.Description<UnitPortDescription>().label}</b> <color=#{ColorPalette.unityForegroundDim.ToHexString()}>: {LudiqGUIUtility.EscapeRichText(type)}</color>")));
        }
Exemple #4
0
 protected UnitPortDescription PortDescription(IUnitPort port)
 {
     return(port.Description <UnitPortDescription>());
 }
Exemple #5
0
 private string PortLabel(IUnitPort port)
 {
     return(port.Description <UnitPortDescription>().label);
 }