refactor(app): compose interaction and retained UI startup
This commit is contained in:
parent
f663b04a54
commit
aa6ffa5176
15 changed files with 2157 additions and 467 deletions
|
|
@ -24,10 +24,40 @@ internal sealed class DevToolsInputCaptureSource
|
|||
|
||||
internal sealed class RetainedUiInputCaptureSlot
|
||||
{
|
||||
public UiRoot? Root { get; set; }
|
||||
public UiRoot? Root { get; private set; }
|
||||
|
||||
public IDisposable Bind(UiRoot root)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(root);
|
||||
if (Root is not null)
|
||||
throw new InvalidOperationException("Retained UI input capture is already bound.");
|
||||
Root = root;
|
||||
return new Binding(this, root);
|
||||
}
|
||||
|
||||
public bool WantCaptureMouse => Root?.WantsMouse ?? false;
|
||||
public bool WantCaptureKeyboard => Root?.WantsKeyboard ?? false;
|
||||
|
||||
private void Unbind(UiRoot expected)
|
||||
{
|
||||
if (ReferenceEquals(Root, expected))
|
||||
Root = null;
|
||||
}
|
||||
|
||||
private sealed class Binding : IDisposable
|
||||
{
|
||||
private RetainedUiInputCaptureSlot? _owner;
|
||||
private readonly UiRoot _expected;
|
||||
|
||||
public Binding(RetainedUiInputCaptureSlot owner, UiRoot expected)
|
||||
{
|
||||
_owner = owner;
|
||||
_expected = expected;
|
||||
}
|
||||
|
||||
public void Dispose() =>
|
||||
Interlocked.Exchange(ref _owner, null)?.Unbind(_expected);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class CompositeInputCaptureSource : IInputCaptureSource
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue