Skip to content

Commit

Permalink
BREAKING CHANGES! Renamed several interfaces and methods to conform t…
Browse files Browse the repository at this point in the history
…o Go naming conventions. Gometalinter now gives 0 warnings.

Sorry. Better sooner than later. The changes are the following:
    -Comp
        -Id() => ID()
    -Container
        -ById() => ByID()
    -HasUrl => HasURL
        -Url() => URL()
        -SetUrl() => SetURL()
    -Html => HTML
        -NewHtml() => NewHTML()
        -Html() => HTML()
        -SetHtml() => SetHTML()
    -Server
        -AppUrl() => AppURL()
        -AddRootHeadHtml() => AddRootHeadHTML()
        -RemoveRootHeadHtml() => RemoveRootHeadHTML()
    -Session
        -Id() => ID()
    -Window
        -AddHeadHtml() => AddHeadHTML()
        -RemoveHeadHtml() => RemoveHeadHTML()
        -SetFocusedCompId() => SetFocusedCompID()
  • Loading branch information
icza committed Jan 16, 2017
1 parent 6189167 commit d510007
Show file tree
Hide file tree
Showing 23 changed files with 198 additions and 172 deletions.
6 changes: 3 additions & 3 deletions _examples/login/login_demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func buildLoginWin(s gwu.Session) {
p.CellFmt(l).Style().SetHeightPx(200)

win.Add(p)
win.SetFocusedCompId(tb.Id())
win.SetFocusedCompID(tb.ID())

p = gwu.NewPanel()
p.SetLayout(gwu.LayoutHorizontal)
Expand All @@ -310,12 +310,12 @@ func buildLoginWin(s gwu.Session) {
type sessHandler struct{}

func (h sessHandler) Created(s gwu.Session) {
fmt.Println("SESSION created:", s.Id())
fmt.Println("SESSION created:", s.ID())
buildLoginWin(s)
}

func (h sessHandler) Removed(s gwu.Session) {
fmt.Println("SESSION removed:", s.Id())
fmt.Println("SESSION removed:", s.ID())
}

func main() {
Expand Down
2 changes: 1 addition & 1 deletion _examples/showcase/showcasecore/showcase_gae.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package showcasecore

func init() {
extraHeadHtmls = []string{analyticsTrackingCode}
extraHeadHTMLs = []string{analyticsTrackingCode}
StartServer("")
}

Expand Down
27 changes: 14 additions & 13 deletions _examples/showcase/showcasecore/showcasecore.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ package showcasecore

import (
"fmt"
"github.com/icza/gowut/gwu"
"log"
"time"

"github.com/icza/gowut/gwu"
)

// plural returns an empty string if i is equal to 1,
Expand Down Expand Up @@ -500,20 +501,20 @@ func buildButtonDemo(event gwu.Event) gwu.Comp {
return p
}

func buildHtmlDemo(event gwu.Event) gwu.Comp {
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>`
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:"))
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)
h := gwu.NewHTML(html)
p.Add(h)

return p
Expand Down Expand Up @@ -677,21 +678,21 @@ type demo struct {
}
type pdemo *demo

var extraHeadHtmls []string
var extraHeadHTMLs []string

func buildShowcaseWin(sess gwu.Session) {
win := gwu.NewWindow("show", "Showcase of Features - Gowut")
for _, headHtml := range extraHeadHtmls {
win.AddHeadHtml(headHtml)
for _, headHTML := range extraHeadHTMLs {
win.AddHeadHTML(headHTML)
}

win.Style().SetFullSize()
win.AddEHandlerFunc(func(e gwu.Event) {
switch e.Type() {
case gwu.ETypeWinLoad:
log.Println("LOADING window:", e.Src().Id())
log.Println("LOADING window:", e.Src().ID())
case gwu.ETypeWinUnload:
log.Println("UNLOADING window:", e.Src().Id())
log.Println("UNLOADING window:", e.Src().ID())
}
}, gwu.ETypeWinLoad, gwu.ETypeWinUnload)

Expand Down Expand Up @@ -812,7 +813,7 @@ func buildShowcaseWin(sess gwu.Session) {
l.Style().SetFontWeight(gwu.FontWeightBold)
links.Add(l)
createDemo("Button", buildButtonDemo)
createDemo("Html", buildHtmlDemo)
createDemo("HTML", buildHTMLDemo)
createDemo("Image", buildImageDemo)
createDemo("Label", buildLabelDemo)
createDemo("Link", buildLinkDemo)
Expand Down Expand Up @@ -865,8 +866,8 @@ func (h sessHandler) Removed(s gwu.Session) {}
func StartServer(appName string) {
// Create GUI server
server := gwu.NewServer(appName, "")
for _, headHtml := range extraHeadHtmls {
server.AddRootHeadHtml(headHtml)
for _, headHTML := range extraHeadHTMLs {
server.AddRootHeadHTML(headHTML)
}
server.AddStaticDir("/asdf", "w:/")
server.SetText("Gowut - Showcase of Features")
Expand Down
14 changes: 7 additions & 7 deletions gwu/comp.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ type Container interface {
// Parent() method will return nil.
Remove(c Comp) bool

// ById finds a component (recursively) by its ID and returns it.
// ByID finds a component (recursively) by its ID and returns it.
// nil is returned if no child component is found (recursively)
// with the specified ID.
ById(id ID) Comp
ByID(id ID) Comp

// Clear clears the container, removes all child components.
Clear()
}

// Comp interface: the base of all UI components.
type Comp interface {
// Id returns the unique id of the component
Id() ID
// ID returns the unique id of the component
ID() ID

// Equals tells if this component is equal to the specified another component.
Equals(c2 Comp) bool
Expand Down Expand Up @@ -141,16 +141,16 @@ type compImpl struct {
// JavaScript code which when evaluated provides the component's
// value. Pass an empty string if the component does not have a value.
func newCompImpl(valueProviderJs []byte) compImpl {
id := nextCompId()
id := nextCompID()
return compImpl{id: id, attrs: map[string]string{"id": id.String()}, styleImpl: newStyleImpl(), valueProviderJs: valueProviderJs}
}

func (c *compImpl) Id() ID {
func (c *compImpl) ID() ID {
return c.id
}

func (c *compImpl) Equals(c2 Comp) bool {
return c.id == c2.Id()
return c.id == c2.ID()
}

func (c *compImpl) Parent() Container {
Expand Down
28 changes: 14 additions & 14 deletions gwu/comp_addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,35 +92,35 @@ func (c *hasEnabledImpl) renderEnabled(w Writer) {
}
}

// HasUrl interface defines a URL string property.
type HasUrl interface {
// HasURL interface defines a URL string property.
type HasURL interface {
// URL returns the URL string.
Url() string
URL() string

// SetUrl sets the URL string.
SetUrl(url string)
// SetURL sets the URL string.
SetURL(url string)
}

// newHasUrlImpl creates a new hasUrlImpl
func newHasUrlImpl(url string) hasUrlImpl {
return hasUrlImpl{url}
// newHasURLImpl creates a new hasUrlImpl
func newHasURLImpl(url string) hasURLImpl {
return hasURLImpl{url}
}

// HasUrl implementation.
type hasUrlImpl struct {
// HasURL implementation.
type hasURLImpl struct {
url string // The URL string
}

func (c *hasUrlImpl) Url() string {
func (c *hasURLImpl) URL() string {
return c.url
}

func (c *hasUrlImpl) SetUrl(url string) {
func (c *hasURLImpl) SetURL(url string) {
c.url = url
}

// renderUrl renders the URL string.
func (c *hasUrlImpl) renderUrl(attr string, w Writer) {
// renderURL renders the URL string.
func (c *hasURLImpl) renderURL(attr string, w Writer) {
w.WriteAttr(attr, c.url)
}

Expand Down
12 changes: 6 additions & 6 deletions gwu/css.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ const (
ThemeDebug = "debug" // Debug CSS theme, useful for developing/debugging purposes.
)

// resNameStaticCss returns the CSS resource name
// resNameStaticCSS returns the CSS resource name
// for the specified CSS theme.
func resNameStaticCss(theme string) string {
func resNameStaticCSS(theme string) string {
// E.g. "gowut-default-0.8.0.css"
return "gowut-" + theme + "-" + GowutVersion + ".css"
}

var staticCss map[string][]byte = make(map[string][]byte)
var staticCSS = make(map[string][]byte)

func init() {
staticCss[resNameStaticCss(ThemeDefault)] = []byte("" +
staticCSS[resNameStaticCSS(ThemeDefault)] = []byte("" +
`
.gwuimg-collapsed {background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAATUlEQVQ4y83RsQkAMAhEURNc+iZw7KQNgnjGRlv5D0SRMQPgADjVbr3AuzCz1QJYKAUyiAYiqAx4aHe/p9XAn6C/IQ1kb9TfMATYcM5cL5cg3qDaS5UAAAAASUVORK5CYII=)}
.gwuimg-expanded {background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAATElEQVQ4y2NgGGjACGNUVlb+J0Vje3s7IwMDAwMT1VxAiitgtlPfBcS4Atl22rgAnyvQbaedC7C5ApvtVHEBXlBZWfmfUKwwMQx5AADNQhjmAryM3wAAAABJRU5ErkJggg==)}
Expand Down Expand Up @@ -68,7 +68,7 @@ body {font-family:Arial}
.gwu-PasswBox {}
.gwu-Html {}
.gwu-HTML {}
.gwu-SwitchButton {}
.gwu-SwitchButton-On-Active {background:#00a000; color:#d0ffd0}
Expand Down Expand Up @@ -96,7 +96,7 @@ body {font-family:Arial}
.gwu-SessMonitor-Expired, .gwu-SessMonitor-Error {color:red}
`)

staticCss[resNameStaticCss(ThemeDebug)] = []byte(string(staticCss[resNameStaticCss(ThemeDefault)]) +
staticCSS[resNameStaticCSS(ThemeDebug)] = []byte(string(staticCSS[resNameStaticCSS(ThemeDefault)]) +
`
.gwu-Window td, .gwu-Table td, .gwu-Panel td, .gwu-TabPanel td {border:1px solid black}
`)
Expand Down
6 changes: 3 additions & 3 deletions gwu/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ The UI can be simply assembled hierarchically from containers
and components. Components can generate events which are dispatched
to event handlers - also written in pure Go.
If there is no component for an HTML tag you wish to use, you can
use the Html component to wrap your custom HTML code. Components also allow
use the HTML component to wrap your custom HTML code. Components also allow
you to specify custom HTML attributes that will be added for their
(wrapper) HTML tags.
Expand Down Expand Up @@ -226,7 +226,7 @@ Input components to get data from users:
Other components:
Button
Html
HTML
Image
Label
Link
Expand Down Expand Up @@ -397,6 +397,6 @@ package gwu
// Gowut version information.
const (
GowutVersion = "v1.2.0-dev" // Gowut version: "v"major.minor.maintenance[-dev]
GowutReleaseDate = "2016-09-06 CET" // Gowut release date
GowutReleaseDate = "2017-01-16 CET" // Gowut release date
GowutRelDateLayout = "2006-01-02 MST" // Gowut release date layout (for time.Parse())
)
8 changes: 4 additions & 4 deletions gwu/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (etype EventType) Category() EventCategory {
}

// Attribute names for the general event types; only for the general event types.
var etypeAttrs map[EventType][]byte = map[EventType][]byte{
var etypeAttrs = map[EventType][]byte{
ETypeClick: []byte("onclick"),
ETypeDblClick: []byte("ondblclick"),
ETypeMousedown: []byte("onmousedown"),
Expand All @@ -98,7 +98,7 @@ var etypeAttrs map[EventType][]byte = map[EventType][]byte{
ETypeFocus: []byte("onfocus")}

// Function names for window event types.
var etypeFuncs map[EventType][]byte = map[EventType][]byte{
var etypeFuncs = map[EventType][]byte{
ETypeWinLoad: []byte("onload"),
ETypeWinUnload: []byte("onbeforeunload")} // Bind it to onbeforeunload (instead of onunload) for several reasons (onunload might cause trouble for AJAX; onunload is not called in IE if page is just refreshed...)

Expand Down Expand Up @@ -412,7 +412,7 @@ func (e *eventImpl) MarkDirty(comps ...Comp) {
}
}

shared.dirtyComps[comp.Id()] = comp
shared.dirtyComps[comp.ID()] = comp
}
}
}
Expand All @@ -425,7 +425,7 @@ func (e *eventImpl) MarkDirty(comps ...Comp) {
// its inherited dirty flag changes from true to false.
func (s *sharedEvtData) dirty(c2 Comp) bool {
// First-class being dirty:
if _, found := s.dirtyComps[c2.Id()]; found {
if _, found := s.dirtyComps[c2.ID()]; found {
return true
}

Expand Down
10 changes: 5 additions & 5 deletions gwu/expander.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,28 +97,28 @@ func (c *expanderImpl) Remove(c2 Comp) bool {
return false
}

func (c *expanderImpl) ById(id ID) Comp {
func (c *expanderImpl) ByID(id ID) Comp {
if c.id == id {
return c
}

if c.header != nil {
if c.header.Id() == id {
if c.header.ID() == id {
return c.header
}
if c2, isContainer := c.header.(Container); isContainer {
if c3 := c2.ById(id); c3 != nil {
if c3 := c2.ByID(id); c3 != nil {
return c3
}
}
}

if c.content != nil {
if c.content.Id() == id {
if c.content.ID() == id {
return c.content
}
if c2, isContainer := c.content.(Container); isContainer {
if c3 := c2.ById(id); c3 != nil {
if c3 := c2.ByID(id); c3 != nil {
return c3
}
}
Expand Down
26 changes: 13 additions & 13 deletions gwu/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,39 @@

package gwu

// Html interface defines a component which wraps an HTML text into a component.
// HTML interface defines a component which wraps an HTML text into a component.
//
// Default style class: "gwu-Html"
type Html interface {
// Html is a component.
// Default style class: "gwu-HTML"
type HTML interface {
// HTML is a component.
Comp

// Html returns the HTML text.
Html() string
// HTML returns the HTML text.
HTML() string

// SetHtml sets the HTML text.
SetHtml(html string)
// SetHTML sets the HTML text.
SetHTML(html string)
}

// Html implementation
// HTML implementation
type htmlImpl struct {
compImpl // Component implementation

html string // HTML text
}

// NewHtml creates a new Html.
func NewHtml(html string) Html {
// NewHTML creates a new HTML.
func NewHTML(html string) HTML {
c := &htmlImpl{newCompImpl(nil), html}
c.Style().AddClass("gwu-Html")
return c
}

func (c *htmlImpl) Html() string {
func (c *htmlImpl) HTML() string {
return c.html
}

func (c *htmlImpl) SetHtml(html string) {
func (c *htmlImpl) SetHTML(html string) {
c.html = html
}

Expand Down
Loading

0 comments on commit d510007

Please sign in to comment.