Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion sources/engine/Stride.UI.Tests/Layering/EditTextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public void TestBasicInvalidations()
services.AddService<IGame>(new Game());

var edit = new EditText();
edit.UIElementServices = new UIElementServices { Services = services };

// - test the properties that are supposed to invalidate the object measurement
UIElementLayeringTests.TestMeasureInvalidation(edit, () => edit.Font = new DummyFont());
Expand Down
2 changes: 0 additions & 2 deletions sources/engine/Stride.UI.Tests/Regression/EditTextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ protected override async Task LoadContent()
canvas.Children.Add(edit3);
canvas.Children.Add(edit4);

canvas.UIElementServices = new UIElementServices { Services = this.Services };

UIComponent.Page = new Engine.UIPage { RootElement = canvas };
}

Expand Down
2 changes: 0 additions & 2 deletions sources/engine/Stride.UI.Tests/Regression/MouseOverTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ protected override async Task LoadContent()
canvas.MouseOverStateChanged += (sender, args) => { triggeredCanvas = true;};
stackPanel.MouseOverStateChanged += (sender, args) => { triggeredStackPanel = true;};

canvas.UIElementServices = new UIElementServices { Services = this.Services };

UIComponent.Page = new Engine.UIPage { RootElement = canvas };
}

Expand Down
8 changes: 4 additions & 4 deletions sources/engine/Stride.UI/Controls/EditText.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
using Android.Text.Method;
using Stride.Core;
using Stride.Games;
using Stride.Input;
using Exception = System.Exception;
using KeyEvent = Android.Views.KeyEvent;

namespace Stride.UI.Controls
{
Expand Down Expand Up @@ -228,7 +230,7 @@ private void OnMinLinesChangedImpl()
editText.Post(editTextSetMinLinesAction);
}

private void ActivateEditTextImpl()
private void ActivateEditTextImpl(InputManager inputManager)
{
lock (syncRoot)
{
Expand All @@ -250,7 +252,7 @@ private void ActivateEditTextImpl()
}
}

private void DeactivateEditTextImpl()
private void DeactivateEditTextImpl(InputManager inputManager)
{
lock (syncRoot)
{
Expand All @@ -265,8 +267,6 @@ private void DeactivateEditTextImpl()
activeEditText = null;

GetGameContext().HideEditTextPopup();

FocusedElement = null;
}
}

Expand Down
14 changes: 5 additions & 9 deletions sources/engine/Stride.UI/Controls/EditText.Direct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,14 @@ internal override void OnTextInput(TextEventArgs args)
}
}

private void ActivateEditTextImpl()
private void ActivateEditTextImpl(InputManager inputManager)
{
var input = UIElementServices.Services.GetSafeServiceAs<InputManager>();
input.TextInput?.EnabledTextInput();
inputManager.TextInput?.EnabledTextInput();
}
private void DeactivateEditTextImpl()
{
var input = UIElementServices.Services.GetSafeServiceAs<InputManager>();
input.TextInput?.DisableTextInput();
Composition = "";

FocusedElement = null;
private void DeactivateEditTextImpl(InputManager inputManager)
{
inputManager.TextInput?.DisableTextInput();
}

private void InterpretKey(Keys key, InputManager input)
Expand Down
6 changes: 3 additions & 3 deletions sources/engine/Stride.UI/Controls/EditText.UWP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Stride.Core;
using Stride.Core.Annotations;
using Stride.Games;
using Stride.Input;

namespace Stride.UI.Controls
{
Expand Down Expand Up @@ -42,7 +43,7 @@ private void OnMinLinesChangedImpl()
{
}

private void ActivateEditTextImpl()
private void ActivateEditTextImpl(InputManager inputManager)
{
// try to show the virtual keyboard if no hardward keyboard available
Windows.UI.ViewManagement.InputPane.GetForCurrentView().TryShow();
Expand Down Expand Up @@ -103,7 +104,7 @@ private void EditText_TextChanged(object sender, Windows.UI.Xaml.Controls.TextCh
UpdateSelectionFromEditImpl();
}

private void DeactivateEditTextImpl()
private void DeactivateEditTextImpl(InputManager inputManager)
{
if (editText != null)
{
Expand All @@ -119,7 +120,6 @@ private void DeactivateEditTextImpl()
editText = null;
activeEditText = null;
}
FocusedElement = null;
}

private void UpdateTextToEditImpl()
Expand Down
20 changes: 13 additions & 7 deletions sources/engine/Stride.UI/Controls/EditText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Stride.Engine;
using Stride.Games;
using Stride.Graphics;
using Stride.Input;
using Stride.UI.Events;

namespace Stride.UI.Controls
Expand Down Expand Up @@ -148,20 +149,25 @@ public bool IsSelectionActive
if (IsReadOnly && value) // prevent selection when the Edit is read only
return;

isSelectionActive = value;
var uiSystem = UIElementServices.Services?.GetService<UISystem>();
var inputManager = UIElementServices.Services?.GetService<InputManager>();
if (inputManager is null || uiSystem is null)
return;

if (IsSelectionActive)
isSelectionActive = value;
if (isSelectionActive)
{
var previousEditText = FocusedElement as EditText;
if (previousEditText != null)
if (uiSystem.FocusedElement is EditText previousEditText)
previousEditText.IsSelectionActive = false;

FocusedElement = this;
ActivateEditTextImpl();
uiSystem.FocusedElement = this;
ActivateEditTextImpl(inputManager);
}
else
{
DeactivateEditTextImpl();
uiSystem.FocusedElement = null;
DeactivateEditTextImpl(inputManager);
Composition = "";
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions sources/engine/Stride.UI/Controls/EditText.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Stride.Core;
using Stride.Core.Annotations;
using Stride.Games;
using Stride.Input;
using Stride.UI.Events;

namespace Stride.UI.Controls
Expand Down Expand Up @@ -127,7 +128,6 @@ private static void TextFieldOnEditingDidEnd(object sender, EventArgs eventArgs)
currentActiveEditText.IsSelectionActive = false;
barView.Hidden = true;
overlayView.Hidden = true;
FocusedElement = null;

if (currentActiveEditText != null)
{
Expand Down Expand Up @@ -171,7 +171,7 @@ private void OnMinLinesChangedImpl()
{
}

private void ActivateEditTextImpl()
private void ActivateEditTextImpl(InputManager inputManager)
{
EnsureGameContext();

Expand Down Expand Up @@ -199,7 +199,7 @@ private bool ShouldChangeCharacters(UITextField theTextField, NSRange range, str
return replacementSize < 0 || theTextField.Text.Length + replacementSize <= MaxLength;
}

private void DeactivateEditTextImpl()
private void DeactivateEditTextImpl(InputManager inputManager)
{
attachedTextField.EditingChanged -= TextFieldOnValueChanged;
attachedTextField.ShouldChangeCharacters -= ShouldChangeCharacters;
Expand Down
22 changes: 21 additions & 1 deletion sources/engine/Stride.UI/Engine/UIComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Stride.Engine
[DataContract("UIComponent")]
[Display("UI", Expand = ExpandRule.Once)]
[DefaultEntityComponentRenderer(typeof(UIRenderProcessor))]
[DefaultEntityComponentProcessor(typeof(UIProcessor))]
[ComponentOrder(9800)]
[ComponentCategory("UI")]
public sealed class UIComponent : ActivableEntityComponent
Expand All @@ -36,7 +37,15 @@ public UIComponent()
/// <userdoc>The UI page.</userdoc>
[DataMember(10)]
[Display("Page")]
public UIPage Page { get; set; }
public UIPage Page
{
get;
set
{
field = value;
field?.Services = Services;
}
}

/// <summary>
/// Specifies the sampling method to be used for this component
Expand Down Expand Up @@ -125,5 +134,16 @@ public UIComponent()
/// </summary>
[DataMemberIgnore]
public const float FixedSizeVerticalUnit = 1; // 100% of the vertical resolution

[DataMemberIgnore]
internal IServiceRegistry Services
{
get;
set
{
field = value;
Page?.Services = Services;
}
}
}
}
21 changes: 20 additions & 1 deletion sources/engine/Stride.UI/Engine/UIPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@ public sealed class UIPage : ComponentBase
/// </summary>
/// <userdoc>The root element of the page.</userdoc>
[DataMember]
public UIElement RootElement { get; set; }
public UIElement RootElement
{
get;
set
{
field = value;
field?.UIElementServices = new UIElementServices { Services = Services };
}
}

[DataMemberIgnore]
internal IServiceRegistry Services
{
get;
set
{
field = value;
RootElement?.UIElementServices = new UIElementServices { Services = Services };
}
}
}
}
19 changes: 19 additions & 0 deletions sources/engine/Stride.UI/Rendering/UI/UIProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.

using Stride.Engine;

namespace Stride.Rendering.UI
{
public class UIProcessor : EntityProcessor<UIComponent>
{
protected override void OnEntityComponentAdding(Entity entity, UIComponent uiComponent, UIComponent _)
{
uiComponent.Services = Services;
}

protected override void OnEntityComponentRemoved(Entity entity, UIComponent uiComponent, UIComponent _)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private UIElement UpdateMouseOver(ref Viewport viewport, ref Matrix worldViewPro
}
}

UIElementUnderMouseCursor = mouseOverElement;
uiSystem.UIElementUnderMouseCursor = mouseOverElement;

// update cached values
state.LastMouseOverElement = mouseOverElement;
Expand Down
10 changes: 4 additions & 6 deletions sources/engine/Stride.UI/Rendering/UI/UIRenderFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public partial class UIRenderFeature : RootRenderFeature
public override Type SupportedRenderObjectType => typeof(RenderUIElement);

/// <summary>
/// Represents the UI-element thats currently under the mouse cursor.
/// Represents the UI-element currently under the mouse cursor.
/// Only elements with CanBeHitByUser == true are taken into account.
/// Last processed element_state / ?UIComponent? with a valid element will be used.
/// </summary>
public UIElement UIElementUnderMouseCursor { get; private set; }
public UIElement UIElementUnderMouseCursor => uiSystem.UIElementUnderMouseCursor;

public UIRenderFeature()
{
Expand Down Expand Up @@ -172,7 +172,8 @@ private void DrawInternal(RenderDrawContext context, RenderView renderView, Rend
elementUnderMouseCursor = loopedElementUnderMouseCursor;
}
}
UIElementUnderMouseCursor = elementUnderMouseCursor;

uiSystem.UIElementUnderMouseCursor = elementUnderMouseCursor;

// render the UI elements of all the entities
foreach (var uiElementState in uiElementStates)
Expand Down Expand Up @@ -208,9 +209,6 @@ private void DrawInternal(RenderDrawContext context, RenderView renderView, Rend
var projectedVirtualWidth = viewportSize * (transformedVirtualWidth.XY() / transformedVirtualWidth.W - projectedOrigin);
var projectedVirtualHeight = viewportSize * (transformedVirtualHeight.XY() / transformedVirtualHeight.W - projectedOrigin);

// Set default services
rootElement.UIElementServices = new UIElementServices { Services = RenderSystem.Services };

// set default resource dictionary

// update layouting context.
Expand Down
5 changes: 0 additions & 5 deletions sources/engine/Stride.UI/UIElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ protected UIElement()
VisualChildrenCollection = new UIElementCollection();
}

/// <summary>
/// The <see cref="UIElement"/> that currently has the focus.
/// </summary>
internal static UIElement FocusedElement { get; set; }

/// <summary>
/// A unique ID defining the UI element.
/// </summary>
Expand Down
Loading
Loading