Added SetTitle and SetTitleColor functions to the Session

This commit is contained in:
anoshenko 2021-11-10 16:26:19 +03:00
parent 2288487f75
commit d9b33167be
5 changed files with 45 additions and 0 deletions

View File

@ -4233,6 +4233,10 @@ Safari и Firefox.
* RootView() View - возвращает корневой View сессии
* SetTitle(title string) - устанавливает текст заголовка окна/закладки браузера.
* SetTitleColor(color Color) устанавливает цвет панели навигации браузера. Поддерживается только в Safari и Chrome для Android.
* Get(viewID, tag string) interface{} - возвращает значение свойства View с именем tag. Эквивалентно
rui.Get(session.RootView(), viewID, tag)

View File

@ -4198,6 +4198,10 @@ Returns false if no topic with this name was found. Themes named "" are the defa
* RootView() View returns the root View of the session
* SetTitle(title string) sets the text of the browser title/tab
* SetTitleColor(color Color) sets the color of the browser navigation bar. Supported only in Safari and Chrome for android
* Get(viewID, tag string) interface{} returns the value of the View property named tag. Equivalent to
rui.Get(session.RootView(), viewID, tag)

View File

@ -1336,3 +1336,19 @@ function startDowndload(url, filename) {
element.click();
}
}
function setTitleColor(color) {
var metas = document.getElementsByTagName('meta');
if (metas) {
var item = metas.namedItem('theme-color');
if (item) {
item.setAttribute('content', color)
return
}
}
var meta = document.createElement('meta');
meta.setAttribute('name', 'theme-color');
meta.setAttribute('content', color);
document.getElementsByTagName('head')[0].appendChild(meta);
}

View File

@ -113,6 +113,9 @@ func (demo *demoSession) CreateRootView(session rui.Session) rui.View {
rui.Set(demo.rootView, "rootTitleButton", rui.ClickEvent, demo.clickMenuButton)
demo.showPage(0)
if color, ok := rui.StringToColor("#ffc0ded9"); ok {
session.SetTitleColor(color)
}
return demo.rootView
}
@ -147,6 +150,7 @@ func (demo *demoSession) showPage(index int) {
stackLayout.MoveToFront(demo.pages[index].view)
}
rui.Set(demo.rootView, "rootTitleText", rui.Text, demo.pages[index].title)
demo.rootView.Session().SetTitle(demo.pages[index].title)
}
// TODO
}

View File

@ -40,9 +40,15 @@ type Session interface {
// GetString returns the text for the current language
GetString(tag string) (string, bool)
// Content returns the SessionContent of session
Content() SessionContent
setContent(content SessionContent, self Session) bool
// SetTitle sets the text of the browser title/tab
SetTitle(title string)
// SetTitleColor sets the color of the browser navigation bar. Supported only in Safari and Chrome for android
SetTitleColor(color Color)
// RootView returns the root view of the session
RootView() View
// Get returns a value of the view (with id defined by the first argument) property with name defined by the second argument.
@ -53,7 +59,9 @@ type Session interface {
// a description of the error is written to the log
Set(viewID, tag string, value interface{}) bool
// DownloadFile downloads (saves) on the client side the file located at the specified path on the server.
DownloadFile(path string)
//DownloadFileData downloads (saves) on the client side a file with a specified name and specified content.
DownloadFileData(filename string, data []byte)
registerAnimation(props []AnimatedProperty) string
@ -406,3 +414,12 @@ func (session *sessionData) handleViewEvent(command string, data DataObject) {
ErrorLog(`"id" property not found. Event: ` + command)
}
}
func (session *sessionData) SetTitle(title string) {
title, _ = session.GetString(title)
session.runScript(`document.title = "` + title + `";`)
}
func (session *sessionData) SetTitleColor(color Color) {
session.runScript(`setTitleColor("` + color.cssString() + `");`)
}