forked from mbk-lab/rui_orig
2
0
Fork 0

NewApplication function and Start function of the Application interface were replaced by StartApp function

This commit is contained in:
Alexei Anoshenko 2022-01-29 16:25:46 -05:00
parent 93abec1bff
commit 4692d0013a
3 changed files with 32 additions and 19 deletions

View File

@ -1,5 +1,6 @@
# v0.5.0 # v0.5.0
* NewApplication function and Start function of the Application interface were replaced by StartApp function
* Added HasFocus function to the View interface * Added HasFocus function to the View interface
* Added the UserAgent function to the Session interface * Added the UserAgent function to the Session interface
* Added the following properties to TableView: "selection-mode", "allow-selection", "current", "current-style", "current-inactive-style" * Added the following properties to TableView: "selection-mode", "allow-selection", "current", "current-style", "current-inactive-style"

View File

@ -27,19 +27,24 @@ var defaultThemeText string
// Application - app interface // Application - app interface
type Application interface { type Application interface {
// Start - start the application life cycle
Start(addr string)
Finish() Finish()
nextSessionID() int nextSessionID() int
removeSession(id int) removeSession(id int)
} }
type application struct { type application struct {
name, icon string params AppParams
createContentFunc func(Session) SessionContent createContentFunc func(Session) SessionContent
sessions map[int]Session sessions map[int]Session
} }
// AppParams defines parameters of the app
type AppParams struct {
Title string
TitleColor Color
Icon string
}
func (app *application) getStartPage() string { func (app *application) getStartPage() string {
buffer := allocStringBuilder() buffer := allocStringBuilder()
defer freeStringBuilder(buffer) defer freeStringBuilder(buffer)
@ -49,12 +54,19 @@ func (app *application) getStartPage() string {
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>`) <title>`)
buffer.WriteString(app.name) buffer.WriteString(app.params.Title)
buffer.WriteString("</title>") buffer.WriteString("</title>")
if app.icon != "" { if app.params.Icon != "" {
buffer.WriteString(` buffer.WriteString(`
<link rel="icon" href="`) <link rel="icon" href="`)
buffer.WriteString(app.icon) buffer.WriteString(app.params.Icon)
buffer.WriteString(`">`)
}
if app.params.TitleColor != 0 {
buffer.WriteString(`
<meta name="theme-color" content="`)
buffer.WriteString(app.params.TitleColor.cssString())
buffer.WriteString(`">`) buffer.WriteString(`">`)
} }
@ -78,9 +90,8 @@ func (app *application) getStartPage() string {
return buffer.String() return buffer.String()
} }
func (app *application) init(name, icon string) { func (app *application) init(params AppParams) {
app.name = name app.params = params
app.icon = icon
app.sessions = map[int]Session{} app.sessions = map[int]Session{}
} }
@ -277,12 +288,14 @@ func (app *application) startSession(params DataObject, events chan DataObject,
return session, answerText return session, answerText
} }
// NewApplication - create the new application of the single view type. // NewApplication - create the new application and start it
func NewApplication(name, icon string, createContentFunc func(Session) SessionContent) Application { func StartApp(addr string, createContentFunc func(Session) SessionContent, params AppParams) {
app := new(application) app := new(application)
app.init(name, icon) app.init(params)
app.createContentFunc = createContentFunc app.createContentFunc = createContentFunc
return app
http.Handle("/", app)
log.Fatal(http.ListenAndServe(addr, nil))
} }
func OpenBrowser(url string) bool { func OpenBrowser(url string) bool {

View File

@ -113,10 +113,6 @@ func (demo *demoSession) CreateRootView(session rui.Session) rui.View {
rui.Set(demo.rootView, "rootTitleButton", rui.ClickEvent, demo.clickMenuButton) rui.Set(demo.rootView, "rootTitleButton", rui.ClickEvent, demo.clickMenuButton)
demo.showPage(0) demo.showPage(0)
if color, ok := rui.StringToColor("#ffc0ded9"); ok {
session.SetTitleColor(color)
}
return demo.rootView return demo.rootView
} }
@ -158,11 +154,14 @@ func (demo *demoSession) showPage(index int) {
func main() { func main() {
rui.ProtocolInDebugLog = true rui.ProtocolInDebugLog = true
rui.AddEmbedResources(&resources) rui.AddEmbedResources(&resources)
app := rui.NewApplication("RUI demo", "icon.svg", createDemo)
//addr := rui.GetLocalIP() + ":8080" //addr := rui.GetLocalIP() + ":8080"
addr := "localhost:8000" addr := "localhost:8000"
fmt.Print(addr) fmt.Print(addr)
rui.OpenBrowser("http://" + addr) rui.OpenBrowser("http://" + addr)
app.Start(addr) rui.StartApp(addr, createDemo, rui.AppParams{
Title: "RUI demo",
Icon: "icon.svg",
TitleColor: rui.Color(0xffc0ded9),
})
} }