Canvas

Canvas widgets implement structured graphics. A canvas displays any number of items, which may be things like rectangles, circles, lines, and text. Items may be manipulated (e.g. moved or re-colored) and commands may be associated with items in much the same way that the bind command allows commands to be bound to widgets.

Constructors

this
this(UiElement parent, string backgroundColor)

Construct the widget.

this
this(string backgroundColor)

Construct the widget.

Members

Functions

addItem
auto addItem(CanvasItem item)

Add an item to the canvas.

addTagConfig
auto addTagConfig(CanvasTagConfig tagConfig)

Add a tag configuration to the canvas. These can apply options to a tag which can then be applied to any item.

getItemIdNear
int getItemIdNear(int xPos, int yPos, uint radius)

Get an item id nearest to coordinates. If more than one item is at the same closest distance (e.g. two items overlap the point), then the top-most of these items (the last one in the display list) is used. If radius is specified, then it must be a non-negative value. Any item closer than halo to the point is considered to overlap it.

getItemIdsIn
int[] getItemIdsIn(int x1, int y1, int x2, int y2, bool enclosedFully)

Get items within a selection region.

getXPosFromScreen
int getXPosFromScreen(int screenXPos, int gridSpacing)

Get the horizontal position on the canvas that relates to a particular horizontal position on screen.

getYPosFromScreen
int getYPosFromScreen(int screenYPos, int gridSpacing)

Get the vertical position on the canvas that relates to a particular vertical position on screen.

scanDragTo
auto scanDragTo(double xPos, double yPos, int gain)

This command is used to implement scanning on canvases. This command computes the difference between its xPos and yPos arguments (which are typically mouse coordinates) and the xPos and yPos arguments to the last setScanMark command for the widget. It then adjusts the view by gain times the difference in coordinates, where gain defaults to 1. This command is typically associated with mouse motion events in the widget, to produce the effect of dragging the canvas at high speed through its window.

setBackgroundColor
auto setBackgroundColor(string color)

Set the background color. Use colors from the preset color list or a web style hex color.

setScanMark
auto setScanMark(double xPos, double yPos)

This command is used to implement scanning on canvases. Records x and y positions and the canvas's current view. This is used in conjunction with later scanDragTo commands.

setScrollIncrement
auto setScrollIncrement(int increment)

Set the scroll increment i.e. how many pixels are scrolled per each click on a scrollbar.

setScrollRegion
auto setScrollRegion(double left, double top, double right, double bottom)

Set the scroll region of the canvas. This region can be scrolled using scrollbars if it's bigger than the canvas widget itself.

setSelectionTolerance
auto setSelectionTolerance(double tolerance)

Specifies a floating-point value indicating how close the mouse cursor must be to an item before it is considered to be 'inside' the item and able to select it. Defaults to 1.0.

tagItemIn
auto tagItemIn(string tag, int x1, int y1, int x2, int y2, bool enclosedFully)

Tag items within a selection region.

tagItemNear
auto tagItemNear(string tag, int xPos, int yPos, uint radius)

Tag an item nearest to coordinates. If more than one item is at the same closest distance (e.g. two items overlap the point), then the top-most of these items (the last one in the display list) is used. If radius is specified, then it must be a non-negative value. Any item closer than halo to the point is considered to overlap it.

tagItemWithTag
auto tagItemWithTag(string tag, string searchTag)

Tag items that are already tagged with another tag.

Mixins

__anonymous
mixin Border

Mixin common commands.

__anonymous
mixin Height
Undocumented in source.
__anonymous
mixin Relief
Undocumented in source.
__anonymous
mixin Width
Undocumented in source.
__anonymous
mixin XScrollCommand!(Canvas)
Undocumented in source.
__anonymous
mixin XView
Undocumented in source.
__anonymous
mixin YScrollCommand!(Canvas)
Undocumented in source.
__anonymous
mixin YView
Undocumented in source.

Mixed In Members

From mixin Border

setBorderWidth
auto setBorderWidth(int width)

Set the border width of the widget.

From mixin Height

setHeight
auto setHeight(int height)

Set the height of the widget if the geometry manager allows.

From mixin Relief

setRelief
auto setRelief(string relief)

Set the relief type of the widget.

From mixin Width

setWidth
auto setWidth(int width)

Set the width of the widget if the geometry manager allows.

From mixin XView

getXView
double[] getXView()

Get floating point values which represent the viewable portion of the text. Each element is a real fraction between 0 and 1; together they describe the horizontal span that is visible in the window. For example, if the first element is .2 and the second element is .6, 20% of the entry's text is off-screen to the left, the middle 40% is visible in the window, and 40% of the text is off-screen to the right.

setXView
auto setXView(double position)

Adjusts the view in the window so that the position appears at the left edge of the window. Position must be a fraction between 0.0 (start of the text) and 1.0 (end of the text).

scrollXToChar
auto scrollXToChar(int charIndex)

Adjusts the view in the window so that the character index passed is displayed at the left edge of the window.

scrollXChars
auto scrollXChars(int numberOfChars)

Scroll the text by a specified amount of characters. Positive values scroll text to the left, negative values scroll text to the right.

scrollXPages
auto scrollXPages(int numberOfPages)

Scroll the text by a specified amount of pages. Positive values scroll text to the left, negative values scroll text to the right.

From mixin YView

getYView
double[] getYView()

Get floating point values which represent the viewable portion of the text. Each element is a real fraction between 0 and 1; together they describe the vertical span that is visible in the window. For example, if the first element is .2 and the second element is .6, 20% of the entry's text is off-screen to the bottom, the middle 40% is visible in the window, and 40% of the text is off-screen to the bottom.

setYView
auto setYView(double position)

Adjusts the view in the window so that the position appears at the top edge of the window. Position must be a fraction between 0.0 (start of the text) and 1.0 (end of the text).

scrollYToChar
auto scrollYToChar(int charIndex)

Adjusts the view in the window so that the character index passed is displayed at the top edge of the window.

scrollYChars
auto scrollYChars(int numberOfChars)

Scroll the text by a specified amount of characters. Positive values scroll text to the down, negative values scroll text up.

scrollYPages
auto scrollYPages(int numberOfPages)

Scroll the text by a specified amount of pages. Positive values scroll text up, negative values scroll text down.

Inherited Members

From Widget

setState
auto setState(string[] state)

Set the widget's state.

getState
string[] getState()

Get the widget's state.

inState
bool inState(string[] state)

Test if a widget is in a particular state.

removeState
auto removeState(string[] state)

Remove the widget's state.

resetState
auto resetState()

Reset the widget's state to default.

setStyle
auto setStyle(string style)

Set the widget's style.

getStyle
string getStyle()

Get the widget's style.

setKeyboardFocus
auto setKeyboardFocus(string focus)

Set if the widget can recieve focus during keyboard traversal.

getKeyboardFocus
string getKeyboardFocus()

Get if the widget can recieve focus during keyboard traversal.

pack
auto pack(int outerPadding, int innerPadding, string side, string fill, string anchor, bool expand)

Geometry method for loosely placing this widget inside its parent using a web browser model. Widgets flow around each other in the available space.

grid
auto grid(int column, int row, int outerPadding, int innerPadding, int columnSpan, int rowSpan, string sticky)

Geometry method for placing this widget inside its parent using an imaginary grid. Somewhat more direct and intuitive than pack. Choose grid for tabular layouts, and when there's no good reason to choose something else.

place
auto place(int xPos, int yPos, int width, int height, string anchor, string borderMode)

Geometry method for placing this widget inside its parent using absolute positioning.

place
auto place(double relativeXPos, double relativeYPos, double relativeWidth, double relativeHeight, string anchor, string borderMode)

Geometry method for placing this widget inside its parent using relative positioning. In this case the position and size is specified as a floating-point number between 0.0 and 1.0 relative to the height of the parent. 0.5 means the widget will be half as high as the parent and 1.0 means the widget will have the same height as the parent, and so on.

Examples

auto canvas = new Canvas(Color.white)
	.setWidth(350)
	.setHeight(250)
	.addItem(new CanvasRectangle([10, 10, 200, 100]))
	.bind("<ButtonPress-1>", delegate(CommandArgs args){ ... })
	.pack();

Common Commands

These are injected common commands that can also be used with this widget.

Border
Height
Relief
Width
XScrollCommand
XView
YScrollCommand
YView

Additional Events

Additional events that can also be bound to using the bind method.

&lt;&lt;PrevWindow&gt;&gt;, &lt;Alt-Key&gt;, &lt;Key-F10&gt;, &lt;Key-Tab&gt;,

See Also

Meta