Howto:Creating a Canvas GUI Widget: Difference between revisions

Jump to navigation Jump to search
m
Line 147: Line 147:
== Examples ==
== Examples ==
{{Stub}}
{{Stub}}
=== Implementing a hrule widget ===
The following example is based on adapting the line-drawing example taken from [[Canvas_Snippets#Adding_OpenVG_Paths]].
For instance, consider the following snippet (assuming there is already a root group):
<syntaxhighlight lang="nasal">
var width = 640;
var height = 320;
var group = root.createChild("group");
var line = graph.createChild("path", "hrule")
.moveTo(10, height/2)
.lineTo(width-10, height/2)
.setColor(1,0,0) # red
.setStrokeLineWidth(3); # thickness
</syntaxhighlight>
To adapt this to work as a widget, we need to get rid of the width/height variables and instead refer to the position vector in Widget.nas:


=== Implementing a slider widget ===
=== Implementing a slider widget ===

Navigation menu