Canvas snippets: Difference between revisions

Jump to navigation Jump to search
Added snippet for the new TabWidget
m (Johan G moved page Canvas Snippets to Canvas snippets: Sentence case title)
(Added snippet for the new TabWidget)
Line 513: Line 513:
</syntaxhighlight>
</syntaxhighlight>


|}
== Using TabWidgets ==
{| class="wikitable"
|+
!Screenshot
!Code
|-
|Will be added shortly …
|<syntaxhighlight lang="js" line="1">
window = canvas.Window.new([300, 300], "dialog");
myCanvas = window.createCanvas();
root = myCanvas.createGroup();
var vbox = canvas.VBoxLayout.new();
myCanvas.setLayout(vbox);
var tabs = canvas.gui.widgets.TabWidget.new(root, canvas.style, {});
var tabsContent = tabs.getContent();
vbox.addItem(tabs);
for (var i=1; i<=5; i+=1) {
    var tab = canvas.VBoxLayout.new();
    var image = canvas.gui.widgets.Label.new(tabsContent, canvas.style, {});
    image.setImage("Textures/Splash" ~ i ~ ".png");
    image.setFixedSize(128, 128);
    tab.addItem(image);
    var text = canvas.gui.widgets.Label.new(tabsContent, canvas.style, {})
      .setText("Texture " ~ i);
    tab.addItem(text);
    tabs.addTab("tab" ~ i, "Texture " ~ i, tab);
}
</syntaxhighlight>
|}
|}


97

edits

Navigation menu