Skip to content

Commit 062daa5

Browse files
author
grammarian
committed
- Simplified ColumnEdgeDecoration
git-svn-id: https://svn.code.sf.net/p/objectlistview/code/cs/trunk@827 0bec5ed8-b53f-49e6-9885-ce7bc93af311
1 parent c6d254e commit 062daa5

File tree

1 file changed

+12
-47
lines changed

1 file changed

+12
-47
lines changed

ObjectListView/Rendering/Decorations.cs

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public OLVColumn ColumnToDecorate {
172172
/// </summary>
173173
public Pen Pen {
174174
get {
175-
return this.pen ?? Pens.DarkRed;
175+
return this.pen ?? Pens.DarkSlateBlue;
176176
}
177177
set {
178178
if (this.pen == value)
@@ -315,16 +315,6 @@ public enum ColumnEdge {
315315
Right
316316
}
317317

318-
/// <summary>
319-
/// Specify if the decoration will be inside the column,
320-
/// overlap the column edge, or outside the column.
321-
/// </summary>
322-
public enum ColumnEdgeAlignment {
323-
Inside,
324-
Middle,
325-
Outside
326-
}
327-
328318
/// <summary>
329319
/// This decoration draws a line on the edge(s) of its given column
330320
/// </summary>
@@ -348,13 +338,13 @@ public ColumnEdgeDecoration() {
348338
/// <param name="column"></param>
349339
/// <param name="pen"></param>
350340
/// <param name="edge"></param>
351-
/// <param name="alignment"></param>
352-
public ColumnEdgeDecoration(OLVColumn column, Pen pen = null, ColumnEdge edge = ColumnEdge.Right, ColumnEdgeAlignment alignment = ColumnEdgeAlignment.Middle)
341+
/// <param name="xOffset"></param>
342+
public ColumnEdgeDecoration(OLVColumn column, Pen pen = null, ColumnEdge edge = ColumnEdge.Right, float xOffset = 0)
353343
: this() {
354344
this.ColumnToDecorate = column;
355345
this.Pen = pen;
356346
this.Edge = edge;
357-
this.Alignment = alignment;
347+
this.XOffset = xOffset;
358348
}
359349

360350
#endregion
@@ -371,14 +361,13 @@ public ColumnEdge Edge {
371361
private ColumnEdge edge = ColumnEdge.Right;
372362

373363
/// <summary>
374-
/// Gets or sets whether this decoration will draw a line inside the column, overlapping the edge,
375-
/// or outside of the column.
364+
/// Gets or sets the horizontal offset from centered at which the line will be drawn
376365
/// </summary>
377-
public ColumnEdgeAlignment Alignment {
378-
get { return alignment; }
379-
set { alignment = value; }
366+
public float XOffset {
367+
get { return xOffset; }
368+
set { xOffset = value; }
380369
}
381-
private ColumnEdgeAlignment alignment = ColumnEdgeAlignment.Middle;
370+
private float xOffset;
382371

383372
#endregion
384373

@@ -391,33 +380,9 @@ public override void DrawDecoration(ObjectListView olv, Graphics g, Rectangle r,
391380
}
392381

393382
private float CalculateEdge(Rectangle columnBounds) {
394-
int tweak = this.Pen.Width <= 2 ? 0 : 1;
395-
switch (this.Edge) {
396-
case ColumnEdge.Left:
397-
switch (this.Alignment) {
398-
case ColumnEdgeAlignment.Inside:
399-
return tweak + columnBounds.Left;
400-
case ColumnEdgeAlignment.Middle:
401-
return tweak + columnBounds.Left - this.Pen.Width / 2;
402-
case ColumnEdgeAlignment.Outside:
403-
return tweak + columnBounds.Left - this.Pen.Width;
404-
default:
405-
throw new ArgumentOutOfRangeException();
406-
}
407-
case ColumnEdge.Right:
408-
switch (this.Alignment) {
409-
case ColumnEdgeAlignment.Inside:
410-
return tweak + columnBounds.Right - this.Pen.Width;
411-
case ColumnEdgeAlignment.Middle:
412-
return tweak + columnBounds.Right - this.Pen.Width / 2;
413-
case ColumnEdgeAlignment.Outside:
414-
return tweak + columnBounds.Right;
415-
default:
416-
throw new ArgumentOutOfRangeException();
417-
}
418-
default:
419-
throw new ArgumentOutOfRangeException();
420-
}
383+
float tweak = this.XOffset + (this.Pen.Width <= 2 ? 0 : 1);
384+
int x = this.Edge == ColumnEdge.Left ? columnBounds.Left : columnBounds.Right;
385+
return tweak + x - this.Pen.Width / 2;
421386
}
422387

423388
#endregion

0 commit comments

Comments
 (0)