From 0a7a5e55b4650836d2d01478d23da0c07955b1c0 Mon Sep 17 00:00:00 2001 From: Grim Maple Date: Fri, 23 Dec 2022 16:31:09 +0300 Subject: [PATCH] Example 1 refactoring part 2 --- examples/example1/src/example1.d | 550 +--------------------- examples/example1/src/widgets/buttons.d | 136 ++++++ examples/example1/src/widgets/controls.d | 189 ++++++++ examples/example1/src/widgets/longlists.d | 60 +++ examples/example1/src/widgets/misc.d | 117 +++++ examples/example1/src/widgets/package.d | 4 + 6 files changed, 515 insertions(+), 541 deletions(-) create mode 100644 examples/example1/src/widgets/buttons.d create mode 100644 examples/example1/src/widgets/controls.d create mode 100644 examples/example1/src/widgets/longlists.d create mode 100644 examples/example1/src/widgets/misc.d diff --git a/examples/example1/src/example1.d b/examples/example1/src/example1.d index 0340e3bc..e268e411 100644 --- a/examples/example1/src/example1.d +++ b/examples/example1/src/example1.d @@ -29,42 +29,6 @@ import widgets; mixin APP_ENTRY_POINT; -class TimerTest : HorizontalLayout { - ulong timerId; - TextWidget _counter; - int _value; - Button _start; - Button _stop; - override bool onTimer(ulong id) { - _value++; - _counter.text = to!dstring(_value); - return true; - } - this() { - addChild(new TextWidget(null, "Timer test."d)); - _counter = new TextWidget(null, "0"d); - _counter.fontSize(32); - _start = new Button(null, "Start timer"d); - _stop = new Button(null, "Stop timer"d); - _stop.enabled = false; - _start.click = delegate(Widget src) { - _start.enabled = false; - _stop.enabled = true; - timerId = setTimer(1000); - return true; - }; - _stop.click = delegate(Widget src) { - _start.enabled = true; - _stop.enabled = false; - cancelTimer(timerId); - return true; - }; - addChild(_start); - addChild(_stop); - addChild(_counter); - } -} - class TextEditorWidget : VerticalLayout { EditBox _edit; this(string ID) { @@ -99,38 +63,9 @@ Widget createEditorSettingsControl(EditWidgetBase editor) { return res; } -enum : int { - ACTION_FILE_OPEN = 5500, - ACTION_FILE_SAVE, - ACTION_FILE_CLOSE, - ACTION_FILE_EXIT, -} - -debug(SDLSettings) { - import dlangui.core.settings; - void testSDL(string fn) { - Log.d("Loading SDL from ", fn); - Setting s = new Setting(); - if (s.load(fn)) { - Log.d("JSON:\n", s.toJSON(true)); - } else { - Log.e("failed to read SDL from ", fn); - } - } - void testSDLSettings() { - testSDL(`C:\Users\vlopatin\AppData\Roaming\.dlangide\settings.json`); - testSDL("dub.json"); - testSDL("test1.sdl"); - } -} - /// entry point for dlangui based application -extern (C) int UIAppMain(string[] args) { - - debug(SDLSettings) { - testSDLSettings(); - } - +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")); @@ -176,7 +111,7 @@ extern (C) int UIAppMain(string[] args) { FontManager.minAnitialiasedFontSize = 0; // 0 means always antialiased //version (USE_OPENGL) { // // you can turn on subpixel font rendering (ClearType) here - FontManager.subpixelRenderingMode = SubpixelRenderingMode.None; // + FontManager.subpixelRenderingMode = SubpixelRenderingMode.None; // //} else { // you can turn on subpixel font rendering (ClearType) here //FontManager.subpixelRenderingMode = SubpixelRenderingMode.BGR; //SubpixelRenderingMode.None; // @@ -225,15 +160,6 @@ extern (C) int UIAppMain(string[] args) { editItem.add(new Action(EditorActions.Unindent, "MENU_EDIT_UNINDENT"c, "edit-unindent", KeyCode.TAB, KeyFlag.Control)); editItem.add(new Action(20, "MENU_EDIT_PREFERENCES")); - MenuItem editPopupItem = new MenuItem(null); - editPopupItem.add(new Action(EditorActions.Copy, "MENU_EDIT_COPY"c, "edit-copy", KeyCode.KEY_C, KeyFlag.Control)); - editPopupItem.add(new Action(EditorActions.Paste, "MENU_EDIT_PASTE"c, "edit-paste", KeyCode.KEY_V, KeyFlag.Control)); - editPopupItem.add(new Action(EditorActions.Cut, "MENU_EDIT_CUT"c, "edit-cut", KeyCode.KEY_X, KeyFlag.Control)); - editPopupItem.add(new Action(EditorActions.Undo, "MENU_EDIT_UNDO"c, "edit-undo", KeyCode.KEY_Z, KeyFlag.Control)); - editPopupItem.add(new Action(EditorActions.Redo, "MENU_EDIT_REDO"c, "edit-redo", KeyCode.KEY_Y, KeyFlag.Control)); - editPopupItem.add(new Action(EditorActions.Indent, "MENU_EDIT_INDENT"c, "edit-indent", KeyCode.TAB, 0)); - editPopupItem.add(new Action(EditorActions.Unindent, "MENU_EDIT_UNINDENT"c, "edit-unindent", KeyCode.TAB, KeyFlag.Control)); - MenuItem viewItem = new MenuItem(new Action(60, "MENU_VIEW")); MenuItem langItem = new MenuItem(new Action(61, "MENU_VIEW_LANGUAGE")); auto onLangChange = delegate (MenuItem item) { @@ -379,469 +305,11 @@ extern (C) int UIAppMain(string[] args) { tabs.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); // most of controls example - { - LinearLayout controls = new VerticalLayout("controls"); - controls.layoutHeight(FILL_PARENT); - controls.padding = Rect(12.pointsToPixels,12.pointsToPixels,12.pointsToPixels,12.pointsToPixels); - HorizontalLayout line1 = new HorizontalLayout(); - controls.addChild(line1); - - GroupBox gb = new GroupBox("checkboxes", "CheckBox"d); - gb.addChild(new CheckBox("cb1", "CheckBox 1"d)); - gb.addChild(new CheckBox("cb2", "CheckBox 2"d).checked(true)); - gb.addChild(new CheckBox("cb3", "CheckBox disabled"d).enabled(false)); - gb.addChild(new CheckBox("cb4", "CheckBox disabled"d).checked(true).enabled(false)); - line1.addChild(gb); - - GroupBox gb2 = new GroupBox("radiobuttons", "RadioButton"d); - gb2.addChild(new RadioButton("rb1", "RadioButton 1"d).checked(true)); - gb2.addChild(new RadioButton("rb2", "RadioButton 2"d)); - gb2.addChild(new RadioButton("rb3", "RadioButton disabled"d).enabled(false)); - line1.addChild(gb2); - - VerticalLayout col1 = new VerticalLayout(); - GroupBox gb3 = new GroupBox("textbuttons", "Button"d, Orientation.Horizontal); - gb3.addChild(new Button("tb1", "Button"d)); - gb3.addChild(new Button("tb2", "Button disabled"d).enabled(false)); - col1.addChild(gb3); - GroupBox gb4 = new GroupBox("imagetextbuttons", "ImageTextButton"d, Orientation.Horizontal); - gb4.addChild(new ImageTextButton("itb1", "document-open", "Enabled"d)); - gb4.addChild(new ImageTextButton("itb2", "document-save", "Disabled"d).enabled(false)); - col1.addChild(gb4); - GroupBox gbtext = new GroupBox("text", "TextWidget"d, Orientation.Horizontal); - gbtext.addChild(new TextWidget("t1", "Red text"d).fontSize(12.pointsToPixels).textColor(0xFF0000)); - gbtext.addChild(new TextWidget("t2", "Italic text"d).fontSize(12.pointsToPixels).fontItalic(true)); - col1.addChild(gbtext); - line1.addChild(col1); - - VerticalLayout col2 = new VerticalLayout(); - GroupBox gb31 = new GroupBox("switches", "SwitchButton"d, Orientation.Vertical); - gb31.addChild(new SwitchButton("sb1")); - gb31.addChild(new SwitchButton("sb2").checked(true)); - gb31.addChild(new SwitchButton("sb3").enabled(false)); - gb31.addChild(new SwitchButton("sb4").enabled(false).checked(true)); - col2.addChild(gb31); - line1.addChild(col2); - - VerticalLayout col3 = new VerticalLayout(); - GroupBox gb32 = new GroupBox("switches", "ImageButton"d, Orientation.Vertical); - gb32.addChild(new ImageButton("ib1", "edit-copy")); - gb32.addChild(new ImageButton("ib3", "edit-paste").enabled(false)); - col3.addChild(gb32); - GroupBox gb33 = new GroupBox("images", "ImageWidget"d, Orientation.Vertical); - gb33.addChild(new ImageWidget("cr3_logo", "cr3_logo")); - col3.addChild(gb33); - line1.addChild(col3); - - - HorizontalLayout line2 = new HorizontalLayout(); - controls.addChild(line2); - - GroupBox gb5 = new GroupBox("scrollbar", "horizontal ScrollBar"d); - gb5.addChild(new ScrollBar("sb1", Orientation.Horizontal)); - line2.addChild(gb5); - GroupBox gb6 = new GroupBox("slider", "horizontal SliderWidget"d); - gb6.addChild(new SliderWidget("sb2", Orientation.Horizontal)); - line2.addChild(gb6); - GroupBox gb7 = new GroupBox("editline1", "EditLine"d); - gb7.addChild(new EditLine("ed1", "Some text"d).minWidth(120.pointsToPixels)); - line2.addChild(gb7); - GroupBox gb8 = new GroupBox("editline2", "EditLine disabled"d); - gb8.addChild(new EditLine("ed2", "Some text"d).enabled(false).minWidth(120.pointsToPixels)); - line2.addChild(gb8); - - HorizontalLayout line3 = new HorizontalLayout(); - line3.layoutWidth(FILL_PARENT); - GroupBox gbeditbox = new GroupBox("editbox", "EditBox"d, Orientation.Horizontal); - gbeditbox.layoutWidth(FILL_PARENT); - EditBox ed1 = new EditBox("ed1", "Some text in EditBox\nOne more line\nYet another text line"); - ed1.layoutHeight(FILL_PARENT); - gbeditbox.addChild(ed1); - line3.addChild(gbeditbox); - GroupBox gbtabs = new GroupBox(null, "TabWidget"d); - gbtabs.layoutWidth(FILL_PARENT); - TabWidget tabs1 = new TabWidget("tabs1"); - tabs1.addTab(new TextWidget("tab1", "TextWidget on tab page\nTextWidgets can be\nMultiline"d).maxLines(3), "Tab 1"d); - tabs1.addTab(new ImageWidget("tab2", "dlangui-logo1"), "Tab 2"d); - tabs1.tabHost.backgroundColor = 0xE0E0E0; - tabs1.tabHost.padding = Rect(10.pointsToPixels, 10.pointsToPixels, 10.pointsToPixels, 10.pointsToPixels); - gbtabs.addChild(tabs1); - line3.addChild(gbtabs); - controls.addChild(line3); - - HorizontalLayout line4 = new HorizontalLayout(); - line4.layoutWidth(FILL_PARENT); - line4.layoutHeight(FILL_PARENT); - GroupBox gbgrid = new GroupBox("grid", "StringGridWidget"d, Orientation.Horizontal); - StringGridWidget grid = new StringGridWidget("stringgrid"); - grid.resize(12, 10); - gbgrid.layoutWidth(FILL_PARENT); - gbgrid.layoutHeight(FILL_PARENT); - grid.layoutWidth(FILL_PARENT); - grid.layoutHeight(FILL_PARENT); - foreach (index, month; ["January"d, "February"d, "March"d, "April"d, "May"d, "June"d, "July"d, "August"d, "September"d, "October"d, "November"d, "December"d]) - grid.setColTitle(cast(int)index, month); - for (int y = 0; y < 10; y++) - grid.setRowTitle(y, to!dstring(y+1)); - //grid.alignment = Align.Right; - grid.setColWidth(0, 30.pointsToPixels); - grid.autoFit(); - import std.random; - import std.string; - for (int x = 0; x < 12; x++) { - for (int y = 0; y < 10; y++) { - int n = uniform(0, 10000); - grid.setCellText(x, y, to!dstring("%.2f".format(n / 100.0))); - } - } - //grid.autoFit(); - gbgrid.addChild(grid); - line4.addChild(gbgrid); - - GroupBox gbtree = new GroupBox("tree", "TreeWidget"d, Orientation.Vertical); - auto tree = new TreeWidget("gbtree"); - //tree.layoutWidth(WRAP_CONTENT).layoutHeight(FILL_PARENT); - tree.maxHeight(200.pointsToPixels); - 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); - gbtree.addChild(tree); - tree.items.selectItem(tree1); - // test adding new tree items - HorizontalLayout newTreeItem = new HorizontalLayout(); - newTreeItem.layoutWidth = FILL_PARENT; - EditLine edNewTreeItem = new EditLine("newTreeItem", "new item"d); - edNewTreeItem.layoutWidth = FILL_PARENT; - Button btnAddItem = new Button("btnAddTreeItem", "Add"d); - Button btnRemoveItem = new Button("btnRemoveTreeItem", "Remove"d); - newTreeItem.addChild(edNewTreeItem); - newTreeItem.addChild(btnAddItem); - newTreeItem.addChild(btnRemoveItem); - btnAddItem.click = delegate(Widget source) { - import std.random; - dstring label = edNewTreeItem.text; - string id = "item%d".format(uniform(1000000, 9999999, rndGen)); - TreeItem item = tree.items.selectedItem; - if (item) { - Log.d("Creating new tree item ", id, " ", label); - TreeItem newItem = new TreeItem(id, label); - item.addChild(newItem); - } - return true; - }; - btnRemoveItem.click = delegate(Widget source) { - TreeItem item = tree.items.selectedItem; - if (item) { - Log.d("Removing tree item ", item.id, " ", item.text); - item.parent.removeChild(item); - } - return true; - }; - gbtree.addChild(newTreeItem); - line4.addChild(gbtree); - - controls.addChild(line4); - - tabs.addTab(controls, "Controls"d); - } - - LinearLayout layout = new LinearLayout("tab1"); - - - layout.addChild((new TextWidget()).textColor(0x00802000).text("Text widget 0")); - layout.addChild((new TextWidget()).textColor(0x40FF4000).text("Text widget")); - layout.addChild(new ProgressBarWidget().progress(300).animationInterval(50)); - layout.addChild(new ProgressBarWidget().progress(-1).animationInterval(50)); - layout.addChild((new Button("BTN1")).textResource("EXIT")); //.textColor(0x40FF4000) - layout.addChild(new TimerTest()); - - static if (true) { - - - LinearLayout hlayout = new HorizontalLayout(); - hlayout.layoutWidth(FILL_PARENT); - //hlayout.addChild((new Button()).text("<<")); //.textColor(0x40FF4000) - hlayout.addChild((new TextWidget()).text("Several").alignment(Align.Center)); - hlayout.addChild((new ImageWidget()).drawableId("btn_radio").padding(Rect(5,5,5,5)).alignment(Align.Center)); - hlayout.addChild((new TextWidget()).text("items").alignment(Align.Center)); - hlayout.addChild((new ImageWidget()).drawableId("btn_check").padding(Rect(5,5,5,5)).alignment(Align.Center)); - hlayout.addChild((new TextWidget()).text("in horizontal layout")); - hlayout.addChild((new ImageWidget()).drawableId("exit").padding(Rect(5,5,5,5)).alignment(Align.Center)); - hlayout.addChild((new EditLine("editline", "Some text to edit"d)).popupMenu(editPopupItem).alignment(Align.Center).layoutWidth(FILL_PARENT)); - hlayout.addChild((new EditLine("passwd", "Password"d)).passwordChar('*').popupMenu(editPopupItem).alignment(Align.Center).layoutWidth(FILL_PARENT)); - //hlayout.addChild((new Button()).text(">>")); //.textColor(0x40FF4000) - hlayout.backgroundColor = 0x8080C0; - layout.addChild(hlayout); - - LinearLayout vlayoutgroup = new HorizontalLayout(); - LinearLayout vlayout = new VerticalLayout(); - vlayout.addChild((new TextWidget()).text("VLayout line 1").textColor(0x40FF4000)); // - vlayout.addChild((new TextWidget()).text("VLayout line 2").textColor(0x40FF8000)); - vlayout.addChild((new TextWidget()).text("VLayout line 2").textColor(0x40008000)); - vlayout.addChild(new RadioButton("rb1", "Radio button 1"d)); - vlayout.addChild(new RadioButton("rb2", "Radio button 2"d)); - vlayout.addChild(new RadioButton("rb3", "Radio button 3"d)); - vlayout.layoutWidth(FILL_PARENT); - vlayoutgroup.addChild(vlayout); - vlayoutgroup.layoutWidth(FILL_PARENT); - ScrollBar vsb = new ScrollBar("vscroll", Orientation.Vertical); - vlayoutgroup.addChild(vsb); - layout.addChild(vlayoutgroup); - - ScrollBar sb = new ScrollBar("hscroll", Orientation.Horizontal); - layout.addChild(sb.layoutHeight(WRAP_CONTENT).layoutWidth(FILL_PARENT)); - - layout.addChild((new CheckBox("BTN2", "Some checkbox"d))); - layout.addChild((new TextWidget()).textColor(0x40FF4000).text("Text widget")); - layout.addChild((new ImageWidget()).drawableId("exit").padding(Rect(5,5,5,5))); - layout.addChild((new TextWidget()).textColor(0xFF4000).text("Text widget2").padding(Rect(5,5,5,5)).margins(Rect(5,5,5,5)).backgroundColor(0xA0A0A0)); - layout.addChild((new RadioButton("BTN3", "Some radio button"d))); - layout.addChild((new TextWidget(null, "Text widget3 with very long text"d)).textColor(0x004000)); - layout.addChild(new VSpacer()); // vertical spacer to fill extra space - - - Widget w = parseML(q{ - VerticalLayout { - id: vlayout - margins: Rect { left: 5; right: 3; top: 2; bottom: 4 } - padding: Rect { 5, 4, 3, 2 } // same as Rect { left: 5; top: 4; right: 3; bottom: 2 } - TextWidget { - /* this widget can be accessed via id myLabel1 - e.g. w.childById!TextWidget("myLabel1") - */ - id: myLabel1 - text: "Some text"; padding: 5 - enabled: false - } - TextWidget { - id: myLabel2 - text: SOME_TEXT_RESOURCE_ID; margins: 5 - enabled: true - } - } - }); - Log.d("id=", w.id, " text=", w.text, " padding=", w.padding, " margins=", w.margins, - " lbl1.text=", w.childById!TextWidget("myLabel1").text, - " lbl1.enabled=", w.childById!TextWidget("myLabel1").enabled, - " lbl2.text=", w.childById!TextWidget("myLabel2").text - ); - destroy(w); - - layout.childById("BTN1").click = delegate (Widget w) { - Log.d("onClick ", w.id); - //w.backgroundImageId = null; - //w.backgroundColor = 0xFF00FF; - w.textColor = 0xFF00FF; - w.styleId = STYLE_BUTTON_NOMARGINS; - return true; - }; - layout.childById("BTN2").click = delegate (Widget w) { Log.d("onClick ", w.id); return true; }; - layout.childById("BTN3").click = delegate (Widget w) { Log.d("onClick ", w.id); return true; }; - - } - - layout.layoutHeight(FILL_PARENT).layoutWidth(FILL_PARENT); - - tabs.addTab(layout, "Misc"d); - - static if (true) { - // two long lists - // left one is list with widgets as items - // right one is list with string list adapter - HorizontalLayout longLists = new HorizontalLayout("tab2"); - longLists.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); - - ListWidget list = new ListWidget("list1", Orientation.Vertical); - list.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); - - StringListAdapter stringList = new StringListAdapter(); - WidgetListAdapter listAdapter = new WidgetListAdapter(); - listAdapter.add((new TextWidget()).text("This is a list of widgets"d).styleId("LIST_ITEM")); - stringList.add("This is a list of strings from StringListAdapter"d); - stringList.add("If you type with your keyboard,"d); - stringList.add("then you can find the"d); - stringList.add("item in the list"d); - stringList.add("neat!"d); - for (int i = 1; i < 1000; i++) { - dstring label = "List item "d ~ to!dstring(i); - listAdapter.add((new TextWidget()).text("Widget list - "d ~ label).styleId("LIST_ITEM")); - stringList.add("Simple string - "d ~ label); - } - list.ownAdapter = listAdapter; - listAdapter.resetItemState(0, State.Enabled); - listAdapter.resetItemState(5, State.Enabled); - listAdapter.resetItemState(7, State.Enabled); - listAdapter.resetItemState(12, State.Enabled); - assert(list.itemEnabled(5) == false); - assert(list.itemEnabled(6) == true); - list.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); - list.selectItem(0); - - longLists.addChild(list); - - ListWidget list2 = new StringListWidget("list2"); - list2.ownAdapter = stringList; - list2.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); - list2.selectItem(0); - longLists.addChild(list2); - - VerticalLayout itemedit = new VerticalLayout(); - itemedit.addChild(new TextWidget(null, "New item text:"d)); - EditLine itemtext = new EditLine(null, "Text for new item"d); - itemedit.addChild(itemtext); - Button btn = new Button(null, "Add item"d); - itemedit.addChild(btn); - longLists.addChild(itemedit); - btn.click = delegate(Widget src) - { - stringList.add(itemtext.text); - listAdapter.add((new TextWidget()).text(itemtext.text).styleId("LIST_ITEM")); - return true; - }; - tabs.addTab(longLists, "TAB_LONG_LIST"c); - } - - { - LinearLayout layout3 = new VerticalLayout("tab3"); - // 3 types of buttons: Button, ImageButton, ImageTextButton - layout3.addChild(new TextWidget(null, "Buttons in HorizontalLayout"d)); - WidgetGroup buttons1 = new HorizontalLayout(); - buttons1.addChild(new TextWidget(null, "Button widgets: "d)); - buttons1.addChild((new Button("btn1", "Button"d)).tooltipText("Tooltip text for button"d)); - buttons1.addChild((new Button("btn2", "Disabled Button"d)).enabled(false)); - buttons1.addChild(new TextWidget(null, "ImageButton widgets: "d)); - buttons1.addChild(new ImageButton("btn3", "text-plain")); - buttons1.addChild(new TextWidget(null, "disabled: "d)); - buttons1.addChild((new ImageButton("btn4", "folder")).enabled(false)); - layout3.addChild(buttons1); - - WidgetGroup buttons10 = new HorizontalLayout(); - buttons10.addChild(new TextWidget(null, "ImageTextButton widgets: "d)); - buttons10.addChild(new ImageTextButton("btn5", "text-plain", "Enabled"d)); - buttons10.addChild((new ImageTextButton("btn6", "folder", "Disabled"d)).enabled(false)); - buttons10.addChild(new TextWidget(null, "SwitchButton widgets: "d)); - buttons10.addChild((new SwitchButton("SW1")).checked(true)); - buttons10.addChild((new SwitchButton("SW2")).checked(false)); - buttons10.addChild((new SwitchButton("SW3")).checked(true).enabled(false)); - buttons10.addChild((new SwitchButton("SW4")).checked(false).enabled(false)); - layout3.addChild(buttons10); - - WidgetGroup buttons11 = new HorizontalLayout(); - buttons11.addChild(new TextWidget(null, "Construct buttons by action (Button, ImageButton, ImageTextButton): "d)); - Action FILE_OPEN_ACTION = new Action(ACTION_FILE_OPEN, "MENU_FILE_OPEN"c, "document-open", KeyCode.KEY_O, KeyFlag.Control); - buttons11.addChild(new Button(FILE_OPEN_ACTION)); - buttons11.addChild(new ImageButton(FILE_OPEN_ACTION)); - buttons11.addChild(new ImageTextButton(FILE_OPEN_ACTION)); - layout3.addChild(buttons11); - - WidgetGroup buttons12 = new HorizontalLayout(); - buttons12.addChild(new TextWidget(null, "The same in disabled state: "d)); - buttons12.addChild((new Button(FILE_OPEN_ACTION)).enabled(false)); - buttons12.addChild((new ImageButton(FILE_OPEN_ACTION)).enabled(false)); - buttons12.addChild((new ImageTextButton(FILE_OPEN_ACTION)).enabled(false)); - layout3.addChild(buttons12); - - layout3.addChild(new VSpacer()); - layout3.addChild(new TextWidget(null, "CheckBoxes in HorizontalLayout"d)); - WidgetGroup buttons2 = new HorizontalLayout(); - buttons2.addChild(new CheckBox("btn1", "CheckBox 1"d)); - buttons2.addChild(new CheckBox("btn2", "CheckBox 2"d)); - //buttons2.addChild(new ResizerWidget()); - buttons2.addChild(new CheckBox("btn3", "CheckBox 3"d)); - buttons2.addChild(new CheckBox("btn4", "CheckBox 4"d)); - layout3.addChild(buttons2); - - layout3.addChild(new VSpacer()); - layout3.addChild(new TextWidget(null, "RadioButtons in HorizontalLayout"d)); - WidgetGroup buttons3 = new HorizontalLayout(); - buttons3.addChild(new RadioButton("btn1", "RadioButton 1"d)); - buttons3.addChild(new RadioButton("btn2", "RadioButton 2"d)); - buttons3.addChild(new RadioButton("btn3", "RadioButton 3"d)); - buttons3.addChild(new RadioButton("btn4", "RadioButton 4"d)); - layout3.addChild(buttons3); - - layout3.addChild(new VSpacer()); - layout3.addChild(new TextWidget(null, "ImageButtons HorizontalLayout"d)); - WidgetGroup buttons4 = new HorizontalLayout(); - buttons4.addChild(new ImageButton("btn1", "fileclose")); - buttons4.addChild(new ImageButton("btn2", "fileopen")); - buttons4.addChild(new ImageButton("btn3", "exit")); - layout3.addChild(buttons4); - - layout3.addChild(new VSpacer()); - layout3.addChild(new TextWidget(null, "In vertical layouts:"d)); - HorizontalLayout hlayout2 = new HorizontalLayout(); - hlayout2.layoutHeight(FILL_PARENT); //layoutWidth(FILL_PARENT). - - buttons1 = new VerticalLayout(); - buttons1.addChild(new TextWidget(null, "Buttons"d)); - buttons1.addChild(new Button("btn1", "Button 1"d)); - buttons1.addChild(new Button("btn2", "Button 2"d)); - buttons1.addChild((new Button("btn3", "Button 3 - disabled"d)).enabled(false)); - buttons1.addChild(new Button("btn4", "Button 4"d)); - hlayout2.addChild(buttons1); - hlayout2.addChild(new HSpacer()); - - buttons2 = new VerticalLayout(); - buttons2.addChild(new TextWidget(null, "CheckBoxes"d)); - buttons2.addChild(new CheckBox("btn1", "CheckBox 1"d)); - buttons2.addChild(new CheckBox("btn2", "CheckBox 2"d)); - buttons2.addChild(new CheckBox("btn3", "CheckBox 3"d)); - buttons2.addChild(new CheckBox("btn4", "CheckBox 4"d)); - hlayout2.addChild(buttons2); - hlayout2.addChild(new HSpacer()); - - buttons3 = new VerticalLayout(); - buttons3.addChild(new TextWidget(null, "RadioButtons"d)); - buttons3.addChild(new RadioButton("btn1", "RadioButton 1"d)); - buttons3.addChild(new RadioButton("btn2", "RadioButton 2"d)); - //buttons3.addChild(new ResizerWidget()); - buttons3.addChild(new RadioButton("btn3", "RadioButton 3"d)); - buttons3.addChild(new RadioButton("btn4", "RadioButton 4"d)); - hlayout2.addChild(buttons3); - hlayout2.addChild(new HSpacer()); - - buttons4 = new VerticalLayout(); - buttons4.addChild(new TextWidget(null, "ImageButtons"d)); - buttons4.addChild(new ImageButton("btn1", "fileclose")); - buttons4.addChild(new ImageButton("btn2", "fileopen")); - buttons4.addChild(new ImageButton("btn3", "exit")); - hlayout2.addChild(buttons4); - hlayout2.addChild(new HSpacer()); - - WidgetGroup buttons5 = new VerticalLayout(); - buttons5.addChild(new TextWidget(null, "ImageTextButtons"d)); - buttons5.addChild(new ImageTextButton("btn1", "fileclose", "Close"d)); - buttons5.addChild(new ImageTextButton("btn2", "fileopen", "Open"d)); - buttons5.addChild(new ImageTextButton("btn3", "exit", "Exit"d)); - hlayout2.addChild(buttons5); - - - layout3.addChild(hlayout2); - - layout3.addChild(new VSpacer()); - layout3.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); - tabs.addTab(layout3, "TAB_BUTTONS"c); - } + 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; @@ -883,7 +351,7 @@ extern (C) int UIAppMain(string[] args) { EditLine editLine = new EditLine("editline1", "Single line editor sample text"); editors.addChild(createEditorSettingsControl(editLine)); editors.addChild(editLine); - editLine.popupMenu = editPopupItem; + //editLine.popupMenu = editPopupItem; // EditBox sample editors.addChild(new TextWidget(null, "SourceEdit: multiline editor, for source code editing"d)); @@ -908,7 +376,7 @@ void main() }d; editors.addChild(createEditorSettingsControl(editBox)); editors.addChild(editBox); - editBox.popupMenu = editPopupItem; + //editBox.popupMenu = editPopupItem; editors.addChild(new TextWidget(null, "EditBox: additional view for the same content (split view testing)"d)); SourceEdit editBox2 = new SourceEdit("editbox2"); diff --git a/examples/example1/src/widgets/buttons.d b/examples/example1/src/widgets/buttons.d new file mode 100644 index 00000000..a9477e2d --- /dev/null +++ b/examples/example1/src/widgets/buttons.d @@ -0,0 +1,136 @@ +module widgets.buttons; + +import dlangui; + +enum : int { + ACTION_FILE_OPEN = 5500, + ACTION_FILE_SAVE, + ACTION_FILE_CLOSE, + ACTION_FILE_EXIT, +} + +class ButtonsExample : VerticalLayout +{ + this(string ID) + { + super(ID); + // 3 types of buttons: Button, ImageButton, ImageTextButton + addChild(new TextWidget(null, "Buttons in HorizontalLayout"d)); + WidgetGroup buttons1 = new HorizontalLayout(); + buttons1.addChild(new TextWidget(null, "Button widgets: "d)); + buttons1.addChild((new Button("btn1", "Button"d)).tooltipText("Tooltip text for button"d)); + buttons1.addChild((new Button("btn2", "Disabled Button"d)).enabled(false)); + buttons1.addChild(new TextWidget(null, "ImageButton widgets: "d)); + buttons1.addChild(new ImageButton("btn3", "text-plain")); + buttons1.addChild(new TextWidget(null, "disabled: "d)); + buttons1.addChild((new ImageButton("btn4", "folder")).enabled(false)); + addChild(buttons1); + + WidgetGroup buttons10 = new HorizontalLayout(); + buttons10.addChild(new TextWidget(null, "ImageTextButton widgets: "d)); + buttons10.addChild(new ImageTextButton("btn5", "text-plain", "Enabled"d)); + buttons10.addChild((new ImageTextButton("btn6", "folder", "Disabled"d)).enabled(false)); + buttons10.addChild(new TextWidget(null, "SwitchButton widgets: "d)); + buttons10.addChild((new SwitchButton("SW1")).checked(true)); + buttons10.addChild((new SwitchButton("SW2")).checked(false)); + buttons10.addChild((new SwitchButton("SW3")).checked(true).enabled(false)); + buttons10.addChild((new SwitchButton("SW4")).checked(false).enabled(false)); + addChild(buttons10); + + WidgetGroup buttons11 = new HorizontalLayout(); + buttons11.addChild(new TextWidget(null, "Construct buttons by action (Button, ImageButton, ImageTextButton): "d)); + Action FILE_OPEN_ACTION = new Action(ACTION_FILE_OPEN, "MENU_FILE_OPEN"c, "document-open", KeyCode.KEY_O, KeyFlag.Control); + buttons11.addChild(new Button(FILE_OPEN_ACTION)); + buttons11.addChild(new ImageButton(FILE_OPEN_ACTION)); + buttons11.addChild(new ImageTextButton(FILE_OPEN_ACTION)); + addChild(buttons11); + + WidgetGroup buttons12 = new HorizontalLayout(); + buttons12.addChild(new TextWidget(null, "The same in disabled state: "d)); + buttons12.addChild((new Button(FILE_OPEN_ACTION)).enabled(false)); + buttons12.addChild((new ImageButton(FILE_OPEN_ACTION)).enabled(false)); + buttons12.addChild((new ImageTextButton(FILE_OPEN_ACTION)).enabled(false)); + addChild(buttons12); + + addChild(new VSpacer()); + addChild(new TextWidget(null, "CheckBoxes in HorizontalLayout"d)); + WidgetGroup buttons2 = new HorizontalLayout(); + buttons2.addChild(new CheckBox("btn1", "CheckBox 1"d)); + buttons2.addChild(new CheckBox("btn2", "CheckBox 2"d)); + //buttons2.addChild(new ResizerWidget()); + buttons2.addChild(new CheckBox("btn3", "CheckBox 3"d)); + buttons2.addChild(new CheckBox("btn4", "CheckBox 4"d)); + addChild(buttons2); + + addChild(new VSpacer()); + addChild(new TextWidget(null, "RadioButtons in HorizontalLayout"d)); + WidgetGroup buttons3 = new HorizontalLayout(); + buttons3.addChild(new RadioButton("btn1", "RadioButton 1"d)); + buttons3.addChild(new RadioButton("btn2", "RadioButton 2"d)); + buttons3.addChild(new RadioButton("btn3", "RadioButton 3"d)); + buttons3.addChild(new RadioButton("btn4", "RadioButton 4"d)); + addChild(buttons3); + + addChild(new VSpacer()); + addChild(new TextWidget(null, "ImageButtons HorizontalLayout"d)); + WidgetGroup buttons4 = new HorizontalLayout(); + buttons4.addChild(new ImageButton("btn1", "fileclose")); + buttons4.addChild(new ImageButton("btn2", "fileopen")); + buttons4.addChild(new ImageButton("btn3", "exit")); + addChild(buttons4); + + addChild(new VSpacer()); + addChild(new TextWidget(null, "In vertical layouts:"d)); + HorizontalLayout hlayout2 = new HorizontalLayout(); + hlayout2.layoutHeight(FILL_PARENT); //layoutWidth(FILL_PARENT). + + buttons1 = new VerticalLayout(); + buttons1.addChild(new TextWidget(null, "Buttons"d)); + buttons1.addChild(new Button("btn1", "Button 1"d)); + buttons1.addChild(new Button("btn2", "Button 2"d)); + buttons1.addChild((new Button("btn3", "Button 3 - disabled"d)).enabled(false)); + buttons1.addChild(new Button("btn4", "Button 4"d)); + hlayout2.addChild(buttons1); + hlayout2.addChild(new HSpacer()); + + buttons2 = new VerticalLayout(); + buttons2.addChild(new TextWidget(null, "CheckBoxes"d)); + buttons2.addChild(new CheckBox("btn1", "CheckBox 1"d)); + buttons2.addChild(new CheckBox("btn2", "CheckBox 2"d)); + buttons2.addChild(new CheckBox("btn3", "CheckBox 3"d)); + buttons2.addChild(new CheckBox("btn4", "CheckBox 4"d)); + hlayout2.addChild(buttons2); + hlayout2.addChild(new HSpacer()); + + buttons3 = new VerticalLayout(); + buttons3.addChild(new TextWidget(null, "RadioButtons"d)); + buttons3.addChild(new RadioButton("btn1", "RadioButton 1"d)); + buttons3.addChild(new RadioButton("btn2", "RadioButton 2"d)); + //buttons3.addChild(new ResizerWidget()); + buttons3.addChild(new RadioButton("btn3", "RadioButton 3"d)); + buttons3.addChild(new RadioButton("btn4", "RadioButton 4"d)); + hlayout2.addChild(buttons3); + hlayout2.addChild(new HSpacer()); + + buttons4 = new VerticalLayout(); + buttons4.addChild(new TextWidget(null, "ImageButtons"d)); + buttons4.addChild(new ImageButton("btn1", "fileclose")); + buttons4.addChild(new ImageButton("btn2", "fileopen")); + buttons4.addChild(new ImageButton("btn3", "exit")); + hlayout2.addChild(buttons4); + hlayout2.addChild(new HSpacer()); + + WidgetGroup buttons5 = new VerticalLayout(); + buttons5.addChild(new TextWidget(null, "ImageTextButtons"d)); + buttons5.addChild(new ImageTextButton("btn1", "fileclose", "Close"d)); + buttons5.addChild(new ImageTextButton("btn2", "fileopen", "Open"d)); + buttons5.addChild(new ImageTextButton("btn3", "exit", "Exit"d)); + hlayout2.addChild(buttons5); + + + addChild(hlayout2); + + addChild(new VSpacer()); + layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); + } +} diff --git a/examples/example1/src/widgets/controls.d b/examples/example1/src/widgets/controls.d new file mode 100644 index 00000000..0997d279 --- /dev/null +++ b/examples/example1/src/widgets/controls.d @@ -0,0 +1,189 @@ +module widgets.controls; + +import dlangui; + +class BasicControls : LinearLayout +{ + this(string ID) + { + super(ID); + layoutHeight(FILL_PARENT); + padding = Rect(12.pointsToPixels,12.pointsToPixels,12.pointsToPixels,12.pointsToPixels); + + HorizontalLayout line1 = new HorizontalLayout(); + addChild(line1); + + GroupBox gb = new GroupBox("checkboxes", "CheckBox"d); + gb.addChild(new CheckBox("cb1", "CheckBox 1"d)); + gb.addChild(new CheckBox("cb2", "CheckBox 2"d).checked(true)); + gb.addChild(new CheckBox("cb3", "CheckBox disabled"d).enabled(false)); + gb.addChild(new CheckBox("cb4", "CheckBox disabled"d).checked(true).enabled(false)); + line1.addChild(gb); + + GroupBox gb2 = new GroupBox("radiobuttons", "RadioButton"d); + gb2.addChild(new RadioButton("rb1", "RadioButton 1"d).checked(true)); + gb2.addChild(new RadioButton("rb2", "RadioButton 2"d)); + gb2.addChild(new RadioButton("rb3", "RadioButton disabled"d).enabled(false)); + line1.addChild(gb2); + + VerticalLayout col1 = new VerticalLayout(); + GroupBox gb3 = new GroupBox("textbuttons", "Button"d, Orientation.Horizontal); + gb3.addChild(new Button("tb1", "Button"d)); + gb3.addChild(new Button("tb2", "Button disabled"d).enabled(false)); + col1.addChild(gb3); + GroupBox gb4 = new GroupBox("imagetextbuttons", "ImageTextButton"d, Orientation.Horizontal); + gb4.addChild(new ImageTextButton("itb1", "document-open", "Enabled"d)); + gb4.addChild(new ImageTextButton("itb2", "document-save", "Disabled"d).enabled(false)); + col1.addChild(gb4); + GroupBox gbtext = new GroupBox("text", "TextWidget"d, Orientation.Horizontal); + gbtext.addChild(new TextWidget("t1", "Red text"d).fontSize(12.pointsToPixels).textColor(0xFF0000)); + gbtext.addChild(new TextWidget("t2", "Italic text"d).fontSize(12.pointsToPixels).fontItalic(true)); + col1.addChild(gbtext); + line1.addChild(col1); + + VerticalLayout col2 = new VerticalLayout(); + GroupBox gb31 = new GroupBox("switches", "SwitchButton"d, Orientation.Vertical); + gb31.addChild(new SwitchButton("sb1")); + gb31.addChild(new SwitchButton("sb2").checked(true)); + gb31.addChild(new SwitchButton("sb3").enabled(false)); + gb31.addChild(new SwitchButton("sb4").enabled(false).checked(true)); + col2.addChild(gb31); + line1.addChild(col2); + + VerticalLayout col3 = new VerticalLayout(); + GroupBox gb32 = new GroupBox("switches", "ImageButton"d, Orientation.Vertical); + gb32.addChild(new ImageButton("ib1", "edit-copy")); + gb32.addChild(new ImageButton("ib3", "edit-paste").enabled(false)); + col3.addChild(gb32); + GroupBox gb33 = new GroupBox("images", "ImageWidget"d, Orientation.Vertical); + gb33.addChild(new ImageWidget("cr3_logo", "cr3_logo")); + col3.addChild(gb33); + line1.addChild(col3); + + + HorizontalLayout line2 = new HorizontalLayout(); + addChild(line2); + + GroupBox gb5 = new GroupBox("scrollbar", "horizontal ScrollBar"d); + gb5.addChild(new ScrollBar("sb1", Orientation.Horizontal)); + line2.addChild(gb5); + GroupBox gb6 = new GroupBox("slider", "horizontal SliderWidget"d); + gb6.addChild(new SliderWidget("sb2", Orientation.Horizontal)); + line2.addChild(gb6); + GroupBox gb7 = new GroupBox("editline1", "EditLine"d); + gb7.addChild(new EditLine("ed1", "Some text"d).minWidth(120.pointsToPixels)); + line2.addChild(gb7); + GroupBox gb8 = new GroupBox("editline2", "EditLine disabled"d); + gb8.addChild(new EditLine("ed2", "Some text"d).enabled(false).minWidth(120.pointsToPixels)); + line2.addChild(gb8); + + HorizontalLayout line3 = new HorizontalLayout(); + line3.layoutWidth(FILL_PARENT); + GroupBox gbeditbox = new GroupBox("editbox", "EditBox"d, Orientation.Horizontal); + gbeditbox.layoutWidth(FILL_PARENT); + EditBox ed1 = new EditBox("ed1", "Some text in EditBox\nOne more line\nYet another text line"); + ed1.layoutHeight(FILL_PARENT); + gbeditbox.addChild(ed1); + line3.addChild(gbeditbox); + GroupBox gbtabs = new GroupBox(null, "TabWidget"d); + gbtabs.layoutWidth(FILL_PARENT); + TabWidget tabs1 = new TabWidget("tabs1"); + tabs1.addTab(new TextWidget("tab1", "TextWidget on tab page\nTextWidgets can be\nMultiline"d).maxLines(3), "Tab 1"d); + tabs1.addTab(new ImageWidget("tab2", "dlangui-logo1"), "Tab 2"d); + tabs1.tabHost.backgroundColor = 0xE0E0E0; + tabs1.tabHost.padding = Rect(10.pointsToPixels, 10.pointsToPixels, 10.pointsToPixels, 10.pointsToPixels); + gbtabs.addChild(tabs1); + line3.addChild(gbtabs); + addChild(line3); + + HorizontalLayout line4 = new HorizontalLayout(); + line4.layoutWidth(FILL_PARENT); + line4.layoutHeight(FILL_PARENT); + GroupBox gbgrid = new GroupBox("grid", "StringGridWidget"d, Orientation.Horizontal); + StringGridWidget grid = new StringGridWidget("stringgrid"); + grid.resize(12, 10); + gbgrid.layoutWidth(FILL_PARENT); + gbgrid.layoutHeight(FILL_PARENT); + grid.layoutWidth(FILL_PARENT); + grid.layoutHeight(FILL_PARENT); + foreach (index, month; ["January"d, "February"d, "March"d, "April"d, "May"d, "June"d, "July"d, "August"d, "September"d, "October"d, "November"d, "December"d]) + grid.setColTitle(cast(int)index, month); + for (int y = 0; y < 10; y++) + grid.setRowTitle(y, to!dstring(y+1)); + + grid.setColWidth(0, 30.pointsToPixels); + grid.autoFit(); + import std.random; + import std.string; + for (int x = 0; x < 12; x++) { + for (int y = 0; y < 10; y++) { + int n = uniform(0, 10000); + grid.setCellText(x, y, to!dstring("%.2f".format(n / 100.0))); + } + } + + gbgrid.addChild(grid); + line4.addChild(gbgrid); + + GroupBox gbtree = new GroupBox("tree", "TreeWidget"d, Orientation.Vertical); + auto tree = new TreeWidget("gbtree"); + tree.maxHeight(200.pointsToPixels); + 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); + gbtree.addChild(tree); + tree.items.selectItem(tree1); + // test adding new tree items + HorizontalLayout newTreeItem = new HorizontalLayout(); + newTreeItem.layoutWidth = FILL_PARENT; + EditLine edNewTreeItem = new EditLine("newTreeItem", "new item"d); + edNewTreeItem.layoutWidth = FILL_PARENT; + Button btnAddItem = new Button("btnAddTreeItem", "Add"d); + Button btnRemoveItem = new Button("btnRemoveTreeItem", "Remove"d); + newTreeItem.addChild(edNewTreeItem); + newTreeItem.addChild(btnAddItem); + newTreeItem.addChild(btnRemoveItem); + btnAddItem.click = delegate(Widget source) { + import std.random; + dstring label = edNewTreeItem.text; + string id = "item%d".format(uniform(1000000, 9999999, rndGen)); + TreeItem item = tree.items.selectedItem; + if (item) { + Log.d("Creating new tree item ", id, " ", label); + TreeItem newItem = new TreeItem(id, label); + item.addChild(newItem); + } + return true; + }; + btnRemoveItem.click = delegate(Widget source) { + TreeItem item = tree.items.selectedItem; + if (item) { + Log.d("Removing tree item ", item.id, " ", item.text); + item.parent.removeChild(item); + } + return true; + }; + gbtree.addChild(newTreeItem); + line4.addChild(gbtree); + + addChild(line4); + } +} diff --git a/examples/example1/src/widgets/longlists.d b/examples/example1/src/widgets/longlists.d new file mode 100644 index 00000000..80d2752a --- /dev/null +++ b/examples/example1/src/widgets/longlists.d @@ -0,0 +1,60 @@ +module widgets.longlists; + +import dlangui; + +class LongListsExample : HorizontalLayout +{ + this(string ID) + { + super(ID); + layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); + + ListWidget list = new ListWidget("list1", Orientation.Vertical); + list.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); + + StringListAdapter stringList = new StringListAdapter(); + WidgetListAdapter listAdapter = new WidgetListAdapter(); + listAdapter.add((new TextWidget()).text("This is a list of widgets"d).styleId("LIST_ITEM")); + stringList.add("This is a list of strings from StringListAdapter"d); + stringList.add("If you type with your keyboard,"d); + stringList.add("then you can find the"d); + stringList.add("item in the list"d); + stringList.add("neat!"d); + for (int i = 1; i < 1000; i++) { + dstring label = "List item "d ~ to!dstring(i); + listAdapter.add((new TextWidget()).text("Widget list - "d ~ label).styleId("LIST_ITEM")); + stringList.add("Simple string - "d ~ label); + } + list.ownAdapter = listAdapter; + listAdapter.resetItemState(0, State.Enabled); + listAdapter.resetItemState(5, State.Enabled); + listAdapter.resetItemState(7, State.Enabled); + listAdapter.resetItemState(12, State.Enabled); + assert(list.itemEnabled(5) == false); + assert(list.itemEnabled(6) == true); + list.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); + list.selectItem(0); + + addChild(list); + + ListWidget list2 = new StringListWidget("list2"); + list2.ownAdapter = stringList; + list2.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); + list2.selectItem(0); + addChild(list2); + + VerticalLayout itemedit = new VerticalLayout(); + itemedit.addChild(new TextWidget(null, "New item text:"d)); + EditLine itemtext = new EditLine(null, "Text for new item"d); + itemedit.addChild(itemtext); + Button btn = new Button(null, "Add item"d); + itemedit.addChild(btn); + addChild(itemedit); + btn.click = delegate(Widget src) + { + stringList.add(itemtext.text); + listAdapter.add((new TextWidget()).text(itemtext.text).styleId("LIST_ITEM")); + return true; + }; + } +} diff --git a/examples/example1/src/widgets/misc.d b/examples/example1/src/widgets/misc.d new file mode 100644 index 00000000..65998ab6 --- /dev/null +++ b/examples/example1/src/widgets/misc.d @@ -0,0 +1,117 @@ +module widgets.misc; + +import dlangui; + +class TimerTest : HorizontalLayout { + ulong timerId; + TextWidget _counter; + int _value; + Button _start; + Button _stop; + override bool onTimer(ulong id) { + _value++; + _counter.text = to!dstring(_value); + return true; + } + this() { + addChild(new TextWidget(null, "Timer test."d)); + _counter = new TextWidget(null, "0"d); + _counter.fontSize(32); + _start = new Button(null, "Start timer"d); + _stop = new Button(null, "Stop timer"d); + _stop.enabled = false; + _start.click = delegate(Widget src) { + _start.enabled = false; + _stop.enabled = true; + timerId = setTimer(1000); + return true; + }; + _stop.click = delegate(Widget src) { + _start.enabled = true; + _stop.enabled = false; + cancelTimer(timerId); + return true; + }; + addChild(_start); + addChild(_stop); + addChild(_counter); + } +} + +class MiscExample : LinearLayout +{ + this(string ID) + { + super(ID); + addChild((new TextWidget()).textColor(0x00802000).text("Text widget 0")); + addChild((new TextWidget()).textColor(0x40FF4000).text("Text widget")); + addChild(new ProgressBarWidget().progress(300).animationInterval(50)); + addChild(new ProgressBarWidget().progress(-1).animationInterval(50)); + addChild((new Button("BTN1")).textResource("EXIT")); //.textColor(0x40FF4000) + addChild(new TimerTest()); + + MenuItem editPopupItem = new MenuItem(null); + editPopupItem.add(new Action(EditorActions.Copy, "MENU_EDIT_COPY"c, "edit-copy", KeyCode.KEY_C, KeyFlag.Control)); + editPopupItem.add(new Action(EditorActions.Paste, "MENU_EDIT_PASTE"c, "edit-paste", KeyCode.KEY_V, KeyFlag.Control)); + editPopupItem.add(new Action(EditorActions.Cut, "MENU_EDIT_CUT"c, "edit-cut", KeyCode.KEY_X, KeyFlag.Control)); + editPopupItem.add(new Action(EditorActions.Undo, "MENU_EDIT_UNDO"c, "edit-undo", KeyCode.KEY_Z, KeyFlag.Control)); + editPopupItem.add(new Action(EditorActions.Redo, "MENU_EDIT_REDO"c, "edit-redo", KeyCode.KEY_Y, KeyFlag.Control)); + editPopupItem.add(new Action(EditorActions.Indent, "MENU_EDIT_INDENT"c, "edit-indent", KeyCode.TAB, 0)); + editPopupItem.add(new Action(EditorActions.Unindent, "MENU_EDIT_UNINDENT"c, "edit-unindent", KeyCode.TAB, KeyFlag.Control)); + + LinearLayout hlayout = new HorizontalLayout(); + hlayout.layoutWidth(FILL_PARENT); + //hlayout.addChild((new Button()).text("<<")); //.textColor(0x40FF4000) + hlayout.addChild((new TextWidget()).text("Several").alignment(Align.Center)); + hlayout.addChild((new ImageWidget()).drawableId("btn_radio").padding(Rect(5,5,5,5)).alignment(Align.Center)); + hlayout.addChild((new TextWidget()).text("items").alignment(Align.Center)); + hlayout.addChild((new ImageWidget()).drawableId("btn_check").padding(Rect(5,5,5,5)).alignment(Align.Center)); + hlayout.addChild((new TextWidget()).text("in horizontal layout")); + hlayout.addChild((new ImageWidget()).drawableId("exit").padding(Rect(5,5,5,5)).alignment(Align.Center)); + hlayout.addChild((new EditLine("editline", "Some text to edit"d)).popupMenu(editPopupItem).alignment(Align.Center).layoutWidth(FILL_PARENT)); + hlayout.addChild((new EditLine("passwd", "Password"d)).passwordChar('*').popupMenu(editPopupItem).alignment(Align.Center).layoutWidth(FILL_PARENT)); + //hlayout.addChild((new Button()).text(">>")); //.textColor(0x40FF4000) + hlayout.backgroundColor = 0x8080C0; + addChild(hlayout); + + LinearLayout vlayoutgroup = new HorizontalLayout(); + LinearLayout vlayout = new VerticalLayout(); + vlayout.addChild((new TextWidget()).text("VLayout line 1").textColor(0x40FF4000)); // + vlayout.addChild((new TextWidget()).text("VLayout line 2").textColor(0x40FF8000)); + vlayout.addChild((new TextWidget()).text("VLayout line 2").textColor(0x40008000)); + vlayout.addChild(new RadioButton("rb1", "Radio button 1"d)); + vlayout.addChild(new RadioButton("rb2", "Radio button 2"d)); + vlayout.addChild(new RadioButton("rb3", "Radio button 3"d)); + vlayout.layoutWidth(FILL_PARENT); + vlayoutgroup.addChild(vlayout); + vlayoutgroup.layoutWidth(FILL_PARENT); + ScrollBar vsb = new ScrollBar("vscroll", Orientation.Vertical); + vlayoutgroup.addChild(vsb); + addChild(vlayoutgroup); + + ScrollBar sb = new ScrollBar("hscroll", Orientation.Horizontal); + addChild(sb.layoutHeight(WRAP_CONTENT).layoutWidth(FILL_PARENT)); + + addChild((new CheckBox("BTN2", "Some checkbox"d))); + addChild((new TextWidget()).textColor(0x40FF4000).text("Text widget")); + addChild((new ImageWidget()).drawableId("exit").padding(Rect(5,5,5,5))); + addChild((new TextWidget()).textColor(0xFF4000).text("Text widget2").padding(Rect(5,5,5,5)).margins(Rect(5,5,5,5)).backgroundColor(0xA0A0A0)); + addChild((new RadioButton("BTN3", "Some radio button"d))); + addChild((new TextWidget(null, "Text widget3 with very long text"d)).textColor(0x004000)); + addChild(new VSpacer()); // vertical spacer to fill extra space + + childById("BTN1").click = delegate (Widget w) { + Log.d("onClick ", w.id); + //w.backgroundImageId = null; + //w.backgroundColor = 0xFF00FF; + w.textColor = 0xFF00FF; + w.styleId = STYLE_BUTTON_NOMARGINS; + return true; + }; + childById("BTN2").click = delegate (Widget w) { Log.d("onClick ", w.id); return true; }; + childById("BTN3").click = delegate (Widget w) { Log.d("onClick ", w.id); return true; }; + + layoutHeight(FILL_PARENT).layoutWidth(FILL_PARENT); + + } +} \ No newline at end of file diff --git a/examples/example1/src/widgets/package.d b/examples/example1/src/widgets/package.d index 0565488a..3c57ce42 100644 --- a/examples/example1/src/widgets/package.d +++ b/examples/example1/src/widgets/package.d @@ -1,7 +1,11 @@ module widgets; public import widgets.animation; +public import widgets.buttons; public import widgets.canvas; public import widgets.charts; +public import widgets.controls; public import widgets.icons; +public import widgets.longlists; +public import widgets.misc; public import widgets.opengl;