Sneak peek: The Snap Lines feature in XtraReports v2009.3

ctodx
27 November 2009

A few weeks ago I published a blog post about the new report designer in our reporting product. This is due to be released very soon and, to be honest, for such a great feature, my post left a little to be desired in terms of details. Alex, who writes for the XtraCharts and XtraReports teams, thought it would be a good idea for me to interview members of the development team and get them to reveal more about the new XtraReports.

Dmitry In this first article, he hooked me up with Dmitry Barakhov (whose handle is Dem in the forums), and Dmitry talked about the Snap Lines feature he implemented.

JMB: First of all, what do "snap lines" mean and what is their purpose?

Dem: Basically, snap lines are for the design-time positioning of different UI elements; in our case, for the positioning of report controls.

Let me give you a little background and tell you about the history of this problem. It is common practice to have a report with elements' edges aligned with other elements' edges. To solve this task in XtraReports prior to v2009.3, we had a grid of dots and you positioned controls on that grid:

SnapLines1

However this approach has several drawbacks. First, the corresponding preview of a document will differ from its design-time representation because there will be no dots in the preview. Obviously so — the grid is presented at design time but is not visible at runtime, so having the grid means the user does not get a true visualization of what the runtime preview of the document will look like.

On the sixth day of DevExpress Christmas, I found the new and improved XtraReports Script Editor Another problem with this approach is the necessity to have report elements already aligned to the grid so that other elements would have the ability to be aligned to them. Sometimes this is just not very convenient (in the picture above you can see that xrLabel2 is aligned to the grid but not to the left coordinate of xrLabel1, we have to make sure that's aligned to the grid ourselves).

The 'snap lines' approach, introduced by the Visual Studio Windows Forms designer as well as designers like Blend, doesn't have these shortcomings. It can work without a grid and it allows you to precisely align a control to another control's coordinates.

SnapLines2

JMB: Are snap lines enabled by default?

Dem: Yes. In fact there is a new property in XtraReports — SnappingMode — that regulates this behavior. Its default value is set to SnapLines, but the user can switch to SnapToGrid to return to the old behavior.

JMB: When are snap lines functional? Only during the drag-and-drop of controls within a band?

Dem: Snap lines certainly work during the dragging of controls within a band, but they also work when drag-dropping from one band to another (by the way, snap lines can be disabled during a drag-drop operation by pressing the ALT key). Not only that, but they are also functional during resizing either by using the mouse or keyboard. And finally, they are operative when picking a control from a toolbox and dropping it onto a report.

JMB: What kinds of snap lines are supported by XtraReports in v2009.3?

Dem: For now I've implemented what might be called the "bounds" type of snap lines — that is, the ability to align a report element to another report element's Left, Top, Right, or Bottom coordinates — and the "margin" type of snap lines — that is, the ability to indent a control from another control. This indent is specified by a control's SnapLineMargin and SnapLinePadding for container controls like the XRPanel and XRTableCell.

JMB: Neat. Any plans for expanding this functionality in the future, or (laughs) is there nothing left to do?

Dem: Of course there is more to do [;-)]. For example: snap lines that align to the "Base line" of text is another cool kind of snap line that we are going to implement in the near future. Another is  the ability to add custom snap lines and the ability to restrict certain kinds of snap lines on a particular control.

JMB: Dmitry, thank you for talking with me. Good luck with extending snap lines in future releases!

Dem: You are always welcome!

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.