Canvas snippets: Difference between revisions

Jump to navigation Jump to search
Added tab widget example screenshot
(Added snippet for the new TabWidget)
(Added tab widget example screenshot)
Line 521: Line 521:
!Code
!Code
|-
|-
|Will be added shortly …
|[[File:Canvas TabWidget example.png|alt=Canvas TabWIdget example|thumb|Canvas TabWidget example showing the three default splash screens]]
|<syntaxhighlight lang="js" line="1">
|<syntaxhighlight lang="js" line="1">
window = canvas.Window.new([300, 300], "dialog");
var window = canvas.Window.new([300, 300], "dialog");
myCanvas = window.createCanvas();
var myCanvas = window.createCanvas().set("background", canvas.style.getColor("bg_color"));
root = myCanvas.createGroup();
var root = myCanvas.createGroup();
var vbox = canvas.VBoxLayout.new();
var vbox = canvas.VBoxLayout.new();
myCanvas.setLayout(vbox);
myCanvas.setLayout(vbox);
 
var tabs = canvas.gui.widgets.TabWidget.new(root, canvas.style, {});
var tabs = canvas.gui.widgets.TabWidget.new(root, canvas.style, {});
var tabsContent = tabs.getContent();
var tabsContent = tabs.getContent();
vbox.addItem(tabs);
vbox.addItem(tabs);
for (var i=1; i<=5; i+=1) {
 
    var tab = canvas.VBoxLayout.new();
var tab1 = canvas.VBoxLayout.new();
    var image = canvas.gui.widgets.Label.new(tabsContent, canvas.style, {});
var image1 = canvas.gui.widgets.Label.new(tabsContent, canvas.style, {})
    image.setImage("Textures/Splash" ~ i ~ ".png");
.setImage("Textures/Splash1.png")
    image.setFixedSize(128, 128);
.setFixedSize(128, 128);
    tab.addItem(image);
tab1.addItem(image1);
    var text = canvas.gui.widgets.Label.new(tabsContent, canvas.style, {})
var text1 = canvas.gui.widgets.Label.new(tabsContent, canvas.style, {})
      .setText("Texture " ~ i);
.setText("Texture 1");
    tab.addItem(text);
tab1.addItem(text1);
    tabs.addTab("tab" ~ i, "Texture " ~ i, tab);
tabs.addTab("tab1", "Texture 1", tab1);
}
 
var tab2 = canvas.VBoxLayout.new();
var image2 = canvas.gui.widgets.Label.new(tabsContent, canvas.style, {})
.setImage("Textures/Splash2.png")
.setFixedSize(128, 128);
tab2.addItem(image2);
var text2 = canvas.gui.widgets.Label.new(tabsContent, canvas.style, {})
.setText("Texture 2");
tab2.addItem(text2);
tabs.addTab("tab2", "Texture 2", tab2);
 
var tab3 = canvas.VBoxLayout.new();
var image3 = canvas.gui.widgets.Label.new(tabsContent, canvas.style, {})
.setImage("Textures/Splash3.png")
.setFixedSize(128, 128);
tab3.addItem(image3);
var text3 = canvas.gui.widgets.Label.new(tabsContent, canvas.style, {})
.setText("Texture 3");
tab3.addItem(text3);
tabs.addTab("tab3", "Texture 3", tab3);


</syntaxhighlight>
</syntaxhighlight>
97

edits

Navigation menu