protected override void Init(UiController controller, object binding, DefinitionFile definition) { base.Init(controller, binding, definition); DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(Text)); string font = DefinitionResolver.GetString(controller, binding, file["Font"]); int fontSize = DefinitionResolver.Get <int>(controller, binding, file["FontSize"], 0); int fontSpacing = DefinitionResolver.Get <int>(controller, binding, file["FontSpacing"], 0); _lineHeight = DefinitionResolver.Get <int>(controller, binding, file["LineHeight"], 100); _font = new UiFont(font, fontSize, fontSpacing); _textRotation = DefinitionResolver.Get <TextRotation>(controller, binding, file["TextRotation"], TextRotation.None); HorizontalContentAlignment horzAlign = DefinitionResolver.Get <HorizontalContentAlignment>(controller, binding, file["HorizontalContentAlignment"], HorizontalContentAlignment.Center); VerticalContentAlignment vertAlign = DefinitionResolver.Get <VerticalContentAlignment>(controller, binding, file["VerticalContentAlignment"], VerticalContentAlignment.Center); _pathEllipsis = DefinitionResolver.Get <bool>(controller, binding, file["PathEllipsis"], false); _line = DefinitionResolver.Get <int>(controller, binding, file["Line"], -1); if (_pathEllipsis || _line >= 0) { _stringBuilder = new StringBuilder(); } _textAlign = UiHelper.TextAlignFromContentAlignment(horzAlign, vertAlign); _text = DefinitionResolver.GetSharedString(controller, binding, file["Text"]); }
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); }
protected override bool Init(object controller, object binding, DefinitionFile definition) { if (!base.Init(controller, binding, definition)) { return(false); } DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiEditBoxBase)); Hint = DefinitionResolver.GetSharedString(Controller, Binding, file["Hint"]) ?? new SharedString(); _maxLength = DefinitionResolver.Get(Controller, Binding, file["MaxLength"], int.MaxValue); _inputType = DefinitionResolver.Get(Controller, Binding, file["InputType"], TextInputType.NormalText); _lostFocusCancels = DefinitionResolver.Get(Controller, Binding, file["CancelOnLostFocus"], false); _focusedShared = DefinitionResolver.GetShared(Controller, Binding, file["IsFocused"], false); _focusedShared.Value = false; string filter = DefinitionResolver.GetString(Controller, Binding, file["Filter"]); if (!filter.IsNullOrEmpty()) { _filter = new List <char>(filter.ToCharArray()); } _focusedShared.ValueChanged += (bool focused) => { if (focused) { CurrentlyFocused = this; } else if (CurrentlyFocused == this) { CurrentlyFocused = null; } }; if (_inputType == TextInputType.Password) { _password = new SharedString(); } RegisterDelegate("TextApply", file["TextApply"]); RegisterDelegate("TextChanged", file["TextChanged"]); RegisterDelegate("TextCancel", file["TextCancel"]); RegisterDelegate("LostFocus", file["LostFocus"]); RegisterDelegate("Return", file["Return"]); return(true); }
protected override bool Init(object controller, object binding, DefinitionFile definition) { if (!base.Init(controller, binding, definition)) { return(false); } DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiButton)); Icon = DefinitionResolver.GetShared <Texture2D>(Controller, Binding, file["Icon"], null); if (Icon == null) { Icon = new SharedValue <Texture2D>(); } _gestureMargin = DefinitionResolver.Get <Margin>(Controller, Binding, file["GestureMargin"], Margin.None); _text = DefinitionResolver.GetSharedString(Controller, Binding, file["Text"]); if (_text == null) { _text = new SharedString(); } if (file["Hold"] != null) { RegisterDelegate("Hold", file["Hold"]); _processHold = true; } RegisterDelegate("Release", file["Release"]); RegisterDelegate("Push", file["Push"]); RegisterDelegate("Click", file["Click"]); List <DefinitionFile> drawableFiles = file["Drawables"] as List <DefinitionFile>; if (file["Disabled"] != null && file["Enabled"] == null) { _enabledFlag = DefinitionResolver.GetShared <bool>(Controller, Binding, file["Disabled"], false); _enabledFlagInvert = true; } else { _enabledFlag = DefinitionResolver.GetShared <bool>(Controller, Binding, file["Enabled"], true); _enabledFlagInvert = false; } if (drawableFiles != null) { foreach (var def in drawableFiles) { ButtonDrawable drawable = def.CreateInstance(Controller, Binding) as ButtonDrawable; if (drawable != null) { _drawables.Add(drawable); } } } _pushSound = DefinitionResolver.Get <SoundEffect>(Controller, Binding, file["PushSound"], null); _releaseSound = DefinitionResolver.Get <SoundEffect>(Controller, Binding, file["ReleaseSound"], null); _actionSound = DefinitionResolver.Get <SoundEffect>(Controller, Binding, file["ActionSound"], null); ButtonMode = DefinitionResolver.Get <UiButtonMode>(Controller, Binding, file["Mode"], UiButtonMode.Release); _repeatStart = (float)DefinitionResolver.Get <int>(Controller, Binding, file["RepeatStart"], 0) / 1000f; _repeatInterval = (float)DefinitionResolver.Get <int>(Controller, Binding, file["RepeatInterval"], 0) / 1000f; return(true); }
protected virtual bool Init(object controller, object binding, DefinitionFile definition) { DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiView)); Type controllerType = file["Controller"] as Type; _controller = controller as UiController; if (controllerType != null) { var newController = Activator.CreateInstance(controllerType) as UiController; if (newController != null) { newController.Parent = _controller; Controller = newController; } } Binding = binding; object bindParameter = file["Binding"]; if (bindParameter != null) { Object bind = DefinitionResolver.GetValueFromMethodOrField(Controller, binding, bindParameter); if (bind != null) { Binding = bind; } } Id = DefinitionResolver.GetString(Controller, Binding, file["Id"]); if (file["Hidden"] != null && file["Visible"] == null) { _visiblityFlag = DefinitionResolver.GetShared <bool>(Controller, Binding, file["Hidden"], false); _visibleIsHidden = true; } else { _visiblityFlag = DefinitionResolver.GetShared <bool>(Controller, Binding, file["Visible"], true); } Tag = DefinitionResolver.GetSharedString(Controller, Binding, file["Tag"]); Opacity = DefinitionResolver.GetShared <double>(Controller, Binding, file["Opacity"], 1); DisplayVisibility = Visible ? 1 : 0; _modal = DefinitionResolver.Get <bool>(Controller, Binding, file["Modal"], false); RegisterDelegate("ViewRemoved", file["ViewRemoved"]); RegisterDelegate("ViewAdded", file["ViewAdded"]); RegisterDelegate("ViewActivated", file["ViewActivated"]); RegisterDelegate("ViewDeactivated", file["ViewDeactivated"]); RegisterDelegate("ViewResized", file["ViewResized"]); _minWidth = DefinitionResolver.Get <Length>(Controller, Binding, file["MinWidth"], Length.Zero); _minHeight = DefinitionResolver.Get <Length>(Controller, Binding, file["MinHeight"], Length.Zero); _showSpeed = (float)Math.Max( DefinitionResolver.Get <double>(Controller, Binding, file["ShowHideTime"], -1), DefinitionResolver.Get <double>(Controller, Binding, file["ShowTime"], -1)); if (_showSpeed < 0) { _showSpeed = DefaultShowTime; } _showSpeed /= 1000.0f; _showSpeed = _showSpeed > 0 ? 1 / _showSpeed : float.MaxValue; _hideSpeed = (float)Math.Max( DefinitionResolver.Get <double>(Controller, Binding, file["ShowHideTime"], -1), DefinitionResolver.Get <double>(Controller, Binding, file["HideTime"], -1)); if (_hideSpeed < 0) { _hideSpeed = DefaultHideTime; } _hideSpeed /= 1000.0f; _hideSpeed = _hideSpeed > 0 ? 1 / _hideSpeed : float.MaxValue; CreatePositionParameters(Controller, Binding, definition); DefinitionFile backgroundDrawable = file["BackgroundDrawable"] as DefinitionFile; Color defaultBackgroundColor = Color.Transparent; if (backgroundDrawable != null) { BackgroundDrawable = backgroundDrawable.CreateInstance(Controller, Binding) as IBackgroundDrawable; if (BackgroundDrawable != null) { defaultBackgroundColor = Color.White; } } _backgroundColor = DefinitionResolver.GetColorWrapper(Controller, Binding, file["BackgroundColor"]) ?? new ColorWrapper(defaultBackgroundColor); DefinitionFile showTransitionEffectFile = file["ShowTransitionEffect"] as DefinitionFile; DefinitionFile hideTransitionEffectFile = file["HideTransitionEffect"] as DefinitionFile; DefinitionFile parentShowTransitionEffectFile = file["ParentShowTransitionEffect"] as DefinitionFile; DefinitionFile parentHideTransitionEffectFile = file["ParentHideTransitionEffect"] as DefinitionFile; if (showTransitionEffectFile != null) { _showTransitionEffect = showTransitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect; } if (hideTransitionEffectFile != null) { _hideTransitionEffect = hideTransitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect; } if (parentShowTransitionEffectFile != null) { _parentShowTransitionEffect = parentShowTransitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect; } if (parentHideTransitionEffectFile != null) { _parentHideTransitionEffect = parentHideTransitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect; } return(true); }