use dstring for windowCaption property; example1: change window caption according to currently selected tab

This commit is contained in:
Vadim Lopatin 2014-05-20 08:56:21 +04:00
parent 23a228889a
commit c95a45083b
4 changed files with 75 additions and 40 deletions

View File

@ -119,6 +119,10 @@ extern (C) int UIAppMain(string[] args) {
static if (true) {
VerticalLayout contentLayout = new VerticalLayout();
//=========================================================================
// create main menu
MenuItem mainMenuItems = new MenuItem();
MenuItem fileItem = new MenuItem(new Action(1, "MENU_FILE"));
fileItem.add(new Action(10, "MENU_FILE_OPEN"c, "document-open", KeyCode.KEY_O, KeyFlag.Control));
@ -221,7 +225,12 @@ extern (C) int UIAppMain(string[] args) {
};
contentLayout.addChild(mainMenu);
// ========= create tabs ===================
TabWidget tabs = new TabWidget("TABS");
tabs.onTabChangedListener = delegate(string newTabId, string oldTabId) {
window.windowCaption = tabs.tab(newTabId).text.value ~ " - dlangui example 1"d;
};
tabs.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
LinearLayout layout = new LinearLayout("tab1");

View File

@ -66,9 +66,9 @@ class Window {
}
abstract void show();
/// returns window caption
abstract @property string windowCaption();
abstract @property dstring windowCaption();
/// sets window caption
abstract @property void windowCaption(string caption);
abstract @property void windowCaption(dstring caption);
/// requests layout for main widget and popups
void requestLayout() {
if (_mainWidget)
@ -570,11 +570,27 @@ class Platform {
return _instance;
}
/// create window
abstract Window createWindow(string windowCaption, Window parent, uint flags = WindowFlag.Resizable);
/// close window
/**
* create window
* Args:
* windowCaption = window caption text
* parent = parent Window, or null if no parent
* flags = WindowFlag bit set, combination of Resizable, Modal, Fullscreen
*
* Window w/o Resizable nor Fullscreen will be created with size based on measurement of its content widget
*/
abstract Window createWindow(dstring windowCaption, Window parent, uint flags = WindowFlag.Resizable);
/**
* close window
*
* Closes window earlier created with createWindow()
*/
abstract void closeWindow(Window w);
/**
* Starts application message loop.
*
* When returned from this method, application is shutting down.
*/
abstract int enterMessageLoop();
/// retrieves text from clipboard (when mouseBuffer == true, use mouse selection clipboard - under linux)
abstract dstring getClipboardText(bool mouseBuffer = false);
@ -589,7 +605,7 @@ class Platform {
@property string uiLanguage() {
return _uiLanguage;
}
/// set UI language (e.g. "en", "fr", "ru")
/// set UI language (e.g. "en", "fr", "ru") - will relayout content of all windows if language has been changed
@property Platform uiLanguage(string langCode) {
if (_uiLanguage.equal(langCode))
return this;
@ -605,7 +621,7 @@ class Platform {
@property string uiTheme() {
return _themeId;
}
/// sets application UI theme
/// sets application UI theme - will relayout content of all windows if theme has been changed
@property Platform uiTheme(string themeResourceId) {
if (_themeId.equal(themeResourceId))
return this;

View File

@ -58,7 +58,7 @@ version(USE_SDL) {
SDLPlatform _platform;
SDL_Window * _win;
SDL_Renderer* _renderer;
this(SDLPlatform platform, string caption, Window parent, uint flags) {
this(SDLPlatform platform, dstring caption, Window parent, uint flags) {
_platform = platform;
_caption = caption;
debug Log.d("Creating SDL window");
@ -98,7 +98,7 @@ version(USE_SDL) {
if (_enableOpengl)
windowFlags |= SDL_WINDOW_OPENGL;
}
_win = SDL_CreateWindow(_caption.toStringz, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
_win = SDL_CreateWindow(toUTF8(_caption).toStringz, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
700, 500,
windowFlags);
version(USE_OPENGL) {
@ -108,7 +108,7 @@ version(USE_SDL) {
_enableOpengl = false;
// recreate w/o OpenGL
windowFlags &= ~SDL_WINDOW_OPENGL;
_win = SDL_CreateWindow(_caption.toStringz, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
_win = SDL_CreateWindow(toUTF8(_caption).toStringz, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
700, 500,
windowFlags);
}
@ -166,15 +166,16 @@ version(USE_SDL) {
}
protected string _caption;
protected dstring _caption;
override @property string windowCaption() {
override @property dstring windowCaption() {
return _caption;
}
override @property void windowCaption(string caption) {
override @property void windowCaption(dstring caption) {
_caption = caption;
SDL_SetWindowTitle(_win, _caption.toStringz);
if (_win)
SDL_SetWindowTitle(_win, toUTF8(_caption).toStringz);
}
/// after drawing, call to schedule redraw if animation is active
@ -711,7 +712,7 @@ version(USE_SDL) {
}
override Window createWindow(string windowCaption, Window parent, uint flags = WindowFlag.Resizable) {
override Window createWindow(dstring windowCaption, Window parent, uint flags = WindowFlag.Resizable) {
SDLWindow res = new SDLWindow(this, windowCaption, parent, flags);
_windowMap[res.windowId] = res;
return res;

View File

@ -175,9 +175,9 @@ class TabControl : WidgetGroup {
protected bool _enableCloseButton;
protected TabItemWidget[] _sortedItems;
protected void delegate(string newActiveTabId, string previousTabId) _onTabChanged;
@property void delegate(string newActiveTabId, string previousTabId) onTabChangedListener() { return _onTabChanged; }
@property TabControl onTabChangedListener(void delegate(string newActiveTabId, string previousTabId) listener) { _onTabChanged = listener; return this; }
/// signal of tab change (e.g. by clicking on tab header)
Signal!TabHandler onTabChangedListener;
this(string ID) {
super(ID);
@ -368,8 +368,8 @@ class TabControl : WidgetGroup {
_children.get(i).state = State.Normal;
}
}
if (_onTabChanged !is null)
_onTabChanged(_selectedTabId, previousSelectedTab);
if (onTabChangedListener.assigned)
onTabChangedListener(_selectedTabId, previousSelectedTab);
}
}
@ -393,16 +393,15 @@ class TabHost : FrameLayout, TabHandler {
return this;
}
protected void delegate(string newActiveTabId, string previousTabId) _onTabChanged;
@property void delegate(string newActiveTabId, string previousTabId) onTabChangedListener() { return _onTabChanged; }
@property TabHost onTabChangedListener(void delegate(string newActiveTabId, string previousTabId) listener) { _onTabChanged = listener; return this; }
/// signal of tab change (e.g. by clicking on tab header)
Signal!TabHandler onTabChangedListener;
protected override void onTabChanged(string newActiveTabId, string previousTabId) {
if (newActiveTabId !is null) {
showChild(newActiveTabId, Visibility.Invisible, true);
}
if (_onTabChanged !is null)
_onTabChanged(newActiveTabId, previousTabId);
if (onTabChangedListener.assigned)
onTabChangedListener(newActiveTabId, previousTabId);
}
/// remove tab
@ -465,19 +464,19 @@ class TabWidget : VerticalLayout, TabHandler {
super(ID);
_tabControl = new TabControl("TAB_CONTROL");
_tabHost = new TabHost("TAB_HOST", _tabControl);
_tabControl.onTabChangedListener.connect(this);
styleId = "TAB_WIDGET";
addChild(_tabControl);
addChild(_tabHost);
}
protected void delegate(string newActiveTabId, string previousTabId) _onTabChanged;
@property void delegate(string newActiveTabId, string previousTabId) onTabChangedListener() { return _onTabChanged; }
@property TabWidget onTabChangedListener(void delegate(string newActiveTabId, string previousTabId) listener) { _onTabChanged = listener; return this; }
/// signal of tab change (e.g. by clicking on tab header)
Signal!TabHandler onTabChangedListener;
protected override void onTabChanged(string newActiveTabId, string previousTabId) {
// forward to listener
if (_onTabChanged !is null)
_onTabChanged(newActiveTabId, previousTabId);
if (onTabChangedListener.assigned)
onTabChangedListener(newActiveTabId, previousTabId);
}
/// add new tab by id and label string resource id
@ -485,25 +484,35 @@ class TabWidget : VerticalLayout, TabHandler {
_tabHost.addTab(widget, labelResourceId, iconId, enableCloseButton);
return this;
}
/// add new tab by id and label (raw value)
/// add new tab by id and label (raw value)
TabWidget addTab(Widget widget, dstring label, string iconId = null, bool enableCloseButton = false) {
_tabHost.addTab(widget, label, iconId, enableCloseButton);
return this;
}
/// remove tab by id
/// remove tab by id
TabWidget removeTab(string id) {
_tabHost.removeTab(id);
requestLayout();
return this;
}
/// select tab
/// select tab
void selectTab(string ID) {
_tabHost.selectTab(ID);
}
// /// Set widget rectangle to specified value and layout widget contents. (Step 2 of two phase layout).
// override void layout(Rect rc) {
// Log.d("TabWidget.layout() called");
// super.layout(rc);
// Log.d("after layout(): tabhost.needLayout = ", _tabHost.needLayout);
// }
/// returns tab item by id (null if index out of range)
TabItem tab(int index) {
return _tabControl.tab(index);
}
/// returns tab item by id (null if not found)
TabItem tab(string id) {
return _tabControl.tab(id);
}
/// get tab index by tab id (-1 if not found)
int tabIndex(string id) {
return _tabControl.tabIndex(id);
}
}