Skip to content

Commit ecb0cac

Browse files
committed
- Add listbox clipping class for rounded corner theme.
1 parent bb7b0cd commit ecb0cac

File tree

4 files changed

+194
-481
lines changed

4 files changed

+194
-481
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
using System.Windows.Data;
9+
using System.Windows.Media;
10+
using System.Windows.Documents;
11+
using System.Windows.Shapes;
12+
13+
// For Clipping inside listbox item
14+
15+
namespace Flow.Launcher.Converters
16+
{
17+
public class BorderClipConverter : IMultiValueConverter
18+
{
19+
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
20+
{
21+
if (values.Length == 3 && values[0] is double && values[1] is double && values[2] is CornerRadius)
22+
{
23+
var width = (double)values[0];
24+
var height = (double)values[1];
25+
Path myPath = new Path();
26+
if (width < Double.Epsilon || height < Double.Epsilon)
27+
{
28+
return Geometry.Empty;
29+
}
30+
var radius = (CornerRadius)values[2];
31+
var radiusHeight = radius.TopLeft;
32+
33+
// Drawing Round box for bottom round, and rect for top area of listbox.
34+
var corner = new RectangleGeometry(new Rect(0, 0, width, height), radius.TopLeft, radius.TopLeft);
35+
var box = new RectangleGeometry(new Rect(0, 0, width, radiusHeight), 0, 0);
36+
37+
GeometryGroup myGeometryGroup = new GeometryGroup();
38+
myGeometryGroup.Children.Add(corner);
39+
myGeometryGroup.Children.Add(box);
40+
41+
CombinedGeometry c1 = new CombinedGeometry(GeometryCombineMode.Union, corner, box);
42+
myPath.Data = c1;
43+
44+
myPath.Data.Freeze();
45+
return myPath.Data;
46+
}
47+
48+
return DependencyProperty.UnsetValue;
49+
}
50+
51+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
52+
{
53+
throw new NotSupportedException();
54+
}
55+
}
56+
57+
public class PartiallyRoundedRectangle : Shape
58+
{
59+
public static readonly DependencyProperty RadiusXProperty;
60+
public static readonly DependencyProperty RadiusYProperty;
61+
62+
public static readonly DependencyProperty RoundTopLeftProperty;
63+
public static readonly DependencyProperty RoundTopRightProperty;
64+
public static readonly DependencyProperty RoundBottomLeftProperty;
65+
public static readonly DependencyProperty RoundBottomRightProperty;
66+
67+
public int RadiusX
68+
{
69+
get { return (int)GetValue(RadiusXProperty); }
70+
set { SetValue(RadiusXProperty, value); }
71+
}
72+
73+
public int RadiusY
74+
{
75+
get { return (int)GetValue(RadiusYProperty); }
76+
set { SetValue(RadiusYProperty, value); }
77+
}
78+
79+
public bool RoundTopLeft
80+
{
81+
get { return (bool)GetValue(RoundTopLeftProperty); }
82+
set { SetValue(RoundTopLeftProperty, value); }
83+
}
84+
85+
public bool RoundTopRight
86+
{
87+
get { return (bool)GetValue(RoundTopRightProperty); }
88+
set { SetValue(RoundTopRightProperty, value); }
89+
}
90+
91+
public bool RoundBottomLeft
92+
{
93+
get { return (bool)GetValue(RoundBottomLeftProperty); }
94+
set { SetValue(RoundBottomLeftProperty, value); }
95+
}
96+
97+
public bool RoundBottomRight
98+
{
99+
get { return (bool)GetValue(RoundBottomRightProperty); }
100+
set { SetValue(RoundBottomRightProperty, value); }
101+
}
102+
103+
static PartiallyRoundedRectangle()
104+
{
105+
RadiusXProperty = DependencyProperty.Register
106+
("RadiusX", typeof(int), typeof(PartiallyRoundedRectangle));
107+
RadiusYProperty = DependencyProperty.Register
108+
("RadiusY", typeof(int), typeof(PartiallyRoundedRectangle));
109+
110+
RoundTopLeftProperty = DependencyProperty.Register
111+
("RoundTopLeft", typeof(bool), typeof(PartiallyRoundedRectangle));
112+
RoundTopRightProperty = DependencyProperty.Register
113+
("RoundTopRight", typeof(bool), typeof(PartiallyRoundedRectangle));
114+
RoundBottomLeftProperty = DependencyProperty.Register
115+
("RoundBottomLeft", typeof(bool), typeof(PartiallyRoundedRectangle));
116+
RoundBottomRightProperty = DependencyProperty.Register
117+
("RoundBottomRight", typeof(bool), typeof(PartiallyRoundedRectangle));
118+
}
119+
120+
public PartiallyRoundedRectangle()
121+
{
122+
}
123+
124+
protected override Geometry DefiningGeometry
125+
{
126+
get
127+
{
128+
Geometry result = new RectangleGeometry
129+
(new Rect(0, 0, base.Width, base.Height), RadiusX, RadiusY);
130+
double halfWidth = base.Width / 2;
131+
double halfHeight = base.Height / 2;
132+
133+
if (!RoundTopLeft)
134+
result = new CombinedGeometry
135+
(GeometryCombineMode.Union, result, new RectangleGeometry
136+
(new Rect(0, 0, halfWidth, halfHeight)));
137+
if (!RoundTopRight)
138+
result = new CombinedGeometry
139+
(GeometryCombineMode.Union, result, new RectangleGeometry
140+
(new Rect(halfWidth, 0, halfWidth, halfHeight)));
141+
if (!RoundBottomLeft)
142+
result = new CombinedGeometry
143+
(GeometryCombineMode.Union, result, new RectangleGeometry
144+
(new Rect(0, halfHeight, halfWidth, halfHeight)));
145+
if (!RoundBottomRight)
146+
result = new CombinedGeometry
147+
(GeometryCombineMode.Union, result, new RectangleGeometry
148+
(new Rect(halfWidth, halfHeight, halfWidth, halfHeight)));
149+
150+
return result;
151+
}
152+
}
153+
}
154+
}

0 commit comments

Comments
 (0)