-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompositionWrapper.cs
More file actions
80 lines (57 loc) · 2.32 KB
/
CompositionWrapper.cs
File metadata and controls
80 lines (57 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Developed by Bulat Bagaviev (@sunnyyssh).
// This file is licensed to you under the MIT license.
using System.Collections.Immutable;
namespace Sunnyyssh.ConsoleUI;
public abstract class CompositionWrapper : Wrapper
{
private readonly IReadOnlyList<ChildInfo> _compositionChildren;
protected override DrawState CreateDrawState()
{
return GetChildrenCombinedState();
}
private DrawState GetChildrenCombinedState()
{
var childrenStates = _compositionChildren
.Select(RequestChildState)
.ToArray();
return DrawState.Combine(childrenStates);
}
private DrawState RequestChildState(ChildInfo child)
{
child.Child.RequestDrawState(new DrawOptions());
var result = child.TransformState();
// It's neccessary to invoke it on drawing.
child.Child.OnDraw();
return result;
}
private void RedrawChild(UIElement child, RedrawElementEventArgs args)
{
ArgumentNullException.ThrowIfNull(child, nameof(child));
ArgumentNullException.ThrowIfNull(args, nameof(args));
var childInfo = Children.SingleOrDefault(ch => ch.Child == child);
if (childInfo is null)
return;
var resultState = childInfo.TransformState();
Redraw(resultState);
}
// ReSharper disable once UnusedMember.Local
private void EraseChild(ChildInfo childInfo)
{
ArgumentNullException.ThrowIfNull(childInfo, nameof(childInfo));
var erasingState = childInfo.CreateErasingState()
.Shift(childInfo.Left, childInfo.Top);
Redraw(erasingState);
childInfo.Child.OnRemove();
}
protected CompositionWrapper(int width, int height, ImmutableList<ChildInfo> orderedChildren,
ImmutableList<ChildInfo> compositionChildren, FocusFlowSpecification focusFlowSpecification, OverlappingPriority overlappingPriority)
: base(width, height, orderedChildren, focusFlowSpecification, overlappingPriority)
{
ArgumentNullException.ThrowIfNull(compositionChildren, nameof(compositionChildren));
_compositionChildren = compositionChildren;
foreach (var child in _compositionChildren)
{
child.Child.RedrawElement += RedrawChild;
}
}
}