Howto:Creating a Canvas GUI dialog file: Difference between revisions

Jump to navigation Jump to search
Demo code tweaks/prepare for better screenshot
(Demo code tweaks/prepare for better screenshot)
Line 36: Line 36:
     var m = {
     var m = {
       parents: [DemoDialog],
       parents: [DemoDialog],
       _dlg: canvas.Window.new([400,300], "dialog")
       _dlg: canvas.Window.new([140,160], "dialog")
                         .set("title", "Demo Dialog")
                         .set("title", "VBoxLayout")
                         .set("resize", 1),
                         .set("resize", 1),
     };
     };
 
     m._dlg.getCanvas(1)
     m._dlg.getCanvas(1)
           .set("background", canvas.style.getColor("bg_color"));
           .set("background", canvas.style.getColor("bg_color"));
Line 47: Line 47:
     var vbox = canvas.VBoxLayout.new();
     var vbox = canvas.VBoxLayout.new();
     m._dlg.setLayout(vbox);
     m._dlg.setLayout(vbox);
 
     # this is where you can add widgets from $FG_ROOT/Nasal/canvas/gui/widgets, e.g.:
     # this is where you can add widgets from $FG_ROOT/Nasal/canvas/gui/widgets, e.g.:
     for(var i=0;i <=5; i+=1)
     for(var i = 0; i < 5; i += 1 )
    vbox.addItem(
      vbox.addItem(
                canvas.gui.widgets.Button.new(m._root, canvas.style, {})
        canvas.gui.widgets.Button.new(m._root, canvas.style, {})
                            .setText( "Button #"~i )
                                .setText("Button #" ~ i)
     );
      );
 
     var hint = vbox.sizeHint();
    hint[0] = math.max(140, hint[0]);
    m._dlg.setSize(hint);
 
     return m;
     return m;
   },
   },
};
};
 
var demo = DemoDialog.new();</syntaxhighlight>
var demo = DemoDialog.new();</syntaxhighlight>


166

edits

Navigation menu