spreadsheet example

This commit is contained in:
Vadim Lopatin 2015-11-30 10:31:51 +03:00
parent 8d008415a5
commit 768d418eec
9 changed files with 125 additions and 30 deletions

View File

@ -410,6 +410,11 @@
</Config>
<Folder name="spreadsheet">
<Folder name="src">
<Folder name="dlangui">
<Folder name="widgets">
<File path="src\dlangui\widgets\spreadsheet.d" />
</Folder>
</Folder>
<File path="src\spreadsheetapp.d" />
</Folder>
</Folder>

View File

@ -1 +1,67 @@
module dlangui.widgets.spreadsheet;
import dlangui.core.types;
import dlangui.widgets.styles;
import dlangui.widgets.widget;
import dlangui.widgets.layouts;
import dlangui.widgets.controls;
import dlangui.widgets.tabs;
import dlangui.widgets.editors;
import dlangui.widgets.grid;
/// standard style id for Tab with Up alignment
immutable string STYLE_TAB_SHEET_DOWN = "TAB_SHEET_DOWN";
/// standard style id for button of Tab with Up alignment
immutable string STYLE_TAB_SHEET_DOWN_BUTTON = "TAB_SHEET_DOWN_BUTTON";
/// standard style id for button of Tab with Up alignment
immutable string STYLE_TAB_SHEET_DOWN_BUTTON_TEXT = "TAB_SHEET_DOWN_BUTTON_TEXT";
class SheetTabs : TabControl {
/// create with ID parameter
this(string ID = null) {
super(ID, Align.Bottom);
setStyles(STYLE_TAB_SHEET_DOWN, STYLE_TAB_SHEET_DOWN_BUTTON, STYLE_TAB_SHEET_DOWN_BUTTON_TEXT);
}
}
class SheetEditControl : HorizontalLayout {
EditLine _edPosition;
EditLine _edText;
this(string ID = "sheetEdit") {
_edPosition = new EditLine("edPosition");
_edText = new EditLine("edText");
_edPosition.maxWidth = 100;
_edPosition.minWidth = 100;
_edText.layoutWidth = FILL_PARENT;
addChild(_edPosition);
addChild(_edText);
}
}
class SpreadSheetWidget : VerticalLayout {
SheetEditControl _editControl;
StringGridWidget _grid;
SheetTabs _tabs;
this(string ID = "spreadsheet") {
_editControl = new SheetEditControl();
_editControl.layoutWidth = FILL_PARENT;
_grid = new StringGridWidget("grid");
_grid.layoutWidth = FILL_PARENT;
_grid.layoutHeight = FILL_PARENT;
_grid.resize(50, 50);
_tabs = new SheetTabs();
_tabs.layoutWidth = FILL_PARENT;
_tabs.addTab("Sheet1", "Sheet1"d);
_tabs.addTab("Sheet2", "Sheet2"d);
_tabs.addTab("Sheet3", "Sheet3"d);
layoutWidth = FILL_PARENT;
layoutHeight = FILL_PARENT;
backgroundColor = 0xFFE0E0E0;
minHeight = 100;
addChild(_editControl);
addChild(_grid);
addChild(_tabs);
}
}

View File

@ -3,7 +3,7 @@ module spreadsheet;
import dlangui;
import dlangui.dialogs.filedlg;
import dlangui.dialogs.dialog;
import dlangui.dml.dmlhighlight;
import dlangui.widgets.spreadsheet;
import std.array : replaceFirst;
mixin APP_ENTRY_POINT;
@ -42,35 +42,12 @@ const Action ACTION_EDIT_PREFERENCES = (new Action(IDEActions.EditPreferences, "
const Action ACTION_DEBUG_START = new Action(IDEActions.DebugStart, "MENU_DEBUG_UPDATE_PREVIEW"c, "debug-run"c, KeyCode.F5, 0);
const Action ACTION_HELP_ABOUT = new Action(IDEActions.HelpAbout, "MENU_HELP_ABOUT"c);
/// DIDE source file editor
class DMLSourceEdit : SourceEdit {
this(string ID) {
super(ID);
MenuItem editPopupItem = new MenuItem(null);
editPopupItem.add(ACTION_EDIT_COPY, ACTION_EDIT_PASTE, ACTION_EDIT_CUT, ACTION_EDIT_UNDO, ACTION_EDIT_REDO, ACTION_EDIT_INDENT, ACTION_EDIT_UNINDENT, ACTION_EDIT_TOGGLE_LINE_COMMENT, ACTION_DEBUG_START);
popupMenu = editPopupItem;
content.syntaxSupport = new DMLSyntaxSupport("");
setTokenHightlightColor(TokenCategory.Comment, 0x008000); // green
setTokenHightlightColor(TokenCategory.Keyword, 0x0000FF); // blue
setTokenHightlightColor(TokenCategory.String, 0xa31515); // brown
setTokenHightlightColor(TokenCategory.Integer, 0xa315C0); //
setTokenHightlightColor(TokenCategory.Float, 0xa315C0); //
setTokenHightlightColor(TokenCategory.Error, 0xFF0000); // red
setTokenHightlightColor(TokenCategory.Op, 0x503000);
setTokenHightlightColor(TokenCategory.Identifier_Class, 0x000080); // blue
}
this() {
this("DMLEDIT");
}
}
class EditFrame : AppFrame {
MenuItem mainMenuItems;
override protected void init() {
_appName = "DMLEdit";
_appName = "DlangUISpreadSheet";
super.init();
}
@ -231,15 +208,15 @@ class EditFrame : AppFrame {
}
}
SpreadSheetWidget _spreadsheet;
/// create app body widget
override protected Widget createBody() {
VerticalLayout bodyWidget = new VerticalLayout();
bodyWidget.layoutWidth = FILL_PARENT;
bodyWidget.layoutHeight = FILL_PARENT;
HorizontalLayout hlayout = new HorizontalLayout();
hlayout.layoutWidth = FILL_PARENT;
hlayout.layoutHeight = FILL_PARENT;
bodyWidget.addChild(hlayout);
_spreadsheet = new SpreadSheetWidget();
bodyWidget.addChild(_spreadsheet);
return bodyWidget;
}
@ -255,8 +232,13 @@ extern (C) int UIAppMain(string[] args) {
FontManager.fontGamma = 0.8;
FontManager.hintingMode = HintingMode.Normal;
// select translation file - for english language
Platform.instance.uiLanguage = "en";
// load theme from file "theme_custom.xml"
Platform.instance.uiTheme = "theme_custom";
// create window
Window window = Platform.instance.createWindow("DlangUI ML editor"d, null, WindowFlag.Resizable, 700, 470);
Window window = Platform.instance.createWindow("DlangUI SpreadSheet example"d, null, WindowFlag.Resizable, 700, 470);
// create some widget to show in window
window.windowIcon = drawableCache.getImage("dlangui-logo1");

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 341 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 B

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:constantSize="true"
android:dither="false"
android:variablePadding="false" >
<item
android:drawable="tab_sheet_down_selected"
android:state_selected="true" />
<item
android:drawable="tab_sheet_down_normal" />
</selector>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<theme
id="theme_custom"
parent="theme_default"
fontSize="16"
>
<style id="TAB_SHEET_DOWN_BUTTON"
backgroundImageId="tab_sheet_down_background"
layoutWidth="FILL_PARENT"
>
<state state_selected="true" backgroundImageId="tab_up_backgrond_selected"/>
</style>
<style id="TAB_SHEET_DOWN_BUTTON_TEXT"
textColor="#000000"
align="Center"
fontSize="12px"
>
<state state_selected="true" state_focused="true" textColor="#000000"/>
<state state_selected="true" textColor="#000000"/>
<state state_focused="true" textColor="#000000"/>
<state state_hovered="true" textColor="#808000"/>
</style>
<style id="TAB_SHEET_DOWN_BUTTON"
backgroundImageId="tab_sheet_down"
/>
</theme>

View File

@ -16,5 +16,10 @@ res/mdpi/edit-paste.png
res/mdpi/edit-redo.png
res/mdpi/edit-undo.png
res/mdpi/edit-unindent.png
res/mdpi/tab_sheet_down_background.9.png
res/mdpi/tab_sheet_down_normal.9.png
res/mdpi/tab_sheet_down_selected.9.png
res/mdpi/text-dml.png
res/mdpi/tx_fabric.jpg
res/tab_sheet_down.xml
res/theme_custom.xml