forked from microsoft/microsoft-ui-xaml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLayoutContextAdapter.cpp
110 lines (91 loc) · 2.65 KB
/
LayoutContextAdapter.cpp
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
#include <pch.h>
#include <common.h>
#include "ItemsRepeater.common.h"
#include "VirtualizingLayoutContext.h"
#include "LayoutContextAdapter.h"
LayoutContextAdapter::LayoutContextAdapter(winrt::NonVirtualizingLayoutContext const& nonVirtualizingContext)
{
m_nonVirtualizingContext = winrt::make_weak(nonVirtualizingContext);
}
#pragma region ILayoutContextOverrides
winrt::IInspectable LayoutContextAdapter::LayoutStateCore()
{
if (auto context = m_nonVirtualizingContext.get())
{
return context.LayoutState();
}
return nullptr;
}
void LayoutContextAdapter::LayoutStateCore(winrt::IInspectable const& state)
{
if (auto context = m_nonVirtualizingContext.get())
{
context.LayoutStateCore(state);
}
}
#pragma endregion
#pragma region IVirtualizingLayoutContextOverrides
int32_t LayoutContextAdapter::ItemCountCore()
{
if (auto context = m_nonVirtualizingContext.get())
{
return context.Children().Size();
}
return 0;
}
winrt::IInspectable LayoutContextAdapter::GetItemAtCore(int index)
{
if (auto context = m_nonVirtualizingContext.get())
{
return context.Children().GetAt(index);
}
return nullptr;
}
winrt::UIElement LayoutContextAdapter::GetOrCreateElementAtCore(int index, winrt::ElementRealizationOptions const& options)
{
if (auto context = m_nonVirtualizingContext.get())
{
return context.Children().GetAt(index);
}
return nullptr;
}
void LayoutContextAdapter::RecycleElementCore(winrt::UIElement const& element)
{
}
int32_t LayoutContextAdapter::GetElementIndexCore(winrt::UIElement const& element)
{
if (auto context = m_nonVirtualizingContext.get())
{
auto children = context.Children();
for (unsigned int i = 0; i < children.Size(); i++)
{
if (children.GetAt(i) == element)
{
return i;
}
}
}
return -1;
}
winrt::Rect LayoutContextAdapter::RealizationRectCore()
{
return winrt::Rect{ 0, 0, std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity() };
}
int LayoutContextAdapter::RecommendedAnchorIndexCore()
{
return -1;
}
winrt::Point LayoutContextAdapter::LayoutOriginCore()
{
return winrt::Point(0, 0);
}
void LayoutContextAdapter::LayoutOriginCore(winrt::Point const& value)
{
if (value != winrt::Point(0, 0))
{
throw winrt::hresult_invalid_argument(L"LayoutOrigin must be at (0,0) when RealizationRect is infinite sized.");
}
}
#pragma endregion