Menu improvements

This commit is contained in:
Vadim Lopatin 2014-05-06 16:24:56 +04:00
parent 3e1db50468
commit b27925f54f
31 changed files with 349 additions and 138 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 828 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 892 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 605 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 593 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 701 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 635 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 771 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 559 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 436 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 598 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 753 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 810 B

View File

@ -37,8 +37,13 @@ extern (C) int UIAppMain(string[] args) {
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/mdpi/") // when res dir is located at the same directory as executable
];
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
drawableCache.setResourcePaths(resourceDirs);
// setup i18n - look for i18n directory inside one of passed directories
@ -53,21 +58,24 @@ extern (C) int UIAppMain(string[] args) {
VerticalLayout contentLayout = new VerticalLayout();
MenuItem mainMenuItems = new MenuItem();
MenuItem fileItem = new MenuItem(new Action(1, "File"d));
fileItem.add(new Action(10, "Open..."d));
fileItem.add(new Action(11, "Save..."d));
MenuItem openRecentItem = new MenuItem(new Action(13, "Open recent..."d));
fileItem.add(new Action(10, "Open..."d, "document-open", KeyCode.KEY_O, KeyFlag.Control));
fileItem.add(new Action(11, "Save..."d, "document-save", KeyCode.KEY_S, KeyFlag.Control));
MenuItem openRecentItem = new MenuItem(new Action(13, "Open recent..."d, "document-open-recent"));
openRecentItem.add(new Action(100, "File 1"d));
openRecentItem.add(new Action(101, "File 2"d));
openRecentItem.add(new Action(102, "File 3"d));
openRecentItem.add(new Action(103, "File 4"d));
openRecentItem.add(new Action(104, "File 5"d));
fileItem.add(openRecentItem);
fileItem.add(new Action(12, "Exit"d));
fileItem.add(new Action(12, "Exit"d, "document-close", KeyCode.KEY_X, KeyFlag.Alt));
MenuItem editItem = new MenuItem(new Action(2, "Edit"d));
editItem.add(new Action(20, "Copy"d));
editItem.add(new Action(21, "Paste"d));
editItem.add(new Action(22, "Cut"d));
MenuItem windowItem = new MenuItem(new Action(3, "Window"d));
editItem.add(new Action(EditorActions.Copy, "Copy"d, "edit-copy", KeyCode.KEY_C, KeyFlag.Control));
editItem.add(new Action(EditorActions.Paste, "Paste"d, "edit-paste", KeyCode.KEY_V, KeyFlag.Control));
editItem.add(new Action(EditorActions.Cut, "Cut"d, "edit-cut", KeyCode.KEY_X, KeyFlag.Control));
editItem.add(new Action(EditorActions.Undo, "Undo"d, "edit-undo", KeyCode.KEY_Z, KeyFlag.Control));
editItem.add(new Action(EditorActions.Redo, "Redo"d, "edit-redo", KeyCode.KEY_Y, KeyFlag.Control));
editItem.add(new Action(20, "Preferences..."d));
MenuItem windowItem = new MenuItem(new Action(3, "Window"d));
windowItem.add(new Action(30, "Preferences"d));
MenuItem helpItem = new MenuItem(new Action(4, "Help"d));
helpItem.add(new Action(40, "View Help"d));

View File

@ -21,13 +21,175 @@ module dlangui.core.events;
import dlangui.core.i18n;
import dlangui.core.collections;
private import dlangui.widgets.widget;
import std.string;
import std.conv;
import std.utf;
string keyName(uint keyCode) {
switch (keyCode) {
case KeyCode.KEY_A:
return "A";
case KeyCode.KEY_B:
return "B";
case KeyCode.KEY_C:
return "C";
case KeyCode.KEY_D:
return "D";
case KeyCode.KEY_E:
return "E";
case KeyCode.KEY_F:
return "F";
case KeyCode.KEY_G:
return "G";
case KeyCode.KEY_H:
return "H";
case KeyCode.KEY_I:
return "I";
case KeyCode.KEY_J:
return "J";
case KeyCode.KEY_K:
return "K";
case KeyCode.KEY_L:
return "L";
case KeyCode.KEY_M:
return "M";
case KeyCode.KEY_N:
return "N";
case KeyCode.KEY_O:
return "O";
case KeyCode.KEY_P:
return "P";
case KeyCode.KEY_Q:
return "Q";
case KeyCode.KEY_R:
return "R";
case KeyCode.KEY_S:
return "S";
case KeyCode.KEY_T:
return "T";
case KeyCode.KEY_U:
return "U";
case KeyCode.KEY_V:
return "V";
case KeyCode.KEY_W:
return "W";
case KeyCode.KEY_X:
return "X";
case KeyCode.KEY_Y:
return "Y";
case KeyCode.KEY_Z:
return "Z";
case KeyCode.KEY_0:
return "0";
case KeyCode.KEY_1:
return "1";
case KeyCode.KEY_2:
return "2";
case KeyCode.KEY_3:
return "3";
case KeyCode.KEY_4:
return "4";
case KeyCode.KEY_5:
return "5";
case KeyCode.KEY_6:
return "6";
case KeyCode.KEY_7:
return "7";
case KeyCode.KEY_8:
return "8";
case KeyCode.KEY_9:
return "9";
case KeyCode.F1:
return "F1";
case KeyCode.F2:
return "F2";
case KeyCode.F3:
return "F3";
case KeyCode.F4:
return "F4";
case KeyCode.F5:
return "F5";
case KeyCode.F6:
return "F6";
case KeyCode.F7:
return "F7";
case KeyCode.F8:
return "F8";
case KeyCode.F9:
return "F9";
case KeyCode.F10:
return "F10";
case KeyCode.F11:
return "F11";
case KeyCode.F12:
return "F12";
case KeyCode.F13:
return "F13";
case KeyCode.F14:
return "F14";
case KeyCode.F15:
return "F15";
case KeyCode.F16:
return "F16";
case KeyCode.F17:
return "F17";
case KeyCode.F18:
return "F18";
case KeyCode.F19:
return "F19";
case KeyCode.F20:
return "F20";
case KeyCode.F21:
return "F21";
case KeyCode.F22:
return "F22";
case KeyCode.F23:
return "F23";
case KeyCode.F24:
return "F24";
case KeyCode.PAGEUP:
return "PageUp";
case KeyCode.PAGEDOWN:
return "PageDown";
case KeyCode.HOME:
return "Home";
case KeyCode.END:
return "End";
case KeyCode.LEFT:
return "Left";
case KeyCode.RIGHT:
return "Right";
case KeyCode.UP:
return "Up";
case KeyCode.DOWN:
return "Down";
case KeyCode.INS:
return "Ins";
case KeyCode.DEL:
return "Del";
default:
return format("0x%08x", keyCode);
}
}
struct Accelerator {
uint keyCode;
uint keyFlags;
/// returns accelerator text description
@property dstring label() {
dstring buf;
if (keyFlags & KeyFlag.Control)
buf ~= "Ctrl+";
if (keyFlags & KeyFlag.Alt)
buf ~= "Alt+";
if (keyFlags & KeyFlag.Shift)
buf ~= "Shift+";
buf ~= toUTF32(keyName(keyCode));
return cast(dstring)buf;
}
}
/// UI action
@ -39,25 +201,36 @@ class Action {
this(int id) {
_id = id;
}
this(int id, string labelResourceId, string iconResourceId = null) {
this(int id, string labelResourceId, string iconResourceId = null, uint keyCode = 0, uint keyFlags = 0) {
_id = id;
_label = labelResourceId;
_iconId = iconResourceId;
}
this(int id, dstring label, string iconResourceId = null) {
_id = id;
_label = label;
_iconId = iconResourceId;
}
if (keyCode)
_accelerators ~= Accelerator(keyCode, keyFlags);
}
/// action with accelerator, w/o label
this(int id, uint keyCode, uint keyFlags = 0) {
_id = id;
_accelerators ~= Accelerator(keyCode, keyFlags);
}
/// action with label, icon, and accelerator
this(int id, dstring label, string iconResourceId = null, uint keyCode = 0, uint keyFlags = 0) {
_id = id;
_label = label;
_iconId = iconResourceId;
if (keyCode)
_accelerators ~= Accelerator(keyCode, keyFlags);
}
/// returs array of accelerators
@property Accelerator[] accelerators() {
return _accelerators;
}
/// returns text description for first accelerator of action; null if no accelerators
@property dstring acceleratorText() {
if (_accelerators.length < 1)
return null;
return _accelerators[0].label;
}
/// returns true if accelerator matches provided key code and flags
bool checkAccelerator(uint keyCode, uint keyFlags) {
foreach(a; _accelerators)

View File

@ -114,7 +114,8 @@ class UIStringTranslator {
import std.file;
foreach(dir; dirs) {
string path = appendPath(dir, "i18n/");
if (exists(path) && isDir(path)) {
if (exists(path) && isDir(path)) {
Log.i("Adding i18n dir ", path);
_resourceDir = path;
return _resourceDir;
}

View File

@ -30,6 +30,125 @@ import std.algorithm;
immutable dchar EOL = '\n';
/// Editor action codes
enum EditorActions {
None = 0,
/// move cursor one char left
Left = 1000,
/// move cursor one char left with selection
SelectLeft,
/// move cursor one char right
Right,
/// move cursor one char right with selection
SelectRight,
/// move cursor one line up
Up,
/// move cursor one line up with selection
SelectUp,
/// move cursor one line down
Down,
/// move cursor one line down with selection
SelectDown,
/// move cursor one word left
WordLeft,
/// move cursor one word left with selection
SelectWordLeft,
/// move cursor one word right
WordRight,
/// move cursor one word right with selection
SelectWordRight,
/// move cursor one page up
PageUp,
/// move cursor one page up with selection
SelectPageUp,
/// move cursor one page down
PageDown,
/// move cursor one page down with selection
SelectPageDown,
/// move cursor to the beginning of page
PageBegin,
/// move cursor to the beginning of page with selection
SelectPageBegin,
/// move cursor to the end of page
PageEnd,
/// move cursor to the end of page with selection
SelectPageEnd,
/// move cursor to the beginning of line
LineBegin,
/// move cursor to the beginning of line with selection
SelectLineBegin,
/// move cursor to the end of line
LineEnd,
/// move cursor to the end of line with selection
SelectLineEnd,
/// move cursor to the beginning of document
DocumentBegin,
/// move cursor to the beginning of document with selection
SelectDocumentBegin,
/// move cursor to the end of document
DocumentEnd,
/// move cursor to the end of document with selection
SelectDocumentEnd,
/// delete char before cursor (backspace)
DelPrevChar,
/// delete char after cursor (del key)
DelNextChar,
/// delete word before cursor (ctrl + backspace)
DelPrevWord,
/// delete char after cursor (ctrl + del key)
DelNextWord,
/// insert new line (Enter)
InsertNewLine,
/// insert new line after current position (Ctrl+Enter)
PrependNewLine,
/// Turn On/Off replace mode
ToggleReplaceMode,
/// Copy selection to clipboard
Copy,
/// Cut selection to clipboard
Cut,
/// Paste selection from clipboard
Paste,
/// Undo last change
Undo,
/// Redo last undoed change
Redo,
/// Tab (e.g., Tab key to insert tab character or indent text)
Tab,
/// Tab (unindent text, or remove whitespace before cursor, usually Shift+Tab)
BackTab,
/// Select whole content (usually, Ctrl+A)
SelectAll,
// Scroll operations
/// Scroll one line up (not changing cursor)
ScrollLineUp,
/// Scroll one line down (not changing cursor)
ScrollLineDown,
/// Scroll one page up (not changing cursor)
ScrollPageUp,
/// Scroll one page down (not changing cursor)
ScrollPageDown,
/// Scroll window left
ScrollLeft,
/// Scroll window right
ScrollRight,
/// Zoom in editor font
ZoomIn,
/// Zoom out editor font
ZoomOut,
}
/// split dstring by delimiters
dstring[] splitDString(dstring source, dchar delimiter = EOL) {
int start = 0;
@ -683,123 +802,6 @@ class EditableContent {
}
}
/// Editor action codes
enum EditorActions {
None = 0,
/// move cursor one char left
Left = 1000,
/// move cursor one char left with selection
SelectLeft,
/// move cursor one char right
Right,
/// move cursor one char right with selection
SelectRight,
/// move cursor one line up
Up,
/// move cursor one line up with selection
SelectUp,
/// move cursor one line down
Down,
/// move cursor one line down with selection
SelectDown,
/// move cursor one word left
WordLeft,
/// move cursor one word left with selection
SelectWordLeft,
/// move cursor one word right
WordRight,
/// move cursor one word right with selection
SelectWordRight,
/// move cursor one page up
PageUp,
/// move cursor one page up with selection
SelectPageUp,
/// move cursor one page down
PageDown,
/// move cursor one page down with selection
SelectPageDown,
/// move cursor to the beginning of page
PageBegin,
/// move cursor to the beginning of page with selection
SelectPageBegin,
/// move cursor to the end of page
PageEnd,
/// move cursor to the end of page with selection
SelectPageEnd,
/// move cursor to the beginning of line
LineBegin,
/// move cursor to the beginning of line with selection
SelectLineBegin,
/// move cursor to the end of line
LineEnd,
/// move cursor to the end of line with selection
SelectLineEnd,
/// move cursor to the beginning of document
DocumentBegin,
/// move cursor to the beginning of document with selection
SelectDocumentBegin,
/// move cursor to the end of document
DocumentEnd,
/// move cursor to the end of document with selection
SelectDocumentEnd,
/// delete char before cursor (backspace)
DelPrevChar,
/// delete char after cursor (del key)
DelNextChar,
/// delete word before cursor (ctrl + backspace)
DelPrevWord,
/// delete char after cursor (ctrl + del key)
DelNextWord,
/// insert new line (Enter)
InsertNewLine,
/// insert new line after current position (Ctrl+Enter)
PrependNewLine,
/// Turn On/Off replace mode
ToggleReplaceMode,
/// Copy selection to clipboard
Copy,
/// Cut selection to clipboard
Cut,
/// Paste selection from clipboard
Paste,
/// Undo last change
Undo,
/// Redo last undoed change
Redo,
/// Tab (e.g., Tab key to insert tab character or indent text)
Tab,
/// Tab (unindent text, or remove whitespace before cursor, usually Shift+Tab)
BackTab,
/// Select whole content (usually, Ctrl+A)
SelectAll,
// Scroll operations
/// Scroll one line up (not changing cursor)
ScrollLineUp,
/// Scroll one line down (not changing cursor)
ScrollLineDown,
/// Scroll one page up (not changing cursor)
ScrollPageUp,
/// Scroll one page down (not changing cursor)
ScrollPageDown,
/// Scroll window left
ScrollLeft,
/// Scroll window right
ScrollRight,
/// Zoom in editor font
ZoomIn,
/// Zoom out editor font
ZoomOut,
}
/// base for all editor widgets
class EditWidgetBase : WidgetGroup, EditableContentListener {
protected EditableContent _content;

View File

@ -53,7 +53,13 @@ class MenuItem {
_subitems ~= new MenuItem(subitemAction);
return this;
}
/// returns true if item is submenu (contains subitems)
/// returns text description for first accelerator of action; null if no accelerators
@property dstring acceleratorText() {
if (!_action)
return null;
return _action.acceleratorText;
}
/// returns true if item is submenu (contains subitems)
@property bool isSubmenu() {
return _subitems.length > 0;
}
@ -80,15 +86,33 @@ class MenuItem {
/// widget to draw menu item
class MenuItemWidget : HorizontalLayout {
protected MenuItem _item;
protected ImageWidget _icon;
protected TextWidget _accel;
protected TextWidget _label;
@property MenuItem item() { return _item; }
this(MenuItem item) {
id="menuitem";
_item = item;
styleId = "MENU_ITEM";
_label = new TextWidget("MENU_LABEL");
// icon
if (_item.action && _item.action.iconId.length) {
_icon = new ImageWidget("MENU_ICON", _item.action.iconId);
_icon.styleId = "MENU_ICON";
addChild(_icon);
}
// label
_label = new TextWidget("MENU_LABEL");
_label.text = _item.label;
addChild(_label);
_label.styleId = "MENU_LABEL";
addChild(_label);
// accelerator
dstring acc = _item.acceleratorText;
if (acc !is null) {
_accel = new TextWidget("MENU_ACCEL");
_accel.styleId = "MENU_ACCEL";
_accel.text = acc;
addChild(_accel);
}
trackHover = true;
clickable = true;
}

View File

@ -705,6 +705,9 @@ Theme createDefaultTheme() {
menuItem.createState(State.Pressed, State.Pressed).backgroundColor(0x4080C000);
menuItem.createState(State.Selected, State.Selected).backgroundColor(0x00F8F9Fa);
menuItem.createState(State.Hovered, State.Hovered).backgroundColor(0xC0FFFF00);
res.createSubstyle("MENU_ICON").margins(Rect(4,2,4,2)).alignment(Align.VCenter|Align.Left);
res.createSubstyle("MENU_LABEL").margins(Rect(8,2,8,2)).alignment(Align.VCenter|Align.Left);
res.createSubstyle("MENU_ACCEL").margins(Rect(4,2,4,2)).alignment(Align.VCenter|Align.Left);
Style transparentButtonBackground = res.createSubstyle("TRANSPARENT_BUTTON_BACKGROUND").backgroundImageId("transparent_button_background").padding(Rect(4,2,4,2)); //.backgroundColor(0xE0E080) ;
//transparentButtonBackground.createState(State.Focused, State.Focused).backgroundColor(0xC0C0C000);