コード例 #1
0
        public static LayoutValue FromString(string str)
        {
            LayoutValue dimension = new LayoutValue();
            int         value;

            if (str.EndsWith("px"))
            {
                str = str.TrimEnd('p', 'x', ' ');
                int.TryParse(str, out value);
                dimension.Type = ValueType.Pixel;
            }
            else if (str.EndsWith("%"))
            {
                str = str.TrimEnd('%', ' ');
                int.TryParse(str, out value);
                dimension.Type = ValueType.Percent;
            }
            else
            {
                int.TryParse(str, out value);
                dimension.Type = ValueType.Pixel;
            }

            dimension.Value    = value;
            dimension.RawValue = str;

            return(dimension);
        }
コード例 #2
0
        public static int GetPixelSize(LayoutValue inputValue, int parentValue)
        {
            int value = inputValue.Value;

            if (inputValue.Type == ValueType.Percent)
            {
                value = (int)(value * (parentValue / 100f));
            }

            return(value);
        }