override public void SetFocus() { Button b = null; //Debug.Log("DefaultButtonId: " + DefaultButtonId); if (null != DefaultButtonId) { if (DefaultButtonId is AlertButtonFlag) { switch ((AlertButtonFlag)DefaultButtonId) { case AlertButtonFlag.Ok: b = DictId2Button["ok"]; if (null != b) { b.SetFocus(); } break; case AlertButtonFlag.Yes: b = DictId2Button["yes"]; if (null != b) { b.SetFocus(); } break; case AlertButtonFlag.Cancel: b = DictId2Button["cancel"]; if (null != b) { b.SetFocus(); } break; case AlertButtonFlag.No: b = DictId2Button["no"]; if (null != b) { b.SetFocus(); } break; } } else { if (DictId2Button.ContainsKey((string)DefaultButtonId)) { b = DictId2Button[(string)DefaultButtonId]; } } } // nothing in focus? // try with OK if (null == b && null != DefaultButtonId && DictId2Button.ContainsKey((string)DefaultButtonId)) { if (DictId2Button.ContainsKey((string)DefaultButtonId)) { b = DictId2Button[(string)DefaultButtonId]; } } // still nothing? // try with the last button defined if (null == b) { IEnumerator <Button> enumerator = DictId2Button.Values.GetEnumerator(); while (enumerator.MoveNext()) { b = enumerator.Current; } } //Debug.Log("Setting focus to: " + b); // set focus if (null != b) { b.SetFocus(); } }
/*protected override void CreateChildren() * { * base.CreateChildren(); * * // hbox for icon and label * _contentBox = new HGroup * { * MinHeight = 60, * VerticalAlign = VerticalAlign.Middle * }; * AddContentChild(_contentBox); // adding hbox as CONTENT child * * // label * _lblText = new Label * { * Id = "message", * Text = string.Empty, * //Multiline = true, * //WordWrap = true, * MaxWidth = MaxLabelWidth, * MaxHeight = MaxLabelHeight, * Color = Color.black, * }; * _lblText.SetStyle("labelStyle", GetStyle("labelStyle")); * _lblText.SetStyle("font", GetStyle("labelFont")); * _contentBox.AddChild(_lblText); * }*/ #endregion #region Lifecycle methods protected override void CommitProperties() { base.CommitProperties(); if (_optionsChanged) { _optionsChanged = false; var len = _options.Length; for (var i = 0; i < len; i++) { var option = _options[i]; switch (option.Type) { case AlertOptionType.Message: Message = (string)option.Value; break; case AlertOptionType.Title: Title = (string)option.Value; break; case AlertOptionType.Icon: Icon = (Texture)option.Value; break; case AlertOptionType.HeaderIcon: HeaderIconDisplay.Texture = (Texture)option.Value; // 20131206 IconDisplay break; case AlertOptionType.Flags: ProcessFlags((AlertButtonFlag)option.Value); break; case AlertOptionType.Button: AddButton((AlertButtonDescriptor)option.Value); break; case AlertOptionType.DefaultButton: //Debug.Log("Applying: " + option.Value); DefaultButtonId = option.Value; break; case AlertOptionType.SkinClass: SetStyle("skinClass", option.Value); break; case AlertOptionType.AddedEffect: SetStyle("addedEffect", option.Value); break; case AlertOptionType.RemovedEffect: SetStyle("removedEffect", option.Value); break; } } } /*if (_iconChanged) * { * if (null != _icon) * { * if (null == _imgIcon) * { * _imgIcon = new Image {Texture = _icon/*, AlphaBlend = false#1#}; * _contentBox.AddChildAt(_imgIcon, 0); * //_contentBox.ValidateNow(); * } * } * else if (null != _imgIcon) * { * _contentBox.RemoveChild(_imgIcon); * //_contentBox.ValidateNow(); * } * _iconChanged = false; * }*/ /*if (_messageChanged) * { * _messageChanged = false; * MessageDisplay.Text = _message; * }*/ if (_flagsChanged) { _flagsChanged = false; ProcessFlags(_flags); } if (_descriptorsChanged) { _descriptorsChanged = false; string buttonStyleMapper = (string)GetStyle("buttonStyleMapper"); _descriptors.ForEach( delegate(AlertButtonDescriptor descriptor) { Button btn = new Button { Text = descriptor.Text }; var skinClass = EvaluateSkinClassFromStyle("buttonSkin"); if (null != skinClass) { btn.SkinClass = skinClass; } if (null != descriptor.Icon) { btn.Icon = descriptor.Icon; } if (!string.IsNullOrEmpty(buttonStyleMapper)) { btn.StyleName = buttonStyleMapper; } if (!btn.HasStyle("buttonStyle")) { btn.SetStyle("buttonStyle", GetStyle("buttonStyle")); } if (!btn.HasStyle("buttonCursor")) { btn.SetStyle("cursor", GetStyle("buttonCursor")); } //btn.SetStyle("cursor", "pointer"); ControlBarGroup.AddChild(btn); if (descriptor.Focused) { //btn.SetFocus(); DefaultButtonId = descriptor.Id; } DictId2Button.Add(descriptor.Id, btn); DictButton2Id.Add(btn, descriptor.Id); } ); //ControlBarGroup.ValidateNow(); } }