Example #1
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiLabel));

            string fontName    = file["Font"] as string;
            int    fontSize    = DefinitionResolver.Get <int>(Controller, Binding, file["FontSize"], 0);
            int    fontSpacing = DefinitionResolver.Get <int>(Controller, Binding, file["FontSpacing"], 0);

            _font = new UiFont(fontName, fontSize, fontSpacing);

            _lineHeight = DefinitionResolver.Get <int>(Controller, Binding, file["LineHeight"], 100);

            _textMargin = DefinitionResolver.Get <Margin>(Controller, Binding, file["TextMargin"], Margin.None);

            _rotation = DefinitionResolver.Get <TextRotation>(Controller, Binding, file["TextRotation"], TextRotation.None);

            _maxWidth = DefinitionResolver.Get <Length>(Controller, Binding, file["MaxWidth"], new Length(pixels: int.MaxValue));

            Text = DefinitionResolver.GetSharedString(Controller, Binding, file["Text"]);

            if (Text == null)
            {
                return(false);
            }

            TextColor = DefinitionResolver.GetColorWrapper(Controller, Binding, file["TextColor"]) ?? DefaultTextColor;

            HorizontalContentAlignment horzAlign = DefinitionResolver.Get <HorizontalContentAlignment>(Controller, Binding, file["HorizontalContentAlignment"], HorizontalContentAlignment.Auto);
            VerticalContentAlignment   vertAlign = DefinitionResolver.Get <VerticalContentAlignment>(Controller, Binding, file["VerticalContentAlignment"], VerticalContentAlignment.Auto);

            if (horzAlign == HorizontalContentAlignment.Auto)
            {
                horzAlign = UiHelper.ContentAlignFromAlignment(PositionParameters.HorizontalAlignment);
            }

            if (vertAlign == VerticalContentAlignment.Auto)
            {
                vertAlign = UiHelper.ContentAlignFromAlignment(PositionParameters.VerticalAlignment);
            }

            TextAlign = UiHelper.TextAlignFromContentAlignment(horzAlign, vertAlign);

            if (DefinitionResolver.Get <bool>(Controller, Binding, file["AutoSizeUpdate"], false))
            {
                Text.ValueChanged += Text_ValueChanged;
            }

            return(true);
        }