Skip to content

Commit

Permalink
Merging files of release 0.8.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
iczaaa committed Feb 19, 2013
1 parent b853418 commit cd510f6
Show file tree
Hide file tree
Showing 25 changed files with 969 additions and 406 deletions.
514 changes: 312 additions & 202 deletions examples/showcase.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions gwu/button.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ type buttonImpl struct {

// NewButton creates a new Button.
func NewButton(text string) Button {
c := newButtonImpl("", text)
c := newButtonImpl(nil, text)
c.Style().AddClass("gwu-Button")
return &c
}

// newButtonImpl creates a new buttonImpl.
func newButtonImpl(valueProviderJs string, text string) buttonImpl {
func newButtonImpl(valueProviderJs []byte, text string) buttonImpl {
return buttonImpl{newCompImpl(valueProviderJs), newHasTextImpl(text), newHasEnabledImpl()}
}

Expand Down
25 changes: 12 additions & 13 deletions gwu/comp.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,16 @@ type compImpl struct {
attrs map[string]string // Explicitly set HTML attributes for the component's wrapper tag.
styleImpl *styleImpl // Style builder.

handlers map[EventType][]EventHandler // Event handlers mapped from even type. Lazily initialized.
valueProviderJs string // If the HTML representation of the component has a value, this JavaScript code code must provide it. It will be automatically sent as the PARAM_COMP_ID parameter.
handlers map[EventType][]EventHandler // Event handlers mapped from event type. Lazily initialized.
valueProviderJs []byte // If the HTML representation of the component has a value, this JavaScript code code must provide it. It will be automatically sent as the PARAM_COMP_ID parameter.
syncOnETypes map[EventType]bool // Tells on which event types should comp value sync happen.
}

// newCompImpl creates a new compImpl.
// If the component has a value, the valueProviderJs must be a
// 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 string) compImpl {
func newCompImpl(valueProviderJs []byte) compImpl {
id := nextCompId()
return compImpl{id: id, attrs: map[string]string{"id": id.String()}, styleImpl: newStyleImpl(), valueProviderJs: valueProviderJs}
}
Expand Down Expand Up @@ -239,9 +239,6 @@ func (c *compImpl) AddEHandlerFunc(hf func(e Event), etypes ...EventType) {
}

func (c *compImpl) HandlersCount(etype EventType) int {
if c.handlers == nil {
return 0
}
return len(c.handlers[etype])
}

Expand Down Expand Up @@ -279,17 +276,22 @@ var (
// rendrenderEventHandlers renders the event handlers as attributes.
func (c *compImpl) renderEHandlers(w writer) {
for etype, _ := range c.handlers {
// To render : se(event,etype,compId,value)
// Example (checkbox): se(event,0,14,this.checked)
etypeAttr := etypeAttrs[etype]
if len(etypeAttr) == 0 { // Only general events are added to the etypeAttrs map
continue
}

// To render : " <etypeAttr>=\"se(event,etype,compId,value)\""
// Example (checkbox onclick): " onclick=\"se(event,0,4327,this.checked)\""
w.Write(_STR_SPACE)
w.Write(etypeAttrs[etype])
w.Write(etypeAttr)
w.Write(_STR_SE_PREFIX)
w.Writev(int(etype))
w.Write(_STR_COMMA)
w.Writev(int(c.id))
if len(c.valueProviderJs) > 0 && c.syncOnETypes != nil && c.syncOnETypes[etype] {
w.Write(_STR_COMMA)
w.Writes(c.valueProviderJs)
w.Write(c.valueProviderJs)
}
w.Write(_STR_SE_SUFFIX)
}
Expand All @@ -301,9 +303,6 @@ func (b *compImpl) preprocessEvent(event Event, r *http.Request) {
}

func (c *compImpl) dispatchEvent(e Event) {
if c.handlers == nil {
return
}
for _, handler := range c.handlers[e.Type()] {
handler.HandleEvent(e)
}
Expand Down
11 changes: 3 additions & 8 deletions gwu/comp_addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,6 @@ func (c *cellFmtImpl) Style() Style {
}

func (c *cellFmtImpl) attr(name string) string {
if c.attrs == nil {
return ""
}
return c.attrs[name]
}

Expand Down Expand Up @@ -293,10 +290,8 @@ var _STR_VALIGN = []byte("vertical-align:") // "vertical-align:"
func (c *cellFmtImpl) renderWithAligns(tag []byte, halign HAlign, valign VAlign, w writer) {
w.Write(tag)

if c.attrs != nil {
for name, value := range c.attrs {
w.WriteAttr(name, value)
}
for name, value := range c.attrs {
w.WriteAttr(name, value)
}

if halign != HA_DEFAULT {
Expand Down Expand Up @@ -369,7 +364,7 @@ func newTableViewImpl() tableViewImpl {
// Initialize hasHVAlignImpl with HA_DEFAULT and VA_DEFAULT
// so if aligns are not changed, they will not be rendered =>
// they will be inherited (from TR).
c := tableViewImpl{compImpl: newCompImpl(""), hasHVAlignImpl: newHasHVAlignImpl(HA_DEFAULT, VA_DEFAULT)}
c := tableViewImpl{compImpl: newCompImpl(nil), hasHVAlignImpl: newHasHVAlignImpl(HA_DEFAULT, VA_DEFAULT)}
c.SetCellSpacing(0)
c.SetCellPadding(0)
return c
Expand Down
2 changes: 1 addition & 1 deletion gwu/css.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

// Built-in static CSS themes of GWU.
// Built-in static CSS themes of Gowut.

package gwu

Expand Down
25 changes: 16 additions & 9 deletions gwu/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ AJAX technology is used also to refresh some parts (components) that
change (during event handling) without having to reload the whole page
to see the changes.
To quickly test it and see it in action, run the "Showcase of Features"
application by typing: (assuming you're in the root of your GOPATH)
go run src/code.google.com/p/gowut/examples/showcase.go
Features of Gowut
Expand Down Expand Up @@ -116,10 +121,11 @@ position in case of a mouse event etc.). 2) The Event is an accessor to the
Session associated with the client the event is originating from. Through
the event an event handler may access the current Session, create a new
Session or may remove it (invalidate it). 3) The event is also used
to define actions to be executed (automatically by Gowut) after the event
handling. For example if the event handler changes a component, the handler
has to mark it dirty causing it to be re-rendered in the client browser,
or an event handler can change the focused component, or reload another window.
to define actions to be executed (automatically by Gowut) after the event
handling (post-event actions). For example if the event handler changes
a component, the handler has to mark it dirty causing it to be re-rendered
in the client browser, or an event handler can change the focused component,
or reload another window.
Creating a session from an event handler during event dispatching requires
a public window and an event source component (e.g. a Button).
Expand All @@ -131,7 +137,7 @@ SessionHandler can be used then to create the window prior to it being served.
Here's an example how to do it:
// A SessionHandler implementation:
type MySessHandler struct {}
func (h SessHandler) Created(sess gwu.Session) {
func (h SessHandler) Created(s gwu.Session) {
win := gwu.NewWindow("login", "Login Window")
// ...add content to the login window...
s.AddWindow(win)
Expand Down Expand Up @@ -160,7 +166,7 @@ When a component generates an event, the page in the browser will make an
AJAX call sending the event to the server. The event will be passed to all the
appropriate event handlers. Event handlers can mark components dirty,
specifying that they may have changed and they must be re-rendered.
When all the even handlers are done, the ids of the dirty components are sent
When all the event handlers are done, the ids of the dirty components are sent
back, and the browser will request only to render the dirty components,
with AJAX calls, and the results will replace the old component nodes in the
HTML DOM.
Expand Down Expand Up @@ -224,13 +230,14 @@ Other components:
Image
Label
Link
Timer
Full application example
Let a full example follow here which is a complete application.
It builds a simple window, adds components to it, registers event handlers which
modifies the content and starts the GUI server.
modify the content and starts the GUI server.
Component modifications (including both individual components and component
structure) will be seen without page reload.
All written in Go.
Expand Down Expand Up @@ -388,7 +395,7 @@ package gwu

// Gowut version information.
const (
GOWUT_VERSION = "0.7.0" // Gowut version (major.minor.maintenance)
GOWUT_RELEASE_DATE = "2013-02-12 CET" // Gowut release date
GOWUT_VERSION = "0.8.0" // Gowut version (major.minor.maintenance)
GOWUT_RELEASE_DATE = "2013-02-19 CET" // Gowut release date
GOWUT_REL_DATE_LAYOUT = "2006-01-02 MST" // Gowut release date layout (for time.Parse())
)
Loading

0 comments on commit cd510f6

Please sign in to comment.