mirror of https://github.com/buggins/dlangui.git
use dstring for windowCaption property; example1: change window caption according to currently selected tab
This commit is contained in:
parent
23a228889a
commit
c95a45083b
|
@ -119,6 +119,10 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
|
|
||||||
static if (true) {
|
static if (true) {
|
||||||
VerticalLayout contentLayout = new VerticalLayout();
|
VerticalLayout contentLayout = new VerticalLayout();
|
||||||
|
|
||||||
|
//=========================================================================
|
||||||
|
// create main menu
|
||||||
|
|
||||||
MenuItem mainMenuItems = new MenuItem();
|
MenuItem mainMenuItems = new MenuItem();
|
||||||
MenuItem fileItem = new MenuItem(new Action(1, "MENU_FILE"));
|
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));
|
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);
|
contentLayout.addChild(mainMenu);
|
||||||
|
|
||||||
|
// ========= create tabs ===================
|
||||||
|
|
||||||
TabWidget tabs = new TabWidget("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);
|
tabs.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
||||||
|
|
||||||
LinearLayout layout = new LinearLayout("tab1");
|
LinearLayout layout = new LinearLayout("tab1");
|
||||||
|
|
|
@ -66,9 +66,9 @@ class Window {
|
||||||
}
|
}
|
||||||
abstract void show();
|
abstract void show();
|
||||||
/// returns window caption
|
/// returns window caption
|
||||||
abstract @property string windowCaption();
|
abstract @property dstring windowCaption();
|
||||||
/// sets window caption
|
/// sets window caption
|
||||||
abstract @property void windowCaption(string caption);
|
abstract @property void windowCaption(dstring caption);
|
||||||
/// requests layout for main widget and popups
|
/// requests layout for main widget and popups
|
||||||
void requestLayout() {
|
void requestLayout() {
|
||||||
if (_mainWidget)
|
if (_mainWidget)
|
||||||
|
@ -570,11 +570,27 @@ class Platform {
|
||||||
return _instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// create window
|
/**
|
||||||
abstract Window createWindow(string windowCaption, Window parent, uint flags = WindowFlag.Resizable);
|
* create window
|
||||||
/// close 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);
|
abstract void closeWindow(Window w);
|
||||||
|
/**
|
||||||
|
* Starts application message loop.
|
||||||
|
*
|
||||||
|
* When returned from this method, application is shutting down.
|
||||||
|
*/
|
||||||
abstract int enterMessageLoop();
|
abstract int enterMessageLoop();
|
||||||
/// retrieves text from clipboard (when mouseBuffer == true, use mouse selection clipboard - under linux)
|
/// retrieves text from clipboard (when mouseBuffer == true, use mouse selection clipboard - under linux)
|
||||||
abstract dstring getClipboardText(bool mouseBuffer = false);
|
abstract dstring getClipboardText(bool mouseBuffer = false);
|
||||||
|
@ -589,7 +605,7 @@ class Platform {
|
||||||
@property string uiLanguage() {
|
@property string uiLanguage() {
|
||||||
return _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) {
|
@property Platform uiLanguage(string langCode) {
|
||||||
if (_uiLanguage.equal(langCode))
|
if (_uiLanguage.equal(langCode))
|
||||||
return this;
|
return this;
|
||||||
|
@ -605,7 +621,7 @@ class Platform {
|
||||||
@property string uiTheme() {
|
@property string uiTheme() {
|
||||||
return _themeId;
|
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) {
|
@property Platform uiTheme(string themeResourceId) {
|
||||||
if (_themeId.equal(themeResourceId))
|
if (_themeId.equal(themeResourceId))
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -58,7 +58,7 @@ version(USE_SDL) {
|
||||||
SDLPlatform _platform;
|
SDLPlatform _platform;
|
||||||
SDL_Window * _win;
|
SDL_Window * _win;
|
||||||
SDL_Renderer* _renderer;
|
SDL_Renderer* _renderer;
|
||||||
this(SDLPlatform platform, string caption, Window parent, uint flags) {
|
this(SDLPlatform platform, dstring caption, Window parent, uint flags) {
|
||||||
_platform = platform;
|
_platform = platform;
|
||||||
_caption = caption;
|
_caption = caption;
|
||||||
debug Log.d("Creating SDL window");
|
debug Log.d("Creating SDL window");
|
||||||
|
@ -98,7 +98,7 @@ version(USE_SDL) {
|
||||||
if (_enableOpengl)
|
if (_enableOpengl)
|
||||||
windowFlags |= SDL_WINDOW_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,
|
700, 500,
|
||||||
windowFlags);
|
windowFlags);
|
||||||
version(USE_OPENGL) {
|
version(USE_OPENGL) {
|
||||||
|
@ -108,7 +108,7 @@ version(USE_SDL) {
|
||||||
_enableOpengl = false;
|
_enableOpengl = false;
|
||||||
// recreate w/o OpenGL
|
// recreate w/o OpenGL
|
||||||
windowFlags &= ~SDL_WINDOW_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,
|
700, 500,
|
||||||
windowFlags);
|
windowFlags);
|
||||||
}
|
}
|
||||||
|
@ -166,15 +166,16 @@ version(USE_SDL) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected string _caption;
|
protected dstring _caption;
|
||||||
|
|
||||||
override @property string windowCaption() {
|
override @property dstring windowCaption() {
|
||||||
return _caption;
|
return _caption;
|
||||||
}
|
}
|
||||||
|
|
||||||
override @property void windowCaption(string caption) {
|
override @property void windowCaption(dstring caption) {
|
||||||
_caption = 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
|
/// 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);
|
SDLWindow res = new SDLWindow(this, windowCaption, parent, flags);
|
||||||
_windowMap[res.windowId] = res;
|
_windowMap[res.windowId] = res;
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -175,9 +175,9 @@ class TabControl : WidgetGroup {
|
||||||
protected bool _enableCloseButton;
|
protected bool _enableCloseButton;
|
||||||
protected TabItemWidget[] _sortedItems;
|
protected TabItemWidget[] _sortedItems;
|
||||||
|
|
||||||
protected void delegate(string newActiveTabId, string previousTabId) _onTabChanged;
|
|
||||||
@property void delegate(string newActiveTabId, string previousTabId) onTabChangedListener() { return _onTabChanged; }
|
/// signal of tab change (e.g. by clicking on tab header)
|
||||||
@property TabControl onTabChangedListener(void delegate(string newActiveTabId, string previousTabId) listener) { _onTabChanged = listener; return this; }
|
Signal!TabHandler onTabChangedListener;
|
||||||
|
|
||||||
this(string ID) {
|
this(string ID) {
|
||||||
super(ID);
|
super(ID);
|
||||||
|
@ -368,8 +368,8 @@ class TabControl : WidgetGroup {
|
||||||
_children.get(i).state = State.Normal;
|
_children.get(i).state = State.Normal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_onTabChanged !is null)
|
if (onTabChangedListener.assigned)
|
||||||
_onTabChanged(_selectedTabId, previousSelectedTab);
|
onTabChangedListener(_selectedTabId, previousSelectedTab);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,16 +393,15 @@ class TabHost : FrameLayout, TabHandler {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void delegate(string newActiveTabId, string previousTabId) _onTabChanged;
|
/// signal of tab change (e.g. by clicking on tab header)
|
||||||
@property void delegate(string newActiveTabId, string previousTabId) onTabChangedListener() { return _onTabChanged; }
|
Signal!TabHandler onTabChangedListener;
|
||||||
@property TabHost onTabChangedListener(void delegate(string newActiveTabId, string previousTabId) listener) { _onTabChanged = listener; return this; }
|
|
||||||
|
|
||||||
protected override void onTabChanged(string newActiveTabId, string previousTabId) {
|
protected override void onTabChanged(string newActiveTabId, string previousTabId) {
|
||||||
if (newActiveTabId !is null) {
|
if (newActiveTabId !is null) {
|
||||||
showChild(newActiveTabId, Visibility.Invisible, true);
|
showChild(newActiveTabId, Visibility.Invisible, true);
|
||||||
}
|
}
|
||||||
if (_onTabChanged !is null)
|
if (onTabChangedListener.assigned)
|
||||||
_onTabChanged(newActiveTabId, previousTabId);
|
onTabChangedListener(newActiveTabId, previousTabId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// remove tab
|
/// remove tab
|
||||||
|
@ -465,19 +464,19 @@ class TabWidget : VerticalLayout, TabHandler {
|
||||||
super(ID);
|
super(ID);
|
||||||
_tabControl = new TabControl("TAB_CONTROL");
|
_tabControl = new TabControl("TAB_CONTROL");
|
||||||
_tabHost = new TabHost("TAB_HOST", _tabControl);
|
_tabHost = new TabHost("TAB_HOST", _tabControl);
|
||||||
|
_tabControl.onTabChangedListener.connect(this);
|
||||||
styleId = "TAB_WIDGET";
|
styleId = "TAB_WIDGET";
|
||||||
addChild(_tabControl);
|
addChild(_tabControl);
|
||||||
addChild(_tabHost);
|
addChild(_tabHost);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void delegate(string newActiveTabId, string previousTabId) _onTabChanged;
|
/// signal of tab change (e.g. by clicking on tab header)
|
||||||
@property void delegate(string newActiveTabId, string previousTabId) onTabChangedListener() { return _onTabChanged; }
|
Signal!TabHandler onTabChangedListener;
|
||||||
@property TabWidget onTabChangedListener(void delegate(string newActiveTabId, string previousTabId) listener) { _onTabChanged = listener; return this; }
|
|
||||||
|
|
||||||
protected override void onTabChanged(string newActiveTabId, string previousTabId) {
|
protected override void onTabChanged(string newActiveTabId, string previousTabId) {
|
||||||
// forward to listener
|
// forward to listener
|
||||||
if (_onTabChanged !is null)
|
if (onTabChangedListener.assigned)
|
||||||
_onTabChanged(newActiveTabId, previousTabId);
|
onTabChangedListener(newActiveTabId, previousTabId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// add new tab by id and label string resource id
|
/// add new tab by id and label string resource id
|
||||||
|
@ -485,25 +484,35 @@ class TabWidget : VerticalLayout, TabHandler {
|
||||||
_tabHost.addTab(widget, labelResourceId, iconId, enableCloseButton);
|
_tabHost.addTab(widget, labelResourceId, iconId, enableCloseButton);
|
||||||
return this;
|
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) {
|
TabWidget addTab(Widget widget, dstring label, string iconId = null, bool enableCloseButton = false) {
|
||||||
_tabHost.addTab(widget, label, iconId, enableCloseButton);
|
_tabHost.addTab(widget, label, iconId, enableCloseButton);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// remove tab by id
|
/// remove tab by id
|
||||||
TabWidget removeTab(string id) {
|
TabWidget removeTab(string id) {
|
||||||
_tabHost.removeTab(id);
|
_tabHost.removeTab(id);
|
||||||
requestLayout();
|
requestLayout();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// select tab
|
/// select tab
|
||||||
void selectTab(string ID) {
|
void selectTab(string ID) {
|
||||||
_tabHost.selectTab(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) {
|
/// returns tab item by id (null if index out of range)
|
||||||
// Log.d("TabWidget.layout() called");
|
TabItem tab(int index) {
|
||||||
// super.layout(rc);
|
return _tabControl.tab(index);
|
||||||
// Log.d("after layout(): tabhost.needLayout = ", _tabHost.needLayout);
|
}
|
||||||
// }
|
/// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue