示例#1
0
文件: showcase.go 项目: ego008/gowut
func buildHtmlDemo(event gwu.Event) gwu.Comp {
	p := gwu.NewPanel()

	html := `<span onclick="alert('Hi from Html!');">Hi! I'm inserted as HTML. Click on me!</span>`

	p.Add(gwu.NewLabel("The following HTML code is inserted after the text box as an Html component:"))
	ta := gwu.NewTextBox(html)
	ta.SetReadOnly(true)
	ta.Style().SetWidthPx(500)
	ta.SetRows(4)
	p.Add(ta)

	p.AddVSpace(20)
	h := gwu.NewHtml(html)
	p.Add(h)

	return p
}
示例#2
0
func main() {

	os.Mkdir("wikiPages", os.FileMode(os.ModeDir|0777))
	LoadFile("wikiFile.txt")
	fileName = "wikiFile.txt"

	// Create and build a window
	win := gwu.NewWindow("main", "AlfaWiki")
	//win.Style().SetFullWidth()
	win.SetHAlign(gwu.HA_CENTER)
	win.SetCellPadding(2)

	p := gwu.NewHorizontalPanel()
	//p.Style().SetBorder2(1, gwu.BRD_STYLE_SOLID, gwu.CLR_BLACK)
	p.SetCellPadding(2)

	p = gwu.NewHorizontalPanel()
	//p.Style().Set("width","100%")
	//p.Style().SetFullHeight()
	win.Add(p)

	html = gwu.NewHtml(fmt.Sprintf("MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM%v", string(blackfriday.MarkdownCommon([]byte(wikiText)))))
	html.Style().Set("width", "40%")
	html.Style().Set("min-width", "40%")
	html.Style().Set("word-break", "break-all")

	tb = gwu.NewTextBox(wikiText)
	tb.SetRows(50)
	tb.SetCols(80)
	//tb.Style().Set("width","100%")
	//tb.Style().Set("min-width","20em")
	tb.AddSyncOnETypes(gwu.ETYPE_KEY_UP)
	p.Add(tb)
	p.Add(html)

	v := gwu.NewPanel()
	//v.Style().SetFullHeight().SetBorderRight2(2, gwu.BRD_STYLE_SOLID, "#777777")
	//v.Style().Set("width","20%")
	p.Add(v)

	tb.AddEHandlerFunc(func(e gwu.Event) {
		wikiText = tb.Text()
		html.SetHtml(fmt.Sprintf("MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM%v", string(blackfriday.MarkdownCommon([]byte(tb.Text())))))
		e.MarkDirty(html)
		ioutil.WriteFile(
			fmt.Sprintf("wikiPages/%s", fileName),
			[]byte(wikiText), os.FileMode(os.O_WRONLY|os.O_CREATE|os.O_TRUNC|0777))
	}, gwu.ETYPE_CHANGE, gwu.ETYPE_KEY_UP)

	newPageBox = gwu.NewTextBox("New Page Name")
	newPageBox.SetRows(1)
	newPageBox.SetCols(20)
	v.Add(newPageBox)

	newPageButt := gwu.NewButton("New Page")
	newPageButt.AddEHandler(&NewPageHandler{text: "Not used"}, gwu.ETYPE_CLICK)
	v.Add(newPageButt)
	v.AddVSpace(20)

	files, _ := ioutil.ReadDir("wikiPages")
	for i, f := range files {
		b := gwu.NewButton(f.Name() + " " + strconv.Itoa(i))
		b.AddEHandler(&MyButtonHandler2{text: f.Name()}, gwu.ETYPE_CLICK)
		v.Add(b)
	}

	v.AddVSpace(1000)

	// Create and start a GUI server (omitting error check)
	server := gwu.NewServer("guitest", "localhost:8081")
	server.SetText("AlfaWiki")
	win.SetTheme("debug")
	win.AddHeadHtml(`<link rel="stylesheet" type="text/css" href="/mystyle.css">`)
	server.AddWin(win)

	server.Start("main") // Also opens windows list in browser

	for {

	}

}