public void TestBasicInvalidations() { var services = new ServiceRegistry(); services.AddService(typeof(IGame), new Game()); var edit = new EditText(services); // - test the properties that are supposed to invalidate the object measurement UIElementLayeringTests.TestMeasureInvalidation(edit, () => edit.Font = null); UIElementLayeringTests.TestMeasureInvalidation(edit, () => edit.MaxLines = 34); UIElementLayeringTests.TestMeasureInvalidation(edit, () => edit.MinLines = 34); UIElementLayeringTests.TestMeasureInvalidation(edit, () => edit.SelectedText = "toto"); UIElementLayeringTests.TestMeasureInvalidation(edit, () => edit.Text = "titi"); UIElementLayeringTests.TestMeasureInvalidation(edit, () => edit.MaxLength = 3); // text is modified // - test the properties that are not supposed to invalidate the object layout state UIElementLayeringTests.TestNoInvalidation(edit, () => edit.IsReadOnly = !edit.IsReadOnly); UIElementLayeringTests.TestNoInvalidation(edit, () => edit.ActiveImage = new Sprite()); UIElementLayeringTests.TestNoInvalidation(edit, () => edit.InactiveImage = new Sprite()); UIElementLayeringTests.TestNoInvalidation(edit, () => edit.TextColor = new Color(1, 2, 3, 4)); UIElementLayeringTests.TestNoInvalidation(edit, () => edit.SelectionColor = new Color(1, 2, 3, 4)); UIElementLayeringTests.TestNoInvalidation(edit, () => edit.CaretColor = new Color(1, 7, 3, 4)); UIElementLayeringTests.TestNoInvalidation(edit, () => edit.CaretPosition = 34); UIElementLayeringTests.TestNoInvalidation(edit, () => edit.SelectionLength = 2); UIElementLayeringTests.TestNoInvalidation(edit, () => edit.SelectionStart = 0); UIElementLayeringTests.TestNoInvalidation(edit, () => edit.MaxLength = 34); // text is not modified }
protected override async Task LoadContent() { await base.LoadContent(); var background = new Entity { new BackgroundComponent { Texture = Asset.Load<Texture>("ParadoxBackground") } }; Scene.AddChild(background); button1 = new Button { Content = new TextBlock { Text = "text block button 1", Font = Asset.Load<SpriteFont>("CourierNew12"), SynchronousCharacterGeneration = true } }; button1.SetCanvasRelativePosition(new Vector3(0.025f, 0.05f, 0f)); edit1 = new EditText(Services) { Text = "Edit text 1", Font = Asset.Load<SpriteFont>("CourierNew12"), SynchronousCharacterGeneration = true, }; edit1.SetCanvasRelativePosition(new Vector3(0.025f, 0.15f, 0f)); button2 = new Button { Content = new TextBlock { Text = "text block button 2", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), SynchronousCharacterGeneration = true } }; edit2 = new EditText(Services) { Text = "Edit text 2", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), }; stackPanel = new StackPanel { Children = { button2, edit2 }, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Orientation = Orientation.Horizontal }; stackPanel.SetCanvasRelativePosition(new Vector3(0.5f, 0.5f, 0f)); stackPanel.SetCanvasPinOrigin(new Vector3(.5f)); canvas = new Canvas { Children = {button1, edit1, stackPanel}, CanBeHitByUser = true }; button1.MouseOverStateChanged += (sender, args) => { triggeredButton1 = true; oldValueButton1 = args.OldValue; newValueButton1 = args.NewValue;}; button2.MouseOverStateChanged += (sender, args) => { triggeredButton2 = true;}; edit1.MouseOverStateChanged += (sender, args) => { triggeredEdit1 = true;}; edit2.MouseOverStateChanged += (sender, args) => { triggeredEdit2 = true;}; canvas.MouseOverStateChanged += (sender, args) => { triggeredCanvas = true;}; stackPanel.MouseOverStateChanged += (sender, args) => { triggeredStackPanel = true;}; UIComponent.RootElement = canvas; }
private void DeactivateEditTextImpl() { attachedTextField.EditingChanged -= TextFieldOnValueChanged; attachedTextField.ShouldChangeCharacters -= ShouldChangeCharacters; attachedTextField.SecureTextEntry = false; attachedTextField.ResignFirstResponder(); attachedTextField = null; currentActiveEditText = null; }
private void ActivateEditTextImpl() { currentActiveEditText = this; attachedTextField = textField; UpdateInputTypeImpl(); attachedTextField.Text = text; attachedTextField.EditingChanged += TextFieldOnValueChanged; attachedTextField.ShouldChangeCharacters += ShouldChangeCharacters; attachedTextField.BecomeFirstResponder(); }
protected override async Task LoadContent() { await base.LoadContent(); var middleOfScreen = new Vector3(UIComponent.VirtualResolution.X, UIComponent.VirtualResolution.Y, 0) / 2; edit1 = new EditText(Services) { Name = "TestEdit1", Font = Asset.Load<SpriteFont>("MSMincho10"), MinimumWidth = 100, Text = "Sample Text1", MaxLength = 35, TextSize = 20, SynchronousCharacterGeneration = true }; edit1.DependencyProperties.Set(Canvas.PinOriginPropertyKey, 0.5f * Vector3.One); edit1.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(middleOfScreen.X, 100, 0)); edit1.TextChanged += Edit1OnTextChanged; edit2 = new EditText(Services) { Name = "TestEdit2", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), MinimumWidth = 100, Text = "Sample2 Text2", MaxLength = 10, CharacterFilterPredicate = IsLetter, SynchronousCharacterGeneration = true }; edit2.DependencyProperties.Set(Canvas.PinOriginPropertyKey, 0.5f * Vector3.One); edit2.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(middleOfScreen.X, 200, 0)); edit2.TextChanged += Edit2OnTextChanged; edit3 = new EditText(Services) { Name = "TestEdit3", Font = Asset.Load<SpriteFont>("MSMincho10"), MinimumWidth = 100, Text = "secret", MaxLength = 15, TextSize = 24, InputType = EditText.InputTypeFlags.Password, SynchronousCharacterGeneration = true }; edit3.DependencyProperties.Set(Canvas.PinOriginPropertyKey, 0.5f * Vector3.One); edit3.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(middleOfScreen.X, 300, 0)); edit4 = new EditText(Services) { Name = "TestEdit4", Font = Asset.Load<SpriteFont>("MicrosoftSansSerif15"), MinimumWidth = 200, Text = "aligned text", TextSize = 24, SynchronousCharacterGeneration = true }; edit4.DependencyProperties.Set(Canvas.PinOriginPropertyKey, 0.5f * Vector3.One); edit4.DependencyProperties.Set(Canvas.AbsolutePositionPropertyKey, new Vector3(middleOfScreen.X, 400, 0)); var canvas = new Canvas(); canvas.Children.Add(edit1); canvas.Children.Add(edit2); canvas.Children.Add(edit3); canvas.Children.Add(edit4); UIComponent.RootElement = canvas; }
private void CreateWelcomePopup() { // Create welcome text var welcomeText = new TextBlock { Font = westernFont, TextSize = 42, TextColor = Color.White, Text = "Welcome to paradox UI sample.\n" + "Please name your character", TextAlignment = TextAlignment.Center, WrapText = true, Margin = new Thickness(20, 0, 20, 0), HorizontalAlignment = HorizontalAlignment.Center }; // Create Edit text var nameEditText = new EditText(Services) { Font = westernFont, TextSize = 32, TextColor = Color.White, Text = DefaultName, MaxLength = 15, TextAlignment = TextAlignment.Center, ActiveImage = mainScreneImages["tex_edit_activated_background"], InactiveImage = mainScreneImages["tex_edit_inactivated_background"], MouseOverImage = mainScreneImages["tex_edit_inactivated_background"], HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, MinimumWidth = 340, Padding = new Thickness(30, 30, 30, 40), // Pad text (Content inside), Margin = new Thickness(0, 80, 0, 80), // Space around the edit }; nameEditText.SetGridRow(1); // Create cancel and validate button var cancelButton = CreateTextButton("Cancel"); cancelButton.SetGridColumn(1); cancelButton.Click += delegate { nameTextBlock.Text = DefaultName; welcomePopup.Visibility = Visibility.Collapsed; }; var validateButton = CreateTextButton("Validate"); validateButton.SetGridColumn(3); validateButton.Click += delegate { nameTextBlock.Text = nameEditText.Text.Trim(); welcomePopup.Visibility = Visibility.Collapsed; }; // Put cancel and validate buttons in stack panel (Left-right orientation placement) var buttonPanel = new Grid(); buttonPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Star)); buttonPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Auto)); buttonPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Star)); buttonPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Auto)); buttonPanel.ColumnDefinitions.Add(new StripDefinition(StripType.Star)); buttonPanel.RowDefinitions.Add(new StripDefinition()); buttonPanel.LayerDefinitions.Add(new StripDefinition()); buttonPanel.Children.Add(cancelButton); buttonPanel.Children.Add(validateButton); buttonPanel.SetGridRow(2); // Create a stack panel to store items (Top-down orientation placement) var popupContentPanel = new Grid { MaximumWidth = 580, MaximumHeight = 900, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, }; popupContentPanel.ColumnDefinitions.Add(new StripDefinition()); popupContentPanel.RowDefinitions.Add(new StripDefinition(StripType.Auto)); popupContentPanel.RowDefinitions.Add(new StripDefinition(StripType.Star)); popupContentPanel.RowDefinitions.Add(new StripDefinition(StripType.Auto)); popupContentPanel.LayerDefinitions.Add(new StripDefinition()); popupContentPanel.Children.Add(welcomeText); popupContentPanel.Children.Add(nameEditText); popupContentPanel.Children.Add(buttonPanel); var welcomePopupContent = new ContentDecorator { BackgroundImage = popupWindowImage, Content = popupContentPanel, Padding = new Thickness(85, 130, 85, 110) }; welcomePopup = new ModalElement { Visibility = Visibility.Collapsed, Content = welcomePopupContent, }; welcomePopup.SetPanelZIndex(1); }
private void DeactivateEditTextImpl() { if (activeEditText == null) throw new Exception("Internal error: Can not deactivate the EditText, it is already nullified"); // remove callbacks editText.EditorAction -= AndroidEditTextOnEditorAction; editText.AfterTextChanged -= AndroidEditTextOnAfterTextChanged; editText.ClearFocus(); editText = null; activeEditText = null; // remove the edit text from the layout and hide the layout game.Context.EditTextLayout.Visibility = ViewStates.Gone; // deactivate the ime (hide the keyboard) if (staticEditText != null) // staticEditText can be null if window have already been detached. inputMethodManager.HideSoftInputFromWindow(staticEditText.WindowToken, HideSoftInputFlags.None); inputMethodManager = null; FocusedElement = null; }
private void ActivateEditTextImpl() { if(activeEditText != null) throw new Exception("Internal error: Can not activate edit text, another edit text is already active"); EnsureStaticEditText(); activeEditText = this; editText = staticEditText; // set up the initial state of the android EditText UpdateInputTypeImpl(); editText.SetMaxLines(MaxLines); editText.SetMinLines(MinLines); UpdateTextToEditImpl(); UpdateSelectionToEditImpl(); // add callbacks editText.EditorAction += AndroidEditTextOnEditorAction; editText.AfterTextChanged += AndroidEditTextOnAfterTextChanged; // add the edit to the overlay layout and show the layout game.Context.EditTextLayout.Visibility = ViewStates.Visible; // set the focus to the edit box editText.RequestFocus(); // activate the ime (show the keyboard) inputMethodManager = (InputMethodManager)PlatformAndroid.Context.GetSystemService(Context.InputMethodService); inputMethodManager.ShowSoftInput(staticEditText, ShowFlags.Forced); }