Adam D. Ruppe's Minigui using example
Andre Pany
andre at s-e-a-p.de
Sat Aug 17 21:08:08 UTC 2019
https://forum.dlang.org/post/mumgkqopnsnowcmhidop@forum.dlang.org
On Saturday, 16 January 2016 at 03:14:01 UTC, Adam D. Ruppe wrote:
> On Saturday, 16 January 2016 at 01:27:32 UTC, Andre Polykanine
> wrote:
>> Does anyone have an actual example of, say, a simple form with
>> a set of radio buttons or check boxes to start with?
>> Thanks in advance!
>
> Sort of. I still haven't used it in a real world program so it
> isn't complete but here's one of my test programs:
>
> ---
> import arsd.minigui;
>
> void main() {
> auto window = new MainWindow();
>
> auto exitAction = new Action("E&xit");
> exitAction.triggered ~= { window.close(); };
>
> window.statusTip = "D ROX!";
>
> auto button = new Checkbox("Uses D!", window);
> button.isChecked = true;
>
> auto hlayout = new HorizontalLayout(window);
> auto gb = new Fieldset("Type", hlayout);
> auto gb2 = new Fieldset("cool", hlayout);
>
> auto boxlol1 = new Radiobox("Test", gb);
> auto boxlol2 = new Radiobox("Test2", gb2);
>
> auto boxlol3 = new Radiobox("Test", gb);
> auto boxlol4 = new Radiobox("Test2", gb2);
>
> auto group = new MutuallyExclusiveGroup();
> group.addMember(new Radiobox("Heavyweight", gb));
>
> auto btn = group.addMember(new Radiobox("Small
> library", gb));
> btn.isChecked = true;
> btn.statusTip = "205 KB exe on Windows";
>
> //auto spinner = new Spinner(window);
> ComboboxBase cb = new DropDownSelection(window);
> cb.addOption("test");
> cb.addOption("cool");
> cb.setSelection(1);
>
> //cb.addEventListener("changed", (Event ev) {
> //auto bm = new MessageBox("changed " ~
> cb.options[cb.selection]);
> //});
>
> // FIXME: adding this to gb2 instead of window causes
> wtf stuff
> cb = new ComboBox(window);
> cb.addOption("test");
> cb.addOption("cool");
> cb.setSelection(1);
>
>
> cb = new FreeEntrySelection(window);
> cb.addOption("test");
> cb.addOption("cool");
> cb.setSelection(1);
>
> auto lineEdit = new LineEdit(window);
>
> auto menu = new MenuBar();
> auto fileMenu = new Menu("&File");
> auto exitButton = fileMenu.addItem(new
> MenuItem(exitAction));
>
> menu.addItem(fileMenu);
>
> window.loop();
> }
> ---
>
>
> On Windows, it uses the native controls, so it should work
> reasonably well, though on Linux it does its own thing and is
> far from complete.
>
>
>
> BTW simplewindow doesn't seem to compile on newest dmd because
> of the new core.sys.windows.windows so I'll have to update that
> if you're on the newest release...
While searching for a minigui example in Google, you likely will
find this old outdated example. Therefore I answer this very old
post. Here a new example from Adam:
module menutest;
import arsd.minigui;
struct Info {
string name;
string email;
}
class MyWindow : MainWindow {
this() {
super("Menu Demo", 250, 400);
setMenuAndToolbarFromAnnotatedCode(this);
statusTip = "gnarley";
textEdit = new TextEdit(this);
auto hl = new HorizontalLayout(this);
auto btn = new Button("test", hl);
auto btn2 = new Button("test", hl);
btn.addEventListener("click", () {
messageBox("You clicked");
});
btn2.addEventListener(EventType.triggered, () {
dialog!Info((info) {
import std.conv;
textEdit.content = to!string(info);
});
});
textEdit.content = "generic content here";
}
TextEdit textEdit;
@menu("File") {
@toolbar("")
@icon(GenericIcons.New)
@accelerator("Ctrl+Shift+N")
void New() {
textEdit.content = "";
}
@toolbar("")
@icon(GenericIcons.Open)
@accelerator("Ctrl+O")
void Open() {
getOpenFileName( (string s) {
//import std.file;
//textEdit.content = (readText(s));
} );
}
@toolbar("")
@icon(GenericIcons.Save)
void Save() @accelerator("Ctrl+S") { getSaveFileName( (string
s) {} ); }
void SaveAs() {}
@separator
void Exit() @accelerator("Alt+F4") { this.close(); }
}
@menu("Edit") {
@toolbar("")
@icon(GenericIcons.Undo)
@accelerator("Ctrl+Z")
void Undo() {}
@toolbar("")
@icon(GenericIcons.Redo)
@accelerator("Ctrl+R")
void Redo() {}
@separator
@toolbar("")
@icon(GenericIcons.Cut)
@accelerator("Ctrl+X")
void Cut() {}
@toolbar("")
@icon(GenericIcons.Copy)
@accelerator("Ctrl+C")
void Copy() {}
@toolbar("")
@icon(GenericIcons.Paste)
@accelerator("Ctrl+V")
void Paste() {}
}
@menu("Help") {
@accelerator("F1")
void Topics() {}
@separator
void About() {}
}
}
void main() {
auto window = new MyWindow();
window.loop();
}
Kind regards
Andre
More information about the Digitalmars-d-learn
mailing list