define getSegmentPositionByPixelLocation for <, > axis extents
diff --git a/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/Axis.xtend b/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/Axis.xtend
index 1981b93..13451f3 100644
--- a/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/Axis.xtend
+++ b/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/Axis.xtend
@@ -24,8 +24,11 @@
def int getStartPixelOfSegmentPosition(int segmentPosition)
/**
+ * Gets the position of the segment that is nearest to the the given pixel location.
+ *
* @param pixelLocation
- * @return The position of the segment that contains the given pixel location.
+ * @return The position of the segment that contains the given pixel location. If the given pixel location is less than 0, the segment position
+ * returned will be 0. If the given pixel location is greater than the size of the axis, then the last segment position will be returned.
*/
def int getSegmentPositionOfPixelLocation(int pixelLocation)
diff --git a/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/impl/AxisImpl.xtend b/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/impl/AxisImpl.xtend
index 2592a4c..be37a68 100644
--- a/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/impl/AxisImpl.xtend
+++ b/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/impl/AxisImpl.xtend
@@ -54,8 +54,8 @@
}
override getSegmentPositionOfPixelLocation(int pixelLocation) {
- if (pixelLocation < 0) return -1
- else if (pixelLocation == 0) return 0
+ if (pixelLocation <= 0) return 0
+ else if (pixelLocation > pixelSize) return segmentCount - 1
else if (segmentSizeMap.empty) return pixelLocation / defaultSegmentSize
else return findSegmentPositionOfPixelLocation(pixelLocation, 0, pixelSize, 0, segmentCount)
}
diff --git a/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/impl/hideshow/HideShowAxis.xtend b/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/impl/hideshow/HideShowAxis.xtend
index 53d760b..20a4ff0 100644
--- a/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/impl/hideshow/HideShowAxis.xtend
+++ b/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/impl/hideshow/HideShowAxis.xtend
@@ -50,13 +50,15 @@
}
override getSegmentPositionOfPixelLocation(int pixelLocation) {
+ if (pixelLocation < 0) return 0
+
for (segmentPosition : 0 .. segmentCount) {
val startPixel = getStartPixelOfSegmentPosition(segmentPosition)
if (startPixel > pixelLocation)
return segmentPosition - 1
}
- return -1
+ return segmentCount - 1
}
// TODO Optimize. Cache?
diff --git a/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/impl/reorder/ReorderAxis.xtend b/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/impl/reorder/ReorderAxis.xtend
index 6eab87d..ce46c74 100644
--- a/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/impl/reorder/ReorderAxis.xtend
+++ b/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/impl/reorder/ReorderAxis.xtend
@@ -52,13 +52,15 @@
}
override getSegmentPositionOfPixelLocation(int pixelLocation) {
+ if (pixelLocation < 0) return 0
+
for (segmentPosition : 0 .. segmentCount) {
val startPixel = getStartPixelOfSegmentPosition(segmentPosition)
if (startPixel > pixelLocation)
return segmentPosition - 1
}
- return -1
+ return segmentCount - 1
}
override getIdOfSegmentPosition(int segmentPosition) {
diff --git a/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/composite/CompositeAxis.xtend b/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/composite/CompositeAxis.xtend
index b2048f5..aaae4c4 100644
--- a/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/composite/CompositeAxis.xtend
+++ b/NatTable/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/composite/CompositeAxis.xtend
@@ -49,6 +49,9 @@
}
override getSegmentPositionOfPixelLocation(int pixelLocation) {
+ if (pixelLocation < 0) return 0
+ if (pixelLocation > pixelSize) return segmentCount - 1
+
var segmentOffset = 0
var pixelOffset = 0
diff --git a/NatTable/src/org/eclipse/nebula/widgets/nattable/renderer/swt/layer/viewport/SWTViewportLayerPainter.xtend b/NatTable/src/org/eclipse/nebula/widgets/nattable/renderer/swt/layer/viewport/SWTViewportLayerPainter.xtend
index 76c8c2f..12b6f2d 100644
--- a/NatTable/src/org/eclipse/nebula/widgets/nattable/renderer/swt/layer/viewport/SWTViewportLayerPainter.xtend
+++ b/NatTable/src/org/eclipse/nebula/widgets/nattable/renderer/swt/layer/viewport/SWTViewportLayerPainter.xtend
@@ -18,6 +18,7 @@
override paintLayer(ViewportLayer viewportLayer, GraphicsContext gc) {
val swtGC = gc as SWTGraphicsContext
+
if (viewportCanvas == null) {
viewportCanvas = new Canvas(swtGC.SWTComposite, SWT::H_SCROLL.bitwiseOr(SWT::V_SCROLL))
@@ -27,8 +28,8 @@
viewportCanvas.verticalBar.addListener(SWT::Selection, [ event | println(event) ])
viewportCanvas.addPaintListener([ event | defaultPainter.paintLayer(viewportLayer, new SWTGraphicsContext(viewportCanvas, event.gc)) ])
}
+
val clipBounds = swtGC.SWTGC.clipping
- println('''viewport clipBounds «clipBounds»''')
viewportCanvas.bounds = new Rectangle(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height)
}