Merge pull request #490 from dayllenger/master

Highlighting in readme and coding style pages #443
This commit is contained in:
Vadim Lopatin 2017-10-16 11:22:46 +03:00 committed by GitHub
commit dbbad64649
2 changed files with 206 additions and 208 deletions

View File

@ -16,28 +16,28 @@ Method and property names: camelCase with lowercase first letter, e.g.: `textAli
Private and protected class and struct fields: \_camelCase prepended with underscore, e.g. `_windowWidth`. Private and protected class and struct fields: \_camelCase prepended with underscore, e.g. `_windowWidth`.
Signal names: camelCase. Signal names: camelCase.
Enum member names: currently, 3 styles are used: JAVA_LIKE, CamelCase and camelCase. TODO: make it consistent? Enum member names: currently, 3 styles are used: JAVA_LIKE, CamelCase and camelCase. TODO: make it consistent?
```D
class MyClass { class MyClass {
private int _magicNumber; private int _magicNumber;
@property int magicNumber() { return _magicNumber; } @property int magicNumber() { return _magicNumber; }
} }
```
Spaces Spaces
------ ------
Always put space after comma or semicolon if there are more items in the same line. Always put space after comma or semicolon if there are more items in the same line.
```D
update(x, y, isAnimating(this));
update(x, y, isAnimating(this)); auto list = [1, 2, 3, 4, 5];
```
auto list = [1, 2, 3, 4, 5];
Usually there is no space after opening or before closing `[]` and `()`. Usually there is no space after opening or before closing `[]` and `()`.
Spaces may be added to improve readability when there is a sequence brackets of the same type. Spaces may be added to improve readability when there is a sequence brackets of the same type.
```D
auto y = (x * x + ( ((a - b) + c) ) * 2); auto y = (x * x + ( ((a - b) + c) ) * 2);
```
Use spaces before and after == != && || + - * / etc. Use spaces before and after == != && || + - * / etc.
@ -45,41 +45,43 @@ Brackets
-------- --------
Curly braces for `if`, `switch`, `for`, `foreach` - preferable placed on the same lines as keyword: Curly braces for `if`, `switch`, `for`, `foreach` - preferable placed on the same lines as keyword:
```D
if (a == b) {
//
} else {
//
}
if (a == b) { foreach (item; list) {
} else { writeln(item);
} }
```
foreach(item; list) {
writeln(item);
}
Cases in switch should be indented: Cases in switch should be indented:
```D
switch(action.id) { switch(action.id) {
case 1: case 1:
processAction(1); processAction(1);
break; break;
default: default:
break; break;
} }
```
For classes and structs opening { can be either at end of line or in a new line). For classes and structs opening { can be either at end of line or in a new line).
```D
class Foo {
}
class Foo { class Bar : Foo
} {
}
class Bar : Foo ```
{ For methods { should be at the end of line.
}
For methods { can be either at end of line.
Short methods (e.g. property getters) may be written in one line. Short methods (e.g. property getters) may be written in one line.
```D
void invalidate() {
//
}
void invalidate() { int length() { return _list.length; }
// ```
}
int length() { return _list.length; }

324
README.md
View File

@ -128,10 +128,10 @@ Important notice
If build of your app is failed due to dlangui or its dependencies, probably you have not upgraded dependencies. If build of your app is failed due to dlangui or its dependencies, probably you have not upgraded dependencies.
Try following: Try following:
```sh
dub upgrade --force-remove dub upgrade --force-remove
dub build --force dub build --force
```
As well, sometimes removing of dub.json.selections can help. As well, sometimes removing of dub.json.selections can help.
@ -146,11 +146,11 @@ Win32 builds
Build and run demo app using DUB: Build and run demo app using DUB:
```sh
git clone --recursive https://github.com/buggins/dlangui.git git clone --recursive https://github.com/buggins/dlangui.git
cd dlangui/examples/example1 cd dlangui/examples/example1
dub run --build=release dub run --build=release
```
To develop using Visual-D or MonoD, open dlangui.sln using Visual D (or dlangui-monod.sln for MonoD) To develop using Visual-D or MonoD, open dlangui.sln using Visual D (or dlangui-monod.sln for MonoD)
@ -158,13 +158,13 @@ To develop using Visual-D or MonoD, open dlangui.sln using Visual D (or dlangui-
To avoid showing console window add win_app.def file to your package source directory and add line to your dub.json. To avoid showing console window add win_app.def file to your package source directory and add line to your dub.json.
win_app.def: win_app.def:
```json
"sourceFiles": ["$PACKAGE_DIR/src/win_app.def"] "sourceFiles": ["$PACKAGE_DIR/src/win_app.def"]
```
dub.json: dub.json:
```json
"sourceFiles-windows": ["$PACKAGE_DIR/src/win_app.def"], "sourceFiles-windows": ["$PACKAGE_DIR/src/win_app.def"],
```
Mac OSX development using Mono-D Mac OSX development using Mono-D
-------------------------------- --------------------------------
@ -178,17 +178,17 @@ Native Cocoa backend - work is in progress.
In some directory, e.g. ~/src/d/ : In some directory, e.g. ~/src/d/ :
Clone DlangUI repository Clone DlangUI repository
```sh
git clone --recursive https://github.com/buggins/dlangui.git git clone --recursive https://github.com/buggins/dlangui.git
```
Enter dlangui directory Enter dlangui directory
```sh
cd dlangui cd dlangui
```
Open solution file with Mono-D Open solution file with Mono-D
```
dlangui-monod-osx.sln dlangui-monod-osx.sln
```
Linux development using Mono-D Linux development using Mono-D
@ -200,17 +200,17 @@ Required libraries: libsdl2, x11, libfreetype, libfontconfig and OpenGL.
Clone DlangUI repository Clone DlangUI repository
```sh
git clone https://github.com/buggins/dlangui.git git clone https://github.com/buggins/dlangui.git
```
Enter dlangui directory Enter dlangui directory
```sh
cd dlangui cd dlangui
```
Open solution file with Mono-D Open solution file with Mono-D
```
dlangui-monod-linux.sln dlangui-monod-linux.sln
```
Try running examples: helloworld, example1, tetris, dmledit, spreadsheet, opengl Try running examples: helloworld, example1, tetris, dmledit, spreadsheet, opengl
Configurations Debug, Release, Unittest build SDL2+OpenGL versions of apps. Configurations Debug, Release, Unittest build SDL2+OpenGL versions of apps.
@ -258,17 +258,17 @@ Install GIT, DUB, DMD, MonoDevelop with Mono-D plugin.
Clone DlangUI repository Clone DlangUI repository
```sh
git clone https://github.com/buggins/dlangui.git git clone https://github.com/buggins/dlangui.git
```
Enter dlangui directory Enter dlangui directory
```sh
cd dlangui cd dlangui
```
Open solution file with Mono-D Open solution file with Mono-D
```
dlangui-monod-windows.sln dlangui-monod-windows.sln
```
Try running examples: helloworld, example1, tetris, dmledit, spreadsheet, opengl Try running examples: helloworld, example1, tetris, dmledit, spreadsheet, opengl
Configurations Debug, Release, Unittest build SDL2+OpenGL versions of apps. Configurations Debug, Release, Unittest build SDL2+OpenGL versions of apps.
@ -316,21 +316,21 @@ Install GIT, DUB, DMD, MS Visual Studio (e.g. Community 2013) + VisualD plugin
Clone DlangUI repository Clone DlangUI repository
```sh
git clone --recursive https://github.com/buggins/dlangui.git git clone --recursive https://github.com/buggins/dlangui.git
```
For DlangIDE development, close dlangide project on the same directory level as dlangui is cloned: For DlangIDE development, close dlangide project on the same directory level as dlangui is cloned:
```sh
git clone --recursive https://github.com/buggins/dlangide.git git clone --recursive https://github.com/buggins/dlangide.git
```
Enter dlangui directory Enter dlangui directory
```sh
cd dlangui cd dlangui
```
Open solution file with Visual-D Open solution file with Visual-D
```
dlangui-msvc.sln dlangui-msvc.sln
```
Try running examples: helloworld, example1, tetris, dmledit, spreadsheet, opengl Try running examples: helloworld, example1, tetris, dmledit, spreadsheet, opengl
Configurations Debug, Release, Unittest build SDL2+OpenGL versions of apps. Configurations Debug, Release, Unittest build SDL2+OpenGL versions of apps.
@ -384,19 +384,19 @@ Linux builds (DUB)
libsdl2, libfreetype, libfontconfig libsdl2, libfreetype, libfontconfig
E.g. in Ubuntu, you can use following command to enable SDL2 backend builds: E.g. in Ubuntu, you can use following command to enable SDL2 backend builds:
```sh
sudo apt-get install libsdl2-dev sudo apt-get install libsdl2-dev
```
In runtime, .so for following libraries are being loaded (binary packages required): In runtime, .so for following libraries are being loaded (binary packages required):
```
freetype, opengl, fontconfig freetype, opengl, fontconfig
```
Build and run on Linux using DUB: Build and run on Linux using DUB:
```sh
cd examples/example1 cd examples/example1
dub run dlangui:example1 dub run dlangui:example1
```
Other platforms Other platforms
@ -418,39 +418,39 @@ Third party components used
Hello World Hello World
-------------------------------------------------------------- --------------------------------------------------------------
```D
// myproject.d
import dlangui;
mixin APP_ENTRY_POINT;
// myproject.d /// entry point for dlangui based application
import dlangui; extern (C) int UIAppMain(string[] args) {
mixin APP_ENTRY_POINT; // create window
Window window = Platform.instance.createWindow("My Window", null);
/// entry point for dlangui based application // create some widget to show in window
extern (C) int UIAppMain(string[] args) { window.mainWidget = (new Button()).text("Hello world"d).textColor(0xFF0000); // red text
// create window // show window
Window window = Platform.instance.createWindow("My Window", null); window.show();
// create some widget to show in window // run message loop
window.mainWidget = (new Button()).text("Hello world"d).textColor(0xFF0000); // red text return Platform.instance.enterMessageLoop();
// show window }
window.show(); ```
// run message loop
return Platform.instance.enterMessageLoop();
}
Sample dub.json: Sample dub.json:
-------------------------------- --------------------------------
```json
{
"name": "myproject",
"description": "sample DLangUI project",
{ "targetPath": "bin",
"name": "myproject", "targetType": "executable",
"description": "sample DLangUI project",
"targetPath": "bin",
"targetType": "executable",
"dependencies": {
"dlangui": "~master"
}
}
"dependencies": {
"dlangui": "~master"
}
}
```
Hello World using DML Hello World using DML
-------------------------------------------------------------- --------------------------------------------------------------
@ -460,89 +460,85 @@ DlangUI supports creation of widgets from markup.
DML - DlangUI Markup Language - similar to QML. DML - DlangUI Markup Language - similar to QML.
Example of complex UI easy created from text: Example of complex UI easy created from text:
```D
module app;
import dlangui;
mixin APP_ENTRY_POINT;
module app; /// entry point for dlangui based application
extern (C) int UIAppMain(string[] args) {
// create window
Window window = Platform.instance.createWindow("DlangUI example - HelloWorld", null);
import dlangui; // create some widget to show in window
//window.mainWidget = (new Button()).text("Hello, world!"d).margins(Rect(20,20,20,20));
mixin APP_ENTRY_POINT; window.mainWidget = parseML(q{
VerticalLayout {
/// entry point for dlangui based application margins: 10
extern (C) int UIAppMain(string[] args) { padding: 10
// create window backgroundColor: "#C0E0E070" // semitransparent yellow background
Window window = Platform.instance.createWindow("DlangUI example - HelloWorld", null); // red bold text with size = 150% of base style size and font face Arial
TextWidget { text: "Hello World example for DlangUI"; textColor: "red"; fontSize: 150%; fontWeight: 800; fontFace: "Arial" }
// create some widget to show in window // arrange controls as form - table with two columns
//window.mainWidget = (new Button()).text("Hello, world!"d).margins(Rect(20,20,20,20)); TableLayout {
window.mainWidget = parseML(q{ colCount: 2
VerticalLayout { TextWidget { text: "param 1" }
margins: 10 EditLine { id: edit1; text: "some text" }
padding: 10 TextWidget { text: "param 2" }
backgroundColor: "#C0E0E070" // semitransparent yellow background EditLine { id: edit2; text: "some text for param2" }
// red bold text with size = 150% of base style size and font face Arial TextWidget { text: "some radio buttons" }
TextWidget { text: "Hello World example for DlangUI"; textColor: "red"; fontSize: 150%; fontWeight: 800; fontFace: "Arial" } // arrange some radio buttons vertically
// arrange controls as form - table with two columns VerticalLayout {
TableLayout { RadioButton { id: rb1; text: "Item 1" }
colCount: 2 RadioButton { id: rb2; text: "Item 2" }
TextWidget { text: "param 1" } RadioButton { id: rb3; text: "Item 3" }
EditLine { id: edit1; text: "some text" }
TextWidget { text: "param 2" }
EditLine { id: edit2; text: "some text for param2" }
TextWidget { text: "some radio buttons" }
// arrange some radio buttons vertically
VerticalLayout {
RadioButton { id: rb1; text: "Item 1" }
RadioButton { id: rb2; text: "Item 2" }
RadioButton { id: rb3; text: "Item 3" }
}
TextWidget { text: "and checkboxes" }
// arrange some checkboxes horizontally
HorizontalLayout {
CheckBox { id: cb1; text: "checkbox 1" }
CheckBox { id: cb2; text: "checkbox 2" }
}
} }
TextWidget { text: "and checkboxes" }
// arrange some checkboxes horizontally
HorizontalLayout { HorizontalLayout {
Button { id: btnOk; text: "Ok" } CheckBox { id: cb1; text: "checkbox 1" }
Button { id: btnCancel; text: "Cancel" } CheckBox { id: cb2; text: "checkbox 2" }
} }
} }
}); HorizontalLayout {
// you can access loaded items by id - e.g. to assign signal listeners Button { id: btnOk; text: "Ok" }
auto edit1 = window.mainWidget.childById!EditLine("edit1"); Button { id: btnCancel; text: "Cancel" }
auto edit2 = window.mainWidget.childById!EditLine("edit2"); }
// close window on Cancel button click }
window.mainWidget.childById!Button("btnCancel").click = delegate(Widget w) { });
window.close(); // you can access loaded items by id - e.g. to assign signal listeners
return true; auto edit1 = window.mainWidget.childById!EditLine("edit1");
}; auto edit2 = window.mainWidget.childById!EditLine("edit2");
// show message box with content of editors // close window on Cancel button click
window.mainWidget.childById!Button("btnOk").click = delegate(Widget w) { window.mainWidget.childById!Button("btnCancel").click = delegate(Widget w) {
window.showMessageBox(UIString("Ok button pressed"d), window.close();
UIString("Editors content\nEdit1: "d ~ edit1.text ~ "\nEdit2: "d ~ edit2.text)); return true;
return true; };
}; // show message box with content of editors
window.mainWidget.childById!Button("btnOk").click = delegate(Widget w) {
window.showMessageBox(UIString("Ok button pressed"d),
UIString("Editors content\nEdit1: "d ~ edit1.text ~ "\nEdit2: "d ~ edit2.text));
return true;
};
// show window // show window
window.show(); window.show();
// run message loop
return Platform.instance.enterMessageLoop();
}
// run message loop
return Platform.instance.enterMessageLoop();
}
```
There is DMLEdit sample app in DlangUI/examples directory. There is DMLEdit sample app in DlangUI/examples directory.
You can run it with dub: You can run it with dub:
```sh
dub run dlangui:dmledit
dub run dlangui:dmledit ```
It allows to edit DML text and see how it will look like when loaded into app (F5 refreshes view).
It allows to edit QML text and see how it will look like when loaded into app (F5 refreshes view).
Syntax highlight, bracket matching, go to error and other useful features are implemented. Syntax highlight, bracket matching, go to error and other useful features are implemented.
@ -561,8 +557,8 @@ DCD integration: go to definition and autocompletion for D source code.
Project page: [https://github.com/buggins/dlangide](https://github.com/buggins/dlangide) Project page: [https://github.com/buggins/dlangide](https://github.com/buggins/dlangide)
How to build and run using DUB: How to build and run using DUB:
```sh
git clone https://github.com/buggins/dlangide.git git clone https://github.com/buggins/dlangide.git
cd dlangide cd dlangide
dub run dub run
```