mirror of https://github.com/buggins/dlangui.git
Refactor exmaple 1
This commit is contained in:
parent
51d1eabb8d
commit
1d5df4d634
|
@ -40,103 +40,9 @@ class TextEditorWidget : VerticalLayout {
|
|||
}
|
||||
}
|
||||
|
||||
Widget createEditorSettingsControl(EditWidgetBase editor) {
|
||||
HorizontalLayout res = new HorizontalLayout("editor_options");
|
||||
res.addChild((new CheckBox("wantTabs", "wantTabs"d)).checked(editor.wantTabs).addOnCheckChangeListener(delegate(Widget, bool checked) { editor.wantTabs = checked; return true;}));
|
||||
res.addChild((new CheckBox("useSpacesForTabs", "useSpacesForTabs"d)).checked(editor.useSpacesForTabs).addOnCheckChangeListener(delegate(Widget, bool checked) { editor.useSpacesForTabs = checked; return true;}));
|
||||
res.addChild((new CheckBox("readOnly", "readOnly"d)).checked(editor.readOnly).addOnCheckChangeListener(delegate(Widget, bool checked) { editor.readOnly = checked; return true;}));
|
||||
res.addChild((new CheckBox("showLineNumbers", "showLineNumbers"d)).checked(editor.showLineNumbers).addOnCheckChangeListener(delegate(Widget, bool checked) { editor.showLineNumbers = checked; return true;}));
|
||||
res.addChild((new CheckBox("fixedFont", "fixedFont"d)).checked(editor.fontFamily == FontFamily.MonoSpace).addOnCheckChangeListener(delegate(Widget, bool checked) {
|
||||
if (checked)
|
||||
editor.fontFamily(FontFamily.MonoSpace).fontFace("Courier New");
|
||||
else
|
||||
editor.fontFamily(FontFamily.SansSerif).fontFace("Arial");
|
||||
return true;
|
||||
}));
|
||||
res.addChild((new CheckBox("tabSize", "Tab size 8"d)).checked(editor.tabSize == 8).addOnCheckChangeListener(delegate(Widget, bool checked) {
|
||||
if (checked)
|
||||
editor.tabSize(8);
|
||||
else
|
||||
editor.tabSize(4);
|
||||
return true;
|
||||
}));
|
||||
return res;
|
||||
}
|
||||
|
||||
/// entry point for dlangui based application
|
||||
extern (C) int UIAppMain(string[] args)
|
||||
/// Constructs items for main menu
|
||||
auto constructMainMenu()
|
||||
{
|
||||
// always use trace, even for release builds
|
||||
//Log.setLogLevel(LogLevel.Trace);
|
||||
//Log.setFileLogger(new std.stdio.File("ui.log", "w"));
|
||||
|
||||
// resource directory search paths
|
||||
// not required if only embedded resources are used
|
||||
//string[] resourceDirs = [
|
||||
// appendPath(exePath, "../../../res/"), // for Visual D and DUB builds
|
||||
// appendPath(exePath, "../../../res/mdpi/"), // for Visual D and DUB builds
|
||||
// appendPath(exePath, "../../../../res/"),// for Mono-D builds
|
||||
// appendPath(exePath, "../../../../res/mdpi/"),// for Mono-D builds
|
||||
// appendPath(exePath, "res/"), // when res dir is located at the same directory as executable
|
||||
// appendPath(exePath, "../res/"), // when res dir is located at project directory
|
||||
// appendPath(exePath, "../../res/"), // when res dir is located at the same directory as executable
|
||||
// appendPath(exePath, "res/mdpi/"), // when res dir is located at the same directory as executable
|
||||
// appendPath(exePath, "../res/mdpi/"), // when res dir is located at project directory
|
||||
// appendPath(exePath, "../../res/mdpi/") // when res dir is located at the same directory as executable
|
||||
//];
|
||||
// setup resource directories - will use only existing directories
|
||||
//Platform.instance.resourceDirs = resourceDirs;
|
||||
|
||||
// embed resources listed in views/resources.list into executable
|
||||
embeddedResourceList.addResources(embedResourcesFromList!("resources.list")());
|
||||
|
||||
//version (USE_OPENGL) {
|
||||
// // you can turn on subpixel font rendering (ClearType) here
|
||||
//FontManager.subpixelRenderingMode = SubpixelRenderingMode.None; //
|
||||
//} else {
|
||||
// you can turn on subpixel font rendering (ClearType) here
|
||||
FontManager.subpixelRenderingMode = SubpixelRenderingMode.BGR; //SubpixelRenderingMode.None; //
|
||||
//}
|
||||
|
||||
// select translation file - for english language
|
||||
Platform.instance.uiLanguage = "en";
|
||||
// load theme from file "theme_default.xml"
|
||||
Platform.instance.uiTheme = "theme_default";
|
||||
//Platform.instance.uiTheme = "theme_dark";
|
||||
|
||||
// you can override default hinting mode here (Normal, AutoHint, Disabled)
|
||||
FontManager.hintingMode = HintingMode.Normal;
|
||||
// you can override antialiasing setting here (0 means antialiasing always on, some big value = always off)
|
||||
// fonts with size less than specified value will not be antialiased
|
||||
FontManager.minAnitialiasedFontSize = 0; // 0 means always antialiased
|
||||
//version (USE_OPENGL) {
|
||||
// // you can turn on subpixel font rendering (ClearType) here
|
||||
FontManager.subpixelRenderingMode = SubpixelRenderingMode.None; //
|
||||
//} else {
|
||||
// you can turn on subpixel font rendering (ClearType) here
|
||||
//FontManager.subpixelRenderingMode = SubpixelRenderingMode.BGR; //SubpixelRenderingMode.None; //
|
||||
//}
|
||||
|
||||
// create window
|
||||
//Window window = Platform.instance.createWindow("DlangUI Example 1", null, WindowFlag.Resizable, 800, 700);
|
||||
// Expand window size if content is bigger than 800, 700 (change to above version if you want scrollbars and 800, 700 size)
|
||||
Window window = Platform.instance.createWindow("DlangUI Example 1", null, WindowFlag.Resizable | WindowFlag.ExpandSize, 800, 700);
|
||||
// here you can see window or content resize mode
|
||||
//Window window = Platform.instance.createWindow("DlangUI Example 1", null, WindowFlag.Resizable, 400, 400);
|
||||
//window.windowOrContentResizeMode = WindowOrContentResizeMode.resizeWindow;
|
||||
//window.windowOrContentResizeMode = WindowOrContentResizeMode.scrollWindow;
|
||||
//window.windowOrContentResizeMode = WindowOrContentResizeMode.shrinkWidgets;
|
||||
static if (true) {
|
||||
VerticalLayout contentLayout = new VerticalLayout();
|
||||
|
||||
TabWidget tabs = new TabWidget("TABS");
|
||||
tabs.tabClose = delegate(string tabId) {
|
||||
tabs.removeTab(tabId);
|
||||
};
|
||||
|
||||
//=========================================================================
|
||||
// create main menu
|
||||
|
||||
MenuItem mainMenuItems = new MenuItem();
|
||||
MenuItem fileItem = new MenuItem(new Action(1, "MENU_FILE"c));
|
||||
fileItem.add(new Action(ACTION_FILE_OPEN, "MENU_FILE_OPEN"c, "document-open", KeyCode.KEY_O, KeyFlag.Control));
|
||||
|
@ -219,7 +125,92 @@ extern (C) int UIAppMain(string[] args)
|
|||
mainMenuItems.add(viewItem);
|
||||
mainMenuItems.add(windowItem);
|
||||
mainMenuItems.add(helpItem);
|
||||
MainMenu mainMenu = new MainMenu(mainMenuItems);
|
||||
return mainMenuItems;
|
||||
}
|
||||
|
||||
/// entry point for dlangui based application
|
||||
extern (C) int UIAppMain(string[] args)
|
||||
{
|
||||
// always use trace, even for release builds
|
||||
//Log.setLogLevel(LogLevel.Trace);
|
||||
//Log.setFileLogger(new std.stdio.File("ui.log", "w"));
|
||||
|
||||
// resource directory search paths
|
||||
// not required if only embedded resources are used
|
||||
//string[] resourceDirs = [
|
||||
// appendPath(exePath, "../../../res/"), // for Visual D and DUB builds
|
||||
// appendPath(exePath, "../../../res/mdpi/"), // for Visual D and DUB builds
|
||||
// appendPath(exePath, "../../../../res/"),// for Mono-D builds
|
||||
// appendPath(exePath, "../../../../res/mdpi/"),// for Mono-D builds
|
||||
// appendPath(exePath, "res/"), // when res dir is located at the same directory as executable
|
||||
// appendPath(exePath, "../res/"), // when res dir is located at project directory
|
||||
// appendPath(exePath, "../../res/"), // when res dir is located at the same directory as executable
|
||||
// appendPath(exePath, "res/mdpi/"), // when res dir is located at the same directory as executable
|
||||
// appendPath(exePath, "../res/mdpi/"), // when res dir is located at project directory
|
||||
// appendPath(exePath, "../../res/mdpi/") // when res dir is located at the same directory as executable
|
||||
//];
|
||||
// setup resource directories - will use only existing directories
|
||||
//Platform.instance.resourceDirs = resourceDirs;
|
||||
|
||||
// embed resources listed in views/resources.list into executable
|
||||
embeddedResourceList.addResources(embedResourcesFromList!("resources.list")());
|
||||
|
||||
//version (USE_OPENGL) {
|
||||
// // you can turn on subpixel font rendering (ClearType) here
|
||||
//FontManager.subpixelRenderingMode = SubpixelRenderingMode.None; //
|
||||
//} else {
|
||||
// you can turn on subpixel font rendering (ClearType) here
|
||||
FontManager.subpixelRenderingMode = SubpixelRenderingMode.BGR; //SubpixelRenderingMode.None; //
|
||||
//}
|
||||
|
||||
// select translation file - for english language
|
||||
Platform.instance.uiLanguage = "en";
|
||||
// load theme from file "theme_default.xml"
|
||||
Platform.instance.uiTheme = "theme_default";
|
||||
//Platform.instance.uiTheme = "theme_dark";
|
||||
|
||||
// you can override default hinting mode here (Normal, AutoHint, Disabled)
|
||||
FontManager.hintingMode = HintingMode.Normal;
|
||||
// you can override antialiasing setting here (0 means antialiasing always on, some big value = always off)
|
||||
// fonts with size less than specified value will not be antialiased
|
||||
FontManager.minAnitialiasedFontSize = 0; // 0 means always antialiased
|
||||
//version (USE_OPENGL) {
|
||||
// // you can turn on subpixel font rendering (ClearType) here
|
||||
FontManager.subpixelRenderingMode = SubpixelRenderingMode.None; //
|
||||
//} else {
|
||||
// you can turn on subpixel font rendering (ClearType) here
|
||||
//FontManager.subpixelRenderingMode = SubpixelRenderingMode.BGR; //SubpixelRenderingMode.None; //
|
||||
//}
|
||||
|
||||
// create window
|
||||
//Window window = Platform.instance.createWindow("DlangUI Example 1", null, WindowFlag.Resizable, 800, 700);
|
||||
// Expand window size if content is bigger than 800, 700 (change to above version if you want scrollbars and 800, 700 size)
|
||||
Window window = Platform.instance.createWindow("DlangUI Example 1", null, WindowFlag.Resizable | WindowFlag.ExpandSize, 800, 700);
|
||||
// here you can see window or content resize mode
|
||||
//Window window = Platform.instance.createWindow("DlangUI Example 1", null, WindowFlag.Resizable, 400, 400);
|
||||
//window.windowOrContentResizeMode = WindowOrContentResizeMode.resizeWindow;
|
||||
//window.windowOrContentResizeMode = WindowOrContentResizeMode.scrollWindow;
|
||||
//window.windowOrContentResizeMode = WindowOrContentResizeMode.shrinkWidgets;
|
||||
|
||||
VerticalLayout contentLayout = new VerticalLayout();
|
||||
|
||||
TabWidget tabs = new TabWidget("TABS");
|
||||
tabs.tabClose = delegate(string tabId) {
|
||||
tabs.removeTab(tabId);
|
||||
};
|
||||
|
||||
//=========================================================================
|
||||
// create main menu
|
||||
|
||||
MainMenu mainMenu = new MainMenu(constructMainMenu());
|
||||
mainMenu.menuItemClick = delegate(MenuItem item) {
|
||||
Log.d("mainMenu.onMenuItemListener", item.label);
|
||||
const Action a = item.action;
|
||||
if (a) {
|
||||
return contentLayout.dispatchAction(a);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
contentLayout.addChild(mainMenu);
|
||||
// to let main menu handle keyboard shortcuts
|
||||
contentLayout.keyToAction = delegate(Widget source, uint keyCode, uint flags) {
|
||||
|
@ -288,243 +279,25 @@ extern (C) int UIAppMain(string[] args)
|
|||
//return contentLayout.dispatchAction(a);
|
||||
return false;
|
||||
};
|
||||
mainMenu.menuItemClick = delegate(MenuItem item) {
|
||||
Log.d("mainMenu.onMenuItemListener", item.label);
|
||||
const Action a = item.action;
|
||||
if (a) {
|
||||
return contentLayout.dispatchAction(a);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
// ========= create tabs ===================
|
||||
|
||||
tabs.tabChanged = delegate(string newTabId, string oldTabId) {
|
||||
// Setup tab view
|
||||
tabs.tabChanged = delegate(string newTabId, string oldTabId)
|
||||
{
|
||||
window.windowCaption = tabs.tab(newTabId).text.value ~ " - dlangui example 1"d;
|
||||
};
|
||||
tabs.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
||||
|
||||
// most of controls example
|
||||
|
||||
// Add all the example tabs
|
||||
tabs.addTab(new BasicControls("controls"), "Controls"d);
|
||||
tabs.addTab(new MiscExample("tab1"), "Misc"d);
|
||||
tabs.addTab(new LongListsExample("tab2"), "TAB_LONG_LIST"c);
|
||||
tabs.addTab(new ButtonsExample("tab3"), "TAB_BUTTONS"c);
|
||||
|
||||
TableLayout table = new TableLayout("TABLE");
|
||||
table.colCount = 2;
|
||||
// headers
|
||||
table.addChild((new TextWidget(null, "Parameter Name"d)).alignment(Align.Right | Align.VCenter));
|
||||
table.addChild((new TextWidget(null, "Edit Box to edit parameter"d)).alignment(Align.Left | Align.VCenter));
|
||||
// row 1
|
||||
table.addChild((new TextWidget(null, "Parameter 1 name"d)).alignment(Align.Right | Align.VCenter));
|
||||
table.addChild((new EditLine("edit1", "Text 1"d)).layoutWidth(FILL_PARENT));
|
||||
// row 2
|
||||
table.addChild((new TextWidget(null, "Parameter 2 name bla bla"d)).alignment(Align.Right | Align.VCenter));
|
||||
table.addChild((new EditLine("edit2", "Some text for parameter 2"d)).layoutWidth(FILL_PARENT));
|
||||
// row 3
|
||||
table.addChild((new TextWidget(null, "Param 3 is disabled"d)).alignment(Align.Right | Align.VCenter).enabled(false));
|
||||
table.addChild((new EditLine("edit3", "Parameter 3 value"d)).layoutWidth(FILL_PARENT).enabled(false));
|
||||
// normal readonly combo box
|
||||
ComboBox combo1 = new ComboBox("combo1", ["item value 1"d, "item value 2"d, "item value 3"d, "item value 4"d, "item value 5"d, "item value 6"d]);
|
||||
table.addChild((new TextWidget(null, "Combo box param"d)).alignment(Align.Right | Align.VCenter));
|
||||
combo1.selectedItemIndex = 3;
|
||||
table.addChild(combo1).layoutWidth(FILL_PARENT);
|
||||
// disabled readonly combo box
|
||||
ComboBox combo2 = new ComboBox("combo2", ["item value 1"d, "item value 2"d, "item value 3"d]);
|
||||
table.addChild((new TextWidget(null, "Disabled combo box"d)).alignment(Align.Right | Align.VCenter));
|
||||
combo2.enabled = false;
|
||||
combo2.selectedItemIndex = 0;
|
||||
table.addChild(combo2).layoutWidth(FILL_PARENT);
|
||||
|
||||
table.margins(Rect(2,2,2,2)).layoutWidth(FILL_PARENT);
|
||||
tabs.addTab(table, "TAB_TABLE_LAYOUT"c);
|
||||
|
||||
//tabs.addTab((new TextWidget()).id("tab5").textColor(0x00802000).text("Tab 5 contents"), "Tab 5"d);
|
||||
|
||||
//==========================================================================
|
||||
// create Editors test tab
|
||||
VerticalLayout editors = new VerticalLayout("editors");
|
||||
|
||||
// EditLine sample
|
||||
editors.addChild(new TextWidget(null, "EditLine: Single line editor"d));
|
||||
EditLine editLine = new EditLine("editline1", "Single line editor sample text");
|
||||
editors.addChild(createEditorSettingsControl(editLine));
|
||||
editors.addChild(editLine);
|
||||
//editLine.popupMenu = editPopupItem;
|
||||
|
||||
// EditBox sample
|
||||
editors.addChild(new TextWidget(null, "SourceEdit: multiline editor, for source code editing"d));
|
||||
|
||||
SourceEdit editBox = new SourceEdit("editbox1");
|
||||
editBox.text = q{#!/usr/bin/env rdmd
|
||||
// Computes average line length for standard input.
|
||||
import std.stdio;
|
||||
|
||||
void main()
|
||||
{
|
||||
ulong lines = 0;
|
||||
double sumLength = 0;
|
||||
foreach (line; stdin.byLine())
|
||||
{
|
||||
++lines;
|
||||
sumLength += line.length;
|
||||
}
|
||||
writeln("Average line length: ",
|
||||
lines ? sumLength / lines : 0);
|
||||
}
|
||||
}d;
|
||||
editors.addChild(createEditorSettingsControl(editBox));
|
||||
editors.addChild(editBox);
|
||||
//editBox.popupMenu = editPopupItem;
|
||||
|
||||
editors.addChild(new TextWidget(null, "EditBox: additional view for the same content (split view testing)"d));
|
||||
SourceEdit editBox2 = new SourceEdit("editbox2");
|
||||
editBox2.content = editBox.content; // view the same content as first editbox
|
||||
editors.addChild(editBox2);
|
||||
editors.layoutHeight(FILL_PARENT).layoutWidth(FILL_PARENT);
|
||||
|
||||
tabs.addTab(editors, "TAB_EDITORS"c);
|
||||
|
||||
//==========================================================================
|
||||
|
||||
VerticalLayout gridContent = new VerticalLayout("GRID_CONTENT");
|
||||
gridContent.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
||||
HorizontalLayout gridSettings = new HorizontalLayout();
|
||||
StringGridWidget grid = new StringGridWidget("GRID1");
|
||||
|
||||
gridSettings.addChild((new CheckBox("fullColumnOnLeft", "fullColumnOnLeft"d)).checked(grid.fullColumnOnLeft).tooltipText("Extends scroll area to show full column at left when scrolled to rightmost column"d).addOnCheckChangeListener(delegate(Widget, bool checked) { grid.fullColumnOnLeft = checked; return true;}));
|
||||
gridSettings.addChild((new CheckBox("fullRowOnTop", "fullRowOnTop"d)).checked(grid.fullRowOnTop).tooltipText("Extends scroll area to show full row at top when scrolled to end row"d).addOnCheckChangeListener(delegate(Widget, bool checked) { grid.fullRowOnTop = checked; return true;}));
|
||||
gridContent.addChild(gridSettings);
|
||||
|
||||
grid.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
||||
grid.showColHeaders = true;
|
||||
grid.showRowHeaders = true;
|
||||
grid.resize(30, 50);
|
||||
grid.fixedCols = 3;
|
||||
grid.fixedRows = 2;
|
||||
//grid.rowSelect = true; // testing full row selection
|
||||
grid.multiSelect = true;
|
||||
grid.selectCell(4, 6, false);
|
||||
// create sample grid content
|
||||
for (int y = 0; y < grid.rows; y++) {
|
||||
for (int x = 0; x < grid.cols; x++) {
|
||||
grid.setCellText(x, y, "cell("d ~ to!dstring(x + 1) ~ ","d ~ to!dstring(y + 1) ~ ")"d);
|
||||
}
|
||||
grid.setRowTitle(y, to!dstring(y + 1));
|
||||
}
|
||||
for (int x = 0; x < grid.cols; x++) {
|
||||
int col = x + 1;
|
||||
dstring res;
|
||||
int n1 = col / 26;
|
||||
int n2 = col % 26;
|
||||
if (n1)
|
||||
res ~= n1 + 'A';
|
||||
res ~= n2 + 'A';
|
||||
grid.setColTitle(x, res);
|
||||
}
|
||||
grid.autoFit();
|
||||
gridContent.addChild(grid);
|
||||
tabs.addTab(gridContent, "Grid"d);
|
||||
|
||||
//==========================================================================
|
||||
// Scroll view example
|
||||
ScrollWidget scroll = new ScrollWidget("SCROLL1");
|
||||
scroll.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
||||
WidgetGroup scrollContent = new VerticalLayout("CONTENT");
|
||||
scrollContent.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
||||
|
||||
TableLayout table2 = new TableLayout("TABLE2");
|
||||
table2.colCount = 2;
|
||||
// headers
|
||||
table2.addChild((new TextWidget(null, "Parameter Name"d)).alignment(Align.Right | Align.VCenter));
|
||||
table2.addChild((new TextWidget(null, "Edit Box to edit parameter"d)).alignment(Align.Left | Align.VCenter));
|
||||
// row 1
|
||||
table2.addChild((new TextWidget(null, "Parameter 1 name"d)).alignment(Align.Right | Align.VCenter));
|
||||
table2.addChild((new EditLine("edit1", "Text 1"d)).layoutWidth(FILL_PARENT));
|
||||
// row 2
|
||||
table2.addChild((new TextWidget(null, "Parameter 2 name bla bla"d)).alignment(Align.Right | Align.VCenter));
|
||||
table2.addChild((new EditLine("edit2", "Some text for parameter 2 blah blah blah"d)).layoutWidth(FILL_PARENT));
|
||||
// row 3
|
||||
table2.addChild((new TextWidget(null, "Param 3"d)).alignment(Align.Right | Align.VCenter));
|
||||
table2.addChild((new EditLine("edit3", "Parameter 3 value"d)).layoutWidth(FILL_PARENT));
|
||||
// row 4
|
||||
table2.addChild((new TextWidget(null, "Param 4"d)).alignment(Align.Right | Align.VCenter));
|
||||
table2.addChild((new EditLine("edit3", "Parameter 4 value shdjksdfh hsjdfas hdjkf hdjsfk ah"d)).layoutWidth(FILL_PARENT));
|
||||
// row 5
|
||||
table2.addChild((new TextWidget(null, "Param 5 - edit text here - blah blah blah"d)).alignment(Align.Right | Align.VCenter));
|
||||
table2.addChild((new EditLine("edit3", "Parameter 5 value"d)).layoutWidth(FILL_PARENT));
|
||||
// row 6
|
||||
table2.addChild((new TextWidget(null, "Param 6 - just to fill content widget (DISABLED)"d)).alignment(Align.Right | Align.VCenter).enabled(false));
|
||||
table2.addChild((new EditLine("edit3", "Parameter 5 value"d)).layoutWidth(FILL_PARENT).enabled(false));
|
||||
// row 7
|
||||
table2.addChild((new TextWidget(null, "Param 7 - just to fill content widget (DISABLED)"d)).alignment(Align.Right | Align.VCenter).enabled(false));
|
||||
table2.addChild((new EditLine("edit3", "Parameter 5 value"d)).layoutWidth(FILL_PARENT).enabled(false));
|
||||
// row 8
|
||||
table2.addChild((new TextWidget(null, "Param 8 - just to fill content widget"d)).alignment(Align.Right | Align.VCenter));
|
||||
table2.addChild((new EditLine("edit3", "Parameter 5 value"d)).layoutWidth(FILL_PARENT));
|
||||
table2.margins(Rect(10,10,10,10)).layoutWidth(FILL_PARENT);
|
||||
scrollContent.addChild(table2);
|
||||
|
||||
scrollContent.addChild(new TextWidget(null, "Now - some buttons"d));
|
||||
scrollContent.addChild(new ImageTextButton("btn1", "fileclose", "Close"d));
|
||||
scrollContent.addChild(new ImageTextButton("btn2", "fileopen", "Open"d));
|
||||
scrollContent.addChild(new TextWidget(null, "And checkboxes"d));
|
||||
scrollContent.addChild(new CheckBox("btn1", "CheckBox 1"d));
|
||||
scrollContent.addChild(new CheckBox("btn2", "CheckBox 2"d));
|
||||
|
||||
scroll.contentWidget = scrollContent;
|
||||
tabs.addTab(scroll, "Scroll"d);
|
||||
//==========================================================================
|
||||
// tree view example
|
||||
TreeWidget tree = new TreeWidget("TREE1");
|
||||
tree.layoutWidth(WRAP_CONTENT).layoutHeight(FILL_PARENT);
|
||||
TreeItem tree1 = tree.items.newChild("group1", "Group 1"d, "document-open");
|
||||
tree1.newChild("g1_1", "Group 1 item 1"d);
|
||||
tree1.newChild("g1_2", "Group 1 item 2"d);
|
||||
tree1.newChild("g1_3", "Group 1 item 3"d);
|
||||
TreeItem tree2 = tree.items.newChild("group2", "Group 2"d, "document-save");
|
||||
tree2.newChild("g2_1", "Group 2 item 1"d, "edit-copy");
|
||||
tree2.newChild("g2_2", "Group 2 item 2"d, "edit-cut");
|
||||
tree2.newChild("g2_3", "Group 2 item 3"d, "edit-paste");
|
||||
tree2.newChild("g2_4", "Group 2 item 4"d);
|
||||
TreeItem tree3 = tree.items.newChild("group3", "Group 3"d);
|
||||
tree3.newChild("g3_1", "Group 3 item 1"d);
|
||||
tree3.newChild("g3_2", "Group 3 item 2"d);
|
||||
TreeItem tree32 = tree3.newChild("g3_3", "Group 3 item 3"d);
|
||||
tree3.newChild("g3_4", "Group 3 item 4"d);
|
||||
tree32.newChild("group3_2_1", "Group 3 item 2 subitem 1"d);
|
||||
tree32.newChild("group3_2_2", "Group 3 item 2 subitem 2"d);
|
||||
tree32.newChild("group3_2_3", "Group 3 item 2 subitem 3"d);
|
||||
tree32.newChild("group3_2_4", "Group 3 item 2 subitem 4"d);
|
||||
tree32.newChild("group3_2_5", "Group 3 item 2 subitem 5"d);
|
||||
tree3.newChild("g3_5", "Group 3 item 5"d);
|
||||
tree3.newChild("g3_6", "Group 3 item 6"d);
|
||||
|
||||
LinearLayout treeLayout = new HorizontalLayout("TREE");
|
||||
LinearLayout treeControlledPanel = new VerticalLayout();
|
||||
treeLayout.layoutWidth = FILL_PARENT;
|
||||
treeControlledPanel.layoutWidth = FILL_PARENT;
|
||||
treeControlledPanel.layoutHeight = FILL_PARENT;
|
||||
TextWidget treeItemLabel = new TextWidget("TREE_ITEM_DESC");
|
||||
treeItemLabel.layoutWidth = FILL_PARENT;
|
||||
treeItemLabel.layoutHeight = FILL_PARENT;
|
||||
treeItemLabel.alignment = Align.Center;
|
||||
treeItemLabel.text = "Sample text"d;
|
||||
treeControlledPanel.addChild(treeItemLabel);
|
||||
treeLayout.addChild(tree);
|
||||
treeLayout.addChild(new ResizerWidget());
|
||||
treeLayout.addChild(treeControlledPanel);
|
||||
|
||||
tree.selectionChange = delegate(TreeItems source, TreeItem selectedItem, bool activated) {
|
||||
dstring label = "Selected item: "d ~ toUTF32(selectedItem.id) ~ (activated ? " selected + activated"d : " selected"d);
|
||||
treeItemLabel.text = label;
|
||||
};
|
||||
|
||||
tree.items.selectItem(tree.items.child(0));
|
||||
|
||||
tabs.addTab(treeLayout, "Tree"d);
|
||||
|
||||
tabs.addTab(new TableExample("TABLE"), "TAB_TABLE_LAYOUT"c);
|
||||
tabs.addTab(new EditorsExample("EDITORS"), "TAB_EDITORS"c);
|
||||
tabs.addTab(new GridExample("GRID_CONTENT"), "Grid"d);
|
||||
tabs.addTab(new ScrollExample("SCROLL1"), "Scroll"d);
|
||||
tabs.addTab(new TreeExample("TREE"), "Tree"d);
|
||||
tabs.addTab(new ChartsExample("charts"), "Charts"d);
|
||||
tabs.addTab((new SampleAnimationWidget("tab6")).layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT), "TAB_ANIMATION"c);
|
||||
tabs.addTab(new CanvasExample("canvas"), UIString.fromId("TAB_CANVAS"));
|
||||
|
@ -541,9 +314,7 @@ void main()
|
|||
window.mainWidget = contentLayout;
|
||||
|
||||
tabs.selectTab("controls");
|
||||
} else {
|
||||
window.mainWidget = (new Button()).text("sample button");
|
||||
}
|
||||
|
||||
static if (BACKEND_GUI) {
|
||||
window.windowIcon = drawableCache.getImage("dlangui-logo1");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
module widgets.editors;
|
||||
|
||||
import dlangui;
|
||||
|
||||
immutable testCode =
|
||||
`
|
||||
#!/usr/bin/env rdmd
|
||||
// Computes average line length for standard input.
|
||||
import std.stdio;
|
||||
|
||||
void main()
|
||||
{
|
||||
ulong lines = 0;
|
||||
double sumLength = 0;
|
||||
foreach (line; stdin.byLine())
|
||||
{
|
||||
++lines;
|
||||
sumLength += line.length;
|
||||
}
|
||||
writeln("Average line length: ",
|
||||
lines ? sumLength / lines : 0);
|
||||
}
|
||||
`;
|
||||
|
||||
Widget createEditorSettingsControl(EditWidgetBase editor) {
|
||||
HorizontalLayout res = new HorizontalLayout("editor_options");
|
||||
res.addChild((new CheckBox("wantTabs", "wantTabs"d)).checked(editor.wantTabs).addOnCheckChangeListener(delegate(Widget, bool checked) { editor.wantTabs = checked; return true;}));
|
||||
res.addChild((new CheckBox("useSpacesForTabs", "useSpacesForTabs"d)).checked(editor.useSpacesForTabs).addOnCheckChangeListener(delegate(Widget, bool checked) { editor.useSpacesForTabs = checked; return true;}));
|
||||
res.addChild((new CheckBox("readOnly", "readOnly"d)).checked(editor.readOnly).addOnCheckChangeListener(delegate(Widget, bool checked) { editor.readOnly = checked; return true;}));
|
||||
res.addChild((new CheckBox("showLineNumbers", "showLineNumbers"d)).checked(editor.showLineNumbers).addOnCheckChangeListener(delegate(Widget, bool checked) { editor.showLineNumbers = checked; return true;}));
|
||||
res.addChild((new CheckBox("fixedFont", "fixedFont"d)).checked(editor.fontFamily == FontFamily.MonoSpace).addOnCheckChangeListener(delegate(Widget, bool checked) {
|
||||
if (checked)
|
||||
editor.fontFamily(FontFamily.MonoSpace).fontFace("Courier New");
|
||||
else
|
||||
editor.fontFamily(FontFamily.SansSerif).fontFace("Arial");
|
||||
return true;
|
||||
}));
|
||||
res.addChild((new CheckBox("tabSize", "Tab size 8"d)).checked(editor.tabSize == 8).addOnCheckChangeListener(delegate(Widget, bool checked) {
|
||||
if (checked)
|
||||
editor.tabSize(8);
|
||||
else
|
||||
editor.tabSize(4);
|
||||
return true;
|
||||
}));
|
||||
return res;
|
||||
}
|
||||
|
||||
class EditorsExample : VerticalLayout
|
||||
{
|
||||
this(string ID)
|
||||
{
|
||||
super(ID);
|
||||
|
||||
// EditLine sample
|
||||
addChild(new TextWidget(null, "EditLine: Single line editor"d));
|
||||
EditLine editLine = new EditLine("editline1", "Single line editor sample text");
|
||||
addChild(createEditorSettingsControl(editLine));
|
||||
addChild(editLine);
|
||||
|
||||
// EditBox sample
|
||||
addChild(new TextWidget(null, "SourceEdit: multiline editor, for source code editing"d));
|
||||
|
||||
SourceEdit editBox = new SourceEdit("editbox1");
|
||||
editBox.text = UIString.fromRaw(testCode);
|
||||
addChild(createEditorSettingsControl(editBox));
|
||||
addChild(editBox);
|
||||
|
||||
addChild(new TextWidget(null, "EditBox: additional view for the same content (split view testing)"d));
|
||||
SourceEdit editBox2 = new SourceEdit("editbox2");
|
||||
editBox2.content = editBox.content; // view the same content as first editbox
|
||||
addChild(editBox2);
|
||||
layoutHeight(FILL_PARENT).layoutWidth(FILL_PARENT);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
module widgets.grid;
|
||||
|
||||
import dlangui;
|
||||
|
||||
class GridExample : VerticalLayout
|
||||
{
|
||||
this(string ID)
|
||||
{
|
||||
super(ID);
|
||||
layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
||||
HorizontalLayout gridSettings = new HorizontalLayout();
|
||||
StringGridWidget grid = new StringGridWidget("GRID1");
|
||||
|
||||
gridSettings.addChild((new CheckBox("fullColumnOnLeft", "fullColumnOnLeft"d)).checked(grid.fullColumnOnLeft).tooltipText("Extends scroll area to show full column at left when scrolled to rightmost column"d).addOnCheckChangeListener(delegate(Widget, bool checked) { grid.fullColumnOnLeft = checked; return true;}));
|
||||
gridSettings.addChild((new CheckBox("fullRowOnTop", "fullRowOnTop"d)).checked(grid.fullRowOnTop).tooltipText("Extends scroll area to show full row at top when scrolled to end row"d).addOnCheckChangeListener(delegate(Widget, bool checked) { grid.fullRowOnTop = checked; return true;}));
|
||||
addChild(gridSettings);
|
||||
|
||||
grid.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
||||
grid.showColHeaders = true;
|
||||
grid.showRowHeaders = true;
|
||||
grid.resize(30, 50);
|
||||
grid.fixedCols = 3;
|
||||
grid.fixedRows = 2;
|
||||
//grid.rowSelect = true; // testing full row selection
|
||||
grid.multiSelect = true;
|
||||
grid.selectCell(4, 6, false);
|
||||
// create sample grid content
|
||||
for (int y = 0; y < grid.rows; y++) {
|
||||
for (int x = 0; x < grid.cols; x++) {
|
||||
grid.setCellText(x, y, "cell("d ~ to!dstring(x + 1) ~ ","d ~ to!dstring(y + 1) ~ ")"d);
|
||||
}
|
||||
grid.setRowTitle(y, to!dstring(y + 1));
|
||||
}
|
||||
for (int x = 0; x < grid.cols; x++) {
|
||||
int col = x + 1;
|
||||
dstring res;
|
||||
int n1 = col / 26;
|
||||
int n2 = col % 26;
|
||||
if (n1)
|
||||
res ~= n1 + 'A';
|
||||
res ~= n2 + 'A';
|
||||
grid.setColTitle(x, res);
|
||||
}
|
||||
grid.autoFit();
|
||||
addChild(grid);
|
||||
}
|
||||
}
|
|
@ -5,7 +5,12 @@ public import widgets.buttons;
|
|||
public import widgets.canvas;
|
||||
public import widgets.charts;
|
||||
public import widgets.controls;
|
||||
public import widgets.editors;
|
||||
public import widgets.grid;
|
||||
public import widgets.icons;
|
||||
public import widgets.longlists;
|
||||
public import widgets.misc;
|
||||
public import widgets.opengl;
|
||||
public import widgets.scroll;
|
||||
public import widgets.table;
|
||||
public import widgets.tree;
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
module widgets.scroll;
|
||||
|
||||
import dlangui;
|
||||
|
||||
class ScrollExample : ScrollWidget
|
||||
{
|
||||
this(string ID)
|
||||
{
|
||||
super(ID);
|
||||
|
||||
layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
||||
WidgetGroup scrollContent = new VerticalLayout("CONTENT");
|
||||
scrollContent.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
||||
|
||||
TableLayout table2 = new TableLayout("TABLE2");
|
||||
table2.colCount = 2;
|
||||
// headers
|
||||
table2.addChild((new TextWidget(null, "Parameter Name"d)).alignment(Align.Right | Align.VCenter));
|
||||
table2.addChild((new TextWidget(null, "Edit Box to edit parameter"d)).alignment(Align.Left | Align.VCenter));
|
||||
// row 1
|
||||
table2.addChild((new TextWidget(null, "Parameter 1 name"d)).alignment(Align.Right | Align.VCenter));
|
||||
table2.addChild((new EditLine("edit1", "Text 1"d)).layoutWidth(FILL_PARENT));
|
||||
// row 2
|
||||
table2.addChild((new TextWidget(null, "Parameter 2 name bla bla"d)).alignment(Align.Right | Align.VCenter));
|
||||
table2.addChild((new EditLine("edit2", "Some text for parameter 2 blah blah blah"d)).layoutWidth(FILL_PARENT));
|
||||
// row 3
|
||||
table2.addChild((new TextWidget(null, "Param 3"d)).alignment(Align.Right | Align.VCenter));
|
||||
table2.addChild((new EditLine("edit3", "Parameter 3 value"d)).layoutWidth(FILL_PARENT));
|
||||
// row 4
|
||||
table2.addChild((new TextWidget(null, "Param 4"d)).alignment(Align.Right | Align.VCenter));
|
||||
table2.addChild((new EditLine("edit3", "Parameter 4 value shdjksdfh hsjdfas hdjkf hdjsfk ah"d)).layoutWidth(FILL_PARENT));
|
||||
// row 5
|
||||
table2.addChild((new TextWidget(null, "Param 5 - edit text here - blah blah blah"d)).alignment(Align.Right | Align.VCenter));
|
||||
table2.addChild((new EditLine("edit3", "Parameter 5 value"d)).layoutWidth(FILL_PARENT));
|
||||
// row 6
|
||||
table2.addChild((new TextWidget(null, "Param 6 - just to fill content widget (DISABLED)"d)).alignment(Align.Right | Align.VCenter).enabled(false));
|
||||
table2.addChild((new EditLine("edit3", "Parameter 5 value"d)).layoutWidth(FILL_PARENT).enabled(false));
|
||||
// row 7
|
||||
table2.addChild((new TextWidget(null, "Param 7 - just to fill content widget (DISABLED)"d)).alignment(Align.Right | Align.VCenter).enabled(false));
|
||||
table2.addChild((new EditLine("edit3", "Parameter 5 value"d)).layoutWidth(FILL_PARENT).enabled(false));
|
||||
// row 8
|
||||
table2.addChild((new TextWidget(null, "Param 8 - just to fill content widget"d)).alignment(Align.Right | Align.VCenter));
|
||||
table2.addChild((new EditLine("edit3", "Parameter 5 value"d)).layoutWidth(FILL_PARENT));
|
||||
table2.margins(Rect(10,10,10,10)).layoutWidth(FILL_PARENT);
|
||||
scrollContent.addChild(table2);
|
||||
|
||||
scrollContent.addChild(new TextWidget(null, "Now - some buttons"d));
|
||||
scrollContent.addChild(new ImageTextButton("btn1", "fileclose", "Close"d));
|
||||
scrollContent.addChild(new ImageTextButton("btn2", "fileopen", "Open"d));
|
||||
scrollContent.addChild(new TextWidget(null, "And checkboxes"d));
|
||||
scrollContent.addChild(new CheckBox("btn1", "CheckBox 1"d));
|
||||
scrollContent.addChild(new CheckBox("btn2", "CheckBox 2"d));
|
||||
|
||||
contentWidget = scrollContent;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
module widgets.table;
|
||||
|
||||
import dlangui;
|
||||
|
||||
class TableExample : TableLayout
|
||||
{
|
||||
this(string ID)
|
||||
{
|
||||
super(ID);
|
||||
|
||||
colCount = 2;
|
||||
// headers
|
||||
addChild((new TextWidget(null, "Parameter Name"d)).alignment(Align.Right | Align.VCenter));
|
||||
addChild((new TextWidget(null, "Edit Box to edit parameter"d)).alignment(Align.Left | Align.VCenter));
|
||||
// row 1
|
||||
addChild((new TextWidget(null, "Parameter 1 name"d)).alignment(Align.Right | Align.VCenter));
|
||||
addChild((new EditLine("edit1", "Text 1"d)).layoutWidth(FILL_PARENT));
|
||||
// row 2
|
||||
addChild((new TextWidget(null, "Parameter 2 name bla bla"d)).alignment(Align.Right | Align.VCenter));
|
||||
addChild((new EditLine("edit2", "Some text for parameter 2"d)).layoutWidth(FILL_PARENT));
|
||||
// row 3
|
||||
addChild((new TextWidget(null, "Param 3 is disabled"d)).alignment(Align.Right | Align.VCenter).enabled(false));
|
||||
addChild((new EditLine("edit3", "Parameter 3 value"d)).layoutWidth(FILL_PARENT).enabled(false));
|
||||
// normal readonly combo box
|
||||
ComboBox combo1 = new ComboBox("combo1", ["item value 1"d, "item value 2"d, "item value 3"d, "item value 4"d, "item value 5"d, "item value 6"d]);
|
||||
addChild((new TextWidget(null, "Combo box param"d)).alignment(Align.Right | Align.VCenter));
|
||||
combo1.selectedItemIndex = 3;
|
||||
addChild(combo1).layoutWidth(FILL_PARENT);
|
||||
// disabled readonly combo box
|
||||
ComboBox combo2 = new ComboBox("combo2", ["item value 1"d, "item value 2"d, "item value 3"d]);
|
||||
addChild((new TextWidget(null, "Disabled combo box"d)).alignment(Align.Right | Align.VCenter));
|
||||
combo2.enabled = false;
|
||||
combo2.selectedItemIndex = 0;
|
||||
addChild(combo2).layoutWidth(FILL_PARENT);
|
||||
|
||||
margins(Rect(2,2,2,2)).layoutWidth(FILL_PARENT);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
module widgets.tree;
|
||||
|
||||
import dlangui;
|
||||
|
||||
class TreeExample : HorizontalLayout
|
||||
{
|
||||
this(string ID)
|
||||
{
|
||||
super(ID);
|
||||
|
||||
TreeWidget tree = new TreeWidget("TREE1");
|
||||
tree.layoutWidth(WRAP_CONTENT).layoutHeight(FILL_PARENT);
|
||||
TreeItem tree1 = tree.items.newChild("group1", "Group 1"d, "document-open");
|
||||
tree1.newChild("g1_1", "Group 1 item 1"d);
|
||||
tree1.newChild("g1_2", "Group 1 item 2"d);
|
||||
tree1.newChild("g1_3", "Group 1 item 3"d);
|
||||
TreeItem tree2 = tree.items.newChild("group2", "Group 2"d, "document-save");
|
||||
tree2.newChild("g2_1", "Group 2 item 1"d, "edit-copy");
|
||||
tree2.newChild("g2_2", "Group 2 item 2"d, "edit-cut");
|
||||
tree2.newChild("g2_3", "Group 2 item 3"d, "edit-paste");
|
||||
tree2.newChild("g2_4", "Group 2 item 4"d);
|
||||
TreeItem tree3 = tree.items.newChild("group3", "Group 3"d);
|
||||
tree3.newChild("g3_1", "Group 3 item 1"d);
|
||||
tree3.newChild("g3_2", "Group 3 item 2"d);
|
||||
TreeItem tree32 = tree3.newChild("g3_3", "Group 3 item 3"d);
|
||||
tree3.newChild("g3_4", "Group 3 item 4"d);
|
||||
tree32.newChild("group3_2_1", "Group 3 item 2 subitem 1"d);
|
||||
tree32.newChild("group3_2_2", "Group 3 item 2 subitem 2"d);
|
||||
tree32.newChild("group3_2_3", "Group 3 item 2 subitem 3"d);
|
||||
tree32.newChild("group3_2_4", "Group 3 item 2 subitem 4"d);
|
||||
tree32.newChild("group3_2_5", "Group 3 item 2 subitem 5"d);
|
||||
tree3.newChild("g3_5", "Group 3 item 5"d);
|
||||
tree3.newChild("g3_6", "Group 3 item 6"d);
|
||||
|
||||
LinearLayout treeControlledPanel = new VerticalLayout();
|
||||
layoutWidth = FILL_PARENT;
|
||||
treeControlledPanel.layoutWidth = FILL_PARENT;
|
||||
treeControlledPanel.layoutHeight = FILL_PARENT;
|
||||
TextWidget treeItemLabel = new TextWidget("TREE_ITEM_DESC");
|
||||
treeItemLabel.layoutWidth = FILL_PARENT;
|
||||
treeItemLabel.layoutHeight = FILL_PARENT;
|
||||
treeItemLabel.alignment = Align.Center;
|
||||
treeItemLabel.text = "Sample text"d;
|
||||
treeControlledPanel.addChild(treeItemLabel);
|
||||
addChild(tree);
|
||||
addChild(new ResizerWidget());
|
||||
addChild(treeControlledPanel);
|
||||
|
||||
tree.selectionChange = delegate(TreeItems source, TreeItem selectedItem, bool activated) {
|
||||
dstring label = "Selected item: "d ~ toUTF32(selectedItem.id) ~ (activated ? " selected + activated"d : " selected"d);
|
||||
treeItemLabel.text = label;
|
||||
};
|
||||
|
||||
tree.items.selectItem(tree.items.child(0));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue