Skip to content

Commit f16c77f

Browse files
committed
Improve decor rendering to match theme info
Adapt WPF demo
1 parent 3c8bcaf commit f16c77f

5 files changed

Lines changed: 108 additions & 53 deletions

File tree

src/Demo/CanvasWindow.xaml.cs

Lines changed: 76 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -115,53 +115,85 @@ private IEnumerable<ConsumerDefinition> BuildColumns()
115115
foreach (
116116
var child in Enumerable
117117
.Range(0, a)
118-
.Select(x => new ConsumerDefinition
118+
.Select(x =>
119119
{
120-
Content = x.ToString(),
121-
Consumer = o => o is int idx ? idx + (2 * x) : "Oops",
122-
Formatter = o => $"Res: {o}",
123-
Qualify = o =>
124-
int.TryParse(o.ToString(), out var i)
125-
? i switch
126-
{
127-
4 => Qualification.Remark,
128-
6 => Qualification.Warning,
129-
9 => Qualification.Error,
130-
10 => Qualification.ReadOnly,
131-
17 => Qualification.Custom,
132-
18 => Qualification.Custom,
133-
_ => Qualification.Normal
134-
}
135-
: Qualification.Normal,
136-
Colorize = o =>
137-
int.TryParse(o.ToString(), out var i)
138-
? i switch
139-
{
140-
17
141-
=> (
142-
new ThemeColor(150, 100, 120, 0),
143-
new ThemeColor(255, 0, 0, 0)
144-
),
145-
18
146-
=> (
147-
new ThemeColor(150, 0, 100, 120),
148-
new ThemeColor(255, 255, 0, 0)
149-
),
150-
_
151-
=> (
152-
new ThemeColor(0, 0, 0, 0),
153-
new ThemeColor(0, 255, 0, 0)
154-
)
155-
}
156-
: (
157-
new ThemeColor(0, 0, 0, 0),
158-
new ThemeColor(0, 0, 0, 0)
159-
),
160-
Editor = (p, c, s) =>
120+
var cdef = new ConsumerDefinition
121+
{
122+
Content = x.ToString(),
123+
Consumer = o => o is int idx ? idx + (2 * x) : "Oops",
124+
Formatter = o => $"Res: {o}",
125+
Qualify = o =>
126+
int.TryParse(o.ToString(), out var i)
127+
? i switch
128+
{
129+
4 => Qualification.Remark,
130+
6 => Qualification.Warning,
131+
9 => Qualification.Error,
132+
10 => Qualification.ReadOnly,
133+
17 => Qualification.Custom,
134+
18 => Qualification.Custom,
135+
_ => Qualification.Normal
136+
}
137+
: Qualification.Normal,
138+
Colorize = o =>
139+
int.TryParse(o.ToString(), out var i)
140+
? i switch
141+
{
142+
17
143+
=> (
144+
new ThemeColor(150, 100, 120, 0),
145+
new ThemeColor(255, 0, 0, 0)
146+
),
147+
18
148+
=> (
149+
new ThemeColor(150, 0, 100, 120),
150+
new ThemeColor(255, 255, 0, 0)
151+
),
152+
_
153+
=> (
154+
new ThemeColor(0, 0, 0, 0),
155+
new ThemeColor(0, 255, 0, 0)
156+
)
157+
}
158+
: (
159+
new ThemeColor(0, 0, 0, 0),
160+
new ThemeColor(0, 0, 0, 0)
161+
),
162+
Editor = (p, c, s) =>
163+
{
164+
this.Log().Debug($"{p} _ {c} _ {s}");
165+
return !string.IsNullOrWhiteSpace(s);
166+
}
167+
};
168+
169+
switch (x)
161170
{
162-
this.Log().Debug($"{p} _ {c} _ {s}");
163-
return !string.IsNullOrWhiteSpace(s);
171+
case 3:
172+
cdef.RightDecor = (_, o) =>
173+
o switch
174+
{
175+
int i
176+
=> i % 2 == 0
177+
? "Resources/comment.svg"
178+
: string.Empty,
179+
_ => string.Empty,
180+
};
181+
cdef.Editor = (p, c, s) =>
182+
{
183+
this.Log().Debug($"{p} _ {c} _ {s}");
184+
return !string.IsNullOrWhiteSpace(s);
185+
};
186+
break;
187+
case 5:
188+
cdef.LeftDecor = (_, o) => "Resources/comment.svg";
189+
break;
190+
case 6:
191+
cdef.RightDecor = (_, o) => "Resources/comment.svg";
192+
cdef.LeftDecor = (_, o) => "Resources/edit.svg";
193+
break;
164194
}
195+
196+
return cdef;
165197
})
166198
)
167199
{

src/Demo/Demo.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
<LangVersion>default</LangVersion>
88
</PropertyGroup>
99

10+
<ItemGroup>
11+
<Content Include="Resources\comment.svg">
12+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
13+
</Content>
14+
<Content Include="Resources\edit.svg">
15+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
16+
</Content>
17+
</ItemGroup>
18+
1019
<ItemGroup>
1120
<PackageReference Include="Bogus" Version="35.6.5" />
1221
<PackageReference Include="NLog" Version="6.0.6" />

src/Demo/Resources/comment.svg

Lines changed: 3 additions & 0 deletions
Loading

src/Demo/Resources/edit.svg

Lines changed: 8 additions & 0 deletions
Loading

src/HierarchyGrid.Skia/CanvasExtensions.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -882,15 +882,18 @@ private static void RenderDecor(
882882
cell.Top + (screenScale * ((cell.Height - picture.CullRect.Height) / 2))
883883
);
884884

885-
canvas.DrawPicture(
886-
picture,
887-
new SKPoint(x, y),
888-
new SKPaint()
889-
{
890-
Color = renderInfo.ForegroundColor,
891-
Style = SKPaintStyle.StrokeAndFill,
892-
}
893-
);
885+
/* Override path colors to match grid rendering info */
886+
using var paint = new SKPaint()
887+
{
888+
Color = renderInfo.ForegroundColor,
889+
Style = SKPaintStyle.StrokeAndFill,
890+
ColorFilter = SKColorFilter.CreateBlendMode(
891+
renderInfo.ForegroundColor,
892+
SKBlendMode.SrcIn
893+
)
894+
};
895+
896+
canvas.DrawPicture(picture, new SKPoint(x, y), paint);
894897
}
895898

896899
private static void RenderRightSideDecor(

0 commit comments

Comments
 (0)