diff --git a/examples/example1/res/i18n/en.ini b/examples/example1/res/i18n/en.ini index 94260b4c..f0415321 100644 --- a/examples/example1/res/i18n/en.ini +++ b/examples/example1/res/i18n/en.ini @@ -1,4 +1,4 @@ -EXIT=Exit +EXIT=Exit MENU_FILE=&File MENU_FILE_OPEN=&Open MENU_FILE_OPEN_RECENT=Open recent @@ -14,7 +14,7 @@ MENU_EDIT_PREFERENCES=&Preferences MENU_VIEW=&View MENU_VIEW_LANGUAGE=Interface &Language MENU_VIEW_LANGUAGE_EN=English -MENU_VIEW_LANGUAGE_RU=Russian +MENU_VIEW_LANGUAGE_RU=Русский MENU_VIEW_THEME=&Theme MENU_VIEW_THEME_DEFAULT=&Default MENU_VIEW_THEME_CUSTOM1=&Custom 1 @@ -24,3 +24,9 @@ MENU_HELP=&Help MENU_HELP_VIEW_HELP=&View help MENU_HELP_ABOUT=&About +TAB_LONG_LIST=Long list +TAB_BUTTONS=Buttons +TAB_ANIMATION=Animation +TAB_TABLE_LAYOUT=Table layout +TAB_EDITORS=Editors + diff --git a/examples/example1/res/i18n/ru.ini b/examples/example1/res/i18n/ru.ini index fc1e0776..82f24a22 100644 --- a/examples/example1/res/i18n/ru.ini +++ b/examples/example1/res/i18n/ru.ini @@ -1 +1,33 @@ -EXIT=Выход +EXIT=Выход +MENU_FILE=&Файл +MENU_FILE_OPEN=&Открыть +MENU_FILE_OPEN_RECENT=Открыть из последних +MENU_FILE_SAVE=&Сохранить +MENU_FILE_EXIT=Вы&ход +MENU_EDIT=&Правка +MENU_EDIT_COPY=&Копировать +MENU_EDIT_PASTE=&Вставить +MENU_EDIT_CUT=Вырезать +MENU_EDIT_UNDO=&Отмена +MENU_EDIT_REDO=&Повторить +MENU_EDIT_PREFERENCES=&Настройки +MENU_VIEW=&Вид +MENU_VIEW_LANGUAGE=&Язык интерфейса +MENU_VIEW_LANGUAGE_EN=English +MENU_VIEW_LANGUAGE_RU=Русский +MENU_VIEW_THEME=&Тема +MENU_VIEW_THEME_DEFAULT=Стандартная +MENU_VIEW_THEME_CUSTOM1=Пример 1 +MENU_WINDOW=&Окно +MENU_WINDOW_PREFERENCES=&Настройки +MENU_HELP=&Справка +MENU_HELP_VIEW_HELP=&Просмотр справки +MENU_HELP_ABOUT=&О программе + +TAB_LONG_LIST=Длинный список +TAB_BUTTONS=Кнопки +TAB_ANIMATION=Анимация +TAB_TABLE_LAYOUT=Табличный layout +TAB_EDITORS=Редакторы + + diff --git a/examples/example1/src/main.d b/examples/example1/src/main.d index d49d8e71..bddde90d 100644 --- a/examples/example1/src/main.d +++ b/examples/example1/src/main.d @@ -131,17 +131,35 @@ extern (C) int UIAppMain(string[] args) { MenuItem viewItem = new MenuItem(new Action(60, "MENU_VIEW")); MenuItem langItem = new MenuItem(new Action(61, "MENU_VIEW_LANGUAGE")); - langItem.add((new MenuItem(new Action(611, "MENU_VIEW_LANGUAGE_EN"))).type(MenuItemType.Radio).checked(true)); - langItem.add((new MenuItem(new Action(612, "MENU_VIEW_LANGUAGE_RU"))).type(MenuItemType.Radio)); + auto onLangChange = delegate (MenuItem item) { + if (!item.checked) + return false; + if (item.id == 611) { + // set interface language to english + i18n.load("en.ini"); + contentLayout.requestLayout(); + } else if (item.id == 612) { + // set interface language to russian + i18n.load("ru.ini", "en.ini"); + contentLayout.requestLayout(); + } + return true; + }; + MenuItem enLang = (new MenuItem(new Action(611, "MENU_VIEW_LANGUAGE_EN"))).type(MenuItemType.Radio).checked(true); + MenuItem ruLang = (new MenuItem(new Action(612, "MENU_VIEW_LANGUAGE_RU"))).type(MenuItemType.Radio); + enLang.onMenuItemClick = onLangChange; + ruLang.onMenuItemClick = onLangChange; + langItem.add(enLang); + langItem.add(ruLang); MenuItem themeItem = new MenuItem(new Action(62, "MENU_VIEW_THEME")); themeItem.add((new MenuItem(new Action(621, "MENU_VIEW_THEME_DEFAULT"))).type(MenuItemType.Radio).checked(true)); themeItem.add((new MenuItem(new Action(622, "MENU_VIEW_THEME_CUSTOM1"))).type(MenuItemType.Radio)); viewItem.add(langItem); viewItem.add(themeItem); - MenuItem windowItem = new MenuItem(new Action(3, "MENU_WINDOW")); + MenuItem windowItem = new MenuItem(new Action(3, "MENU_WINDOW"c)); windowItem.add(new Action(30, "MENU_WINDOW_PREFERENCES")); - MenuItem helpItem = new MenuItem(new Action(4, "MENU_HELP")); + MenuItem helpItem = new MenuItem(new Action(4, "MENU_HELP"c)); helpItem.add(new Action(40, "MENU_HELP_VIEW_HELP")); helpItem.add(new Action(41, "MENU_HELP_ABOUT")); mainMenuItems.add(fileItem); @@ -239,7 +257,7 @@ extern (C) int UIAppMain(string[] args) { assert(list.itemEnabled(6) == true); list.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); list.selectItem(0); - tabs.addTab(list, "Long List"d); + tabs.addTab(list, "TAB_LONG_LIST"c); } { @@ -329,7 +347,7 @@ extern (C) int UIAppMain(string[] args) { layout3.addChild(new VSpacer()); layout3.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); - tabs.addTab(layout3, "Buttons"d); + tabs.addTab(layout3, "TAB_BUTTONS"c); } TableLayout table = new TableLayout("TABLE"); @@ -347,11 +365,11 @@ extern (C) int UIAppMain(string[] args) { table.addChild((new TextWidget(null, "Param 3"d)).alignment(Align.Right | Align.VCenter)); table.addChild((new EditLine("edit3", "Parameter 3 value"d)).layoutWidth(FILL_PARENT)); table.margins(Rect(10,10,10,10)).layoutWidth(FILL_PARENT); - tabs.addTab(table, "Table Layout"d); + tabs.addTab(table, "TAB_TABLE_LAYOUT"c); tabs.addTab((new TextWidget()).id("tab5").textColor(0x00802000).text("Tab 5 contents"), "Tab 5"d); - tabs.addTab((new SampleAnimationWidget("tab6")).layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT), "Animation"d); + tabs.addTab((new SampleAnimationWidget("tab6")).layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT), "TAB_ANIMATION"c); //========================================================================== // create Editors test tab @@ -390,7 +408,7 @@ extern (C) int UIAppMain(string[] args) { editors.addChild(editBox2); editors.layoutHeight(FILL_PARENT).layoutWidth(FILL_PARENT); - tabs.addTab(editors, "Editors"d); + tabs.addTab(editors, "TAB_EDITORS"c); //========================================================================== diff --git a/src/dlangui/widgets/controls.d b/src/dlangui/widgets/controls.d index 45aeb0b8..ac3199bb 100644 --- a/src/dlangui/widgets/controls.d +++ b/src/dlangui/widgets/controls.d @@ -74,8 +74,8 @@ class TextWidget : Widget { return this; } /// set text to show - override @property Widget text(ref UIString s) { - _text = s; + override @property Widget text(UIString s) { + _text = s; requestLayout(); return this; } @@ -199,7 +199,7 @@ class ImageTextButton : HorizontalLayout { protected TextWidget _label; override @property dstring text() { return _label.text; } override @property Widget text(dstring s) { _label.text = s; requestLayout(); return this; } - override @property Widget text(ref UIString s) { _label.text = s; requestLayout(); return this; } + override @property Widget text(UIString s) { _label.text = s; requestLayout(); return this; } this(string ID = null, string drawableId = null, string textResourceId = null) { super(ID); styleId = "BUTTON"; @@ -292,7 +292,7 @@ class Button : Widget { protected UIString _text; override @property dstring text() { return _text; } override @property Widget text(dstring s) { _text = s; requestLayout(); return this; } - override @property Widget text(ref UIString s) { _text = s; requestLayout(); return this; } + override @property Widget text(UIString s) { _text = s; requestLayout(); return this; } @property Widget textResource(string s) { _text = s; requestLayout(); return this; } this(string ID = null) { super(ID); diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index 0ece7329..5578f480 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -1101,7 +1101,7 @@ class EditWidgetBase : WidgetGroup, EditableContentListener, MenuItemActionHandl } /// set text - override @property Widget text(ref UIString s) { + override @property Widget text(UIString s) { _content.text = s; requestLayout(); return this; diff --git a/src/dlangui/widgets/menu.d b/src/dlangui/widgets/menu.d index 82cf482c..cfc8d334 100644 --- a/src/dlangui/widgets/menu.d +++ b/src/dlangui/widgets/menu.d @@ -42,6 +42,17 @@ enum MenuItemType { Submenu } +/// interface to handle menu item click +interface MenuItemClickHandler { + bool onMenuItemClick(MenuItem item); +} + +/// interface to handle menu item action +interface MenuItemActionHandler { + bool onMenuItemAction(const Action action); +} + + /// menu item properties class MenuItem { protected bool _checked; @@ -50,7 +61,11 @@ class MenuItem { protected Action _action; protected MenuItem[] _subitems; protected MenuItem _parent; - /// item action id, 0 if no action + /// handle menu item click (parameter is MenuItem) + Signal!MenuItemClickHandler onMenuItemClick; + /// handle menu item click action (parameter is Action) + Signal!MenuItemActionHandler onMenuItemAction; + /// item action id, 0 if no action @property int id() { return _action is null ? 0 : _action.id; } /// returns count of submenu items @property int subitemCount() { @@ -345,14 +360,6 @@ class MenuItemWidget : WidgetGroup { } } -interface MenuItemClickHandler { - bool onMenuItemClick(MenuItem item); -} - -interface MenuItemActionHandler { - bool onMenuItemAction(const Action action); -} - /// base class for menus class MenuWidgetBase : ListWidget { protected MenuWidgetBase _parentMenu; @@ -496,6 +503,10 @@ class MenuWidgetBase : ListWidget { } else if (item.type == MenuItemType.Radio) { item.checked = true; } + if (item.onMenuItemClick.assigned) + item.onMenuItemClick(item); + if (item.onMenuItemAction.assigned && item.action) + item.onMenuItemAction(item.action); } protected void onMenuItem(MenuItem item) { diff --git a/src/dlangui/widgets/widget.d b/src/dlangui/widgets/widget.d index c2058039..abc2d789 100644 --- a/src/dlangui/widgets/widget.d +++ b/src/dlangui/widgets/widget.d @@ -440,7 +440,7 @@ class Widget { /// sets widget content text (override to support this) @property Widget text(dstring s) { return this; } /// sets widget content text (override to support this) - @property Widget text(ref UIString s) { return this; } + @property Widget text(UIString s) { return this; } //================================================================== // Layout and drawing related methods