markus / KCOM / WrapPanel / OrientedSize.cs @ ac4f1e13
이력 | 보기 | 이력해설 | 다운로드 (4.24 KB)
1 |
// (c) Copyright Microsoft Corporation. |
---|---|
2 |
// This source is subject to the Microsoft Public License (Ms-PL). |
3 |
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details. |
4 |
// All other rights reserved. |
5 |
|
6 |
using System; |
7 |
using System.Runtime.InteropServices; |
8 |
using System.Windows.Controls; |
9 |
|
10 |
namespace KCOM.WrapPanel |
11 |
{ |
12 |
/// <summary> |
13 |
/// The OrientedSize structure is used to abstract the growth direction from |
14 |
/// the layout algorithms of WrapPanel. When the growth direction is |
15 |
/// oriented horizontally (ex: the next element is arranged on the side of |
16 |
/// the previous element), then the Width grows directly with the placement |
17 |
/// of elements and Height grows indirectly with the size of the largest |
18 |
/// element in the row. When the orientation is reversed, so is the |
19 |
/// directional growth with respect to Width and Height. |
20 |
/// </summary> |
21 |
[StructLayout(LayoutKind.Sequential)] |
22 |
internal struct OrientedSize |
23 |
{ |
24 |
/// <summary> |
25 |
/// The orientation of the structure. |
26 |
/// </summary> |
27 |
private Orientation _orientation; |
28 |
|
29 |
/// <summary> |
30 |
/// Gets the orientation of the structure. |
31 |
/// </summary> |
32 |
public Orientation Orientation |
33 |
{ |
34 |
get { return _orientation; } |
35 |
} |
36 |
|
37 |
/// <summary> |
38 |
/// The size dimension that grows directly with layout placement. |
39 |
/// </summary> |
40 |
private double _direct; |
41 |
|
42 |
/// <summary> |
43 |
/// Gets or sets the size dimension that grows directly with layout |
44 |
/// placement. |
45 |
/// </summary> |
46 |
public double Direct |
47 |
{ |
48 |
get { return _direct; } |
49 |
set { _direct = value; } |
50 |
} |
51 |
|
52 |
/// <summary> |
53 |
/// The size dimension that grows indirectly with the maximum value of |
54 |
/// the layout row or column. |
55 |
/// </summary> |
56 |
private double _indirect; |
57 |
|
58 |
/// <summary> |
59 |
/// Gets or sets the size dimension that grows indirectly with the |
60 |
/// maximum value of the layout row or column. |
61 |
/// </summary> |
62 |
public double Indirect |
63 |
{ |
64 |
get { return _indirect; } |
65 |
set { _indirect = value; } |
66 |
} |
67 |
|
68 |
/// <summary> |
69 |
/// Gets or sets the width of the size. |
70 |
/// </summary> |
71 |
public double Width |
72 |
{ |
73 |
get |
74 |
{ |
75 |
return (Orientation == Orientation.Horizontal) ? |
76 |
Direct : |
77 |
Indirect; |
78 |
} |
79 |
set |
80 |
{ |
81 |
if (Orientation == Orientation.Horizontal) |
82 |
{ |
83 |
Direct = value; |
84 |
} |
85 |
else |
86 |
{ |
87 |
Indirect = value; |
88 |
} |
89 |
} |
90 |
} |
91 |
|
92 |
/// <summary> |
93 |
/// Gets or sets the height of the size. |
94 |
/// </summary> |
95 |
public double Height |
96 |
{ |
97 |
get |
98 |
{ |
99 |
return (Orientation != Orientation.Horizontal) ? |
100 |
Direct : |
101 |
Indirect; |
102 |
} |
103 |
set |
104 |
{ |
105 |
if (Orientation != Orientation.Horizontal) |
106 |
{ |
107 |
Direct = value; |
108 |
} |
109 |
else |
110 |
{ |
111 |
Indirect = value; |
112 |
} |
113 |
} |
114 |
} |
115 |
|
116 |
/// <summary> |
117 |
/// Initializes a new OrientedSize structure. |
118 |
/// </summary> |
119 |
/// <param name="orientation">Orientation of the structure.</param> |
120 |
public OrientedSize(Orientation orientation) : |
121 |
this(orientation, 0.0, 0.0) |
122 |
{ |
123 |
} |
124 |
|
125 |
/// <summary> |
126 |
/// Initializes a new OrientedSize structure. |
127 |
/// </summary> |
128 |
/// <param name="orientation">Orientation of the structure.</param> |
129 |
/// <param name="width">Un-oriented width of the structure.</param> |
130 |
/// <param name="height">Un-oriented height of the structure.</param> |
131 |
public OrientedSize(Orientation orientation, double width, double height) |
132 |
{ |
133 |
_orientation = orientation; |
134 |
|
135 |
// All fields must be initialized before we access the this pointer |
136 |
_direct = 0.0; |
137 |
_indirect = 0.0; |
138 |
|
139 |
Width = width; |
140 |
Height = height; |
141 |
} |
142 |
} |
143 |
} |