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,17 +45,19 @@ 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) { if (a == b) {
//
} else { } else {
//
} }
foreach (item; list) { foreach (item; list) {
writeln(item); 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);
@ -63,23 +65,23 @@ Cases in switch should be indented:
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 { can be either at end of line. For methods { should be at the 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; }
```

106
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,7 +418,7 @@ Third party components used
Hello World Hello World
-------------------------------------------------------------- --------------------------------------------------------------
```D
// myproject.d // myproject.d
import dlangui; import dlangui;
mixin APP_ENTRY_POINT; mixin APP_ENTRY_POINT;
@ -434,11 +434,11 @@ Hello World
// run message loop // run message loop
return Platform.instance.enterMessageLoop(); return Platform.instance.enterMessageLoop();
} }
```
Sample dub.json: Sample dub.json:
-------------------------------- --------------------------------
```json
{ {
"name": "myproject", "name": "myproject",
"description": "sample DLangUI project", "description": "sample DLangUI project",
@ -450,7 +450,7 @@ Sample dub.json:
"dlangui": "~master" "dlangui": "~master"
} }
} }
```
Hello World using DML Hello World using DML
-------------------------------------------------------------- --------------------------------------------------------------
@ -460,9 +460,7 @@ 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; module app;
import dlangui; import dlangui;
@ -531,18 +529,16 @@ Example of complex UI easy created from text:
// run message loop // run message loop
return Platform.instance.enterMessageLoop(); 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
```