mirror of https://github.com/anoshenko/rui.git
NewApplication function and Start function of the Application interface were replaced by StartApp function
This commit is contained in:
parent
93abec1bff
commit
4692d0013a
|
@ -1,5 +1,6 @@
|
|||
# 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 the UserAgent function to the Session interface
|
||||
* Added the following properties to TableView: "selection-mode", "allow-selection", "current", "current-style", "current-inactive-style"
|
||||
|
|
|
@ -27,19 +27,24 @@ var defaultThemeText string
|
|||
|
||||
// Application - app interface
|
||||
type Application interface {
|
||||
// Start - start the application life cycle
|
||||
Start(addr string)
|
||||
Finish()
|
||||
nextSessionID() int
|
||||
removeSession(id int)
|
||||
}
|
||||
|
||||
type application struct {
|
||||
name, icon string
|
||||
params AppParams
|
||||
createContentFunc func(Session) SessionContent
|
||||
sessions map[int]Session
|
||||
}
|
||||
|
||||
// AppParams defines parameters of the app
|
||||
type AppParams struct {
|
||||
Title string
|
||||
TitleColor Color
|
||||
Icon string
|
||||
}
|
||||
|
||||
func (app *application) getStartPage() string {
|
||||
buffer := allocStringBuilder()
|
||||
defer freeStringBuilder(buffer)
|
||||
|
@ -49,12 +54,19 @@ func (app *application) getStartPage() string {
|
|||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>`)
|
||||
buffer.WriteString(app.name)
|
||||
buffer.WriteString(app.params.Title)
|
||||
buffer.WriteString("</title>")
|
||||
if app.icon != "" {
|
||||
if app.params.Icon != "" {
|
||||
buffer.WriteString(`
|
||||
<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(`">`)
|
||||
}
|
||||
|
||||
|
@ -78,9 +90,8 @@ func (app *application) getStartPage() string {
|
|||
return buffer.String()
|
||||
}
|
||||
|
||||
func (app *application) init(name, icon string) {
|
||||
app.name = name
|
||||
app.icon = icon
|
||||
func (app *application) init(params AppParams) {
|
||||
app.params = params
|
||||
app.sessions = map[int]Session{}
|
||||
}
|
||||
|
||||
|
@ -277,12 +288,14 @@ func (app *application) startSession(params DataObject, events chan DataObject,
|
|||
return session, answerText
|
||||
}
|
||||
|
||||
// NewApplication - create the new application of the single view type.
|
||||
func NewApplication(name, icon string, createContentFunc func(Session) SessionContent) Application {
|
||||
// NewApplication - create the new application and start it
|
||||
func StartApp(addr string, createContentFunc func(Session) SessionContent, params AppParams) {
|
||||
app := new(application)
|
||||
app.init(name, icon)
|
||||
app.init(params)
|
||||
app.createContentFunc = createContentFunc
|
||||
return app
|
||||
|
||||
http.Handle("/", app)
|
||||
log.Fatal(http.ListenAndServe(addr, nil))
|
||||
}
|
||||
|
||||
func OpenBrowser(url string) bool {
|
||||
|
|
11
demo/main.go
11
demo/main.go
|
@ -113,10 +113,6 @@ 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
|
||||
}
|
||||
|
||||
|
@ -158,11 +154,14 @@ func (demo *demoSession) showPage(index int) {
|
|||
func main() {
|
||||
rui.ProtocolInDebugLog = true
|
||||
rui.AddEmbedResources(&resources)
|
||||
app := rui.NewApplication("RUI demo", "icon.svg", createDemo)
|
||||
|
||||
//addr := rui.GetLocalIP() + ":8080"
|
||||
addr := "localhost:8000"
|
||||
fmt.Print(addr)
|
||||
rui.OpenBrowser("http://" + addr)
|
||||
app.Start(addr)
|
||||
rui.StartApp(addr, createDemo, rui.AppParams{
|
||||
Title: "RUI demo",
|
||||
Icon: "icon.svg",
|
||||
TitleColor: rui.Color(0xffc0ded9),
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue