Skip to content

Commit

Permalink
Initial drop of GXUI
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-clayton committed Feb 26, 2015
1 parent 27d6805 commit abe1063
Show file tree
Hide file tree
Showing 191 changed files with 16,881 additions and 0 deletions.
25 changes: 25 additions & 0 deletions adapter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package gxui

import (
"gaze/gxui/math"
)

const InvalidAdapterItemId AdapterItemId = 0xFFFFFFFFFFFFFFFF

type AdapterItemId uint64

func (i AdapterItemId) IsValid() bool { return i != InvalidAdapterItemId }

type Adapter interface {
ItemSize(theme Theme) math.Size
Count() int
ItemId(index int) AdapterItemId
ItemIndex(id AdapterItemId) int
Create(theme Theme, index int) Control
OnDataChanged(func()) EventSubscription
OnDataReplaced(func()) EventSubscription
}
35 changes: 35 additions & 0 deletions adapter_base.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package gxui

type AdapterBase struct {
onDataChanged, onDataReplaced Event
}

func (a *AdapterBase) DataChanged() {
if a.onDataChanged != nil {
a.onDataChanged.Fire()
}
}

func (a *AdapterBase) DataReplaced() {
if a.onDataReplaced != nil {
a.onDataReplaced.Fire()
}
}

func (a *AdapterBase) OnDataChanged(f func()) EventSubscription {
if a.onDataChanged == nil {
a.onDataChanged = CreateEvent(func() {})
}
return a.onDataChanged.Listen(f)
}

func (a *AdapterBase) OnDataReplaced(f func()) EventSubscription {
if a.onDataReplaced == nil {
a.onDataReplaced = CreateEvent(func() {})
}
return a.onDataReplaced.Listen(f)
}
21 changes: 21 additions & 0 deletions alignment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package gxui

type HorizontalAlignment int

const (
AlignLeft HorizontalAlignment = iota
AlignCenter
AlignRight
)

type VerticalAlignment int

const (
AlignTop VerticalAlignment = iota
AlignMiddle
AlignBottom
)
90 changes: 90 additions & 0 deletions assert/assert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package assert

import (
"fmt"
"reflect"
"runtime"
)

const debugAssertsEnabled = true

func err(msg string, args ...interface{}) {
if args != nil {
msg = fmt.Sprintf(msg, args...)
}
_, file, line, _ := runtime.Caller(2)
panic(fmt.Errorf("%s:%d %s\n", file, line, msg))
}

func Assert(msg string, args ...interface{}) {
if debugAssertsEnabled && args != nil {
msg = fmt.Sprintf(msg, args...)
}
err("ASSERT: %s", msg)
}

func NoError(e error) {
if debugAssertsEnabled && e != nil {
err("ASSERT: Error '%s' returned", e.Error())
}
}

func True(v bool, msg string, args ...interface{}) {
if debugAssertsEnabled && !v {
if args != nil {
msg = fmt.Sprintf(msg, args...)
}
err("ASSERT: %s", msg)
}
}

func False(v bool, msg string, args ...interface{}) {
if debugAssertsEnabled && v {
if args != nil {
msg = fmt.Sprintf(msg, args...)
}
err("ASSERT: %s", msg)
}
}

func safeIsNil(x interface{}) bool {
v := reflect.ValueOf(x)
switch v.Type().Kind() {
case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
return v.IsNil()
default:
return false
}
}

func NotNil(v interface{}, name string, args ...interface{}) {
if debugAssertsEnabled && v == nil || safeIsNil(v) {
if args != nil {
name = fmt.Sprintf(name, args...)
}
err("ASSERT: %s was nil\n", name)
}
}

func Nil(v interface{}, name string, args ...interface{}) {
if debugAssertsEnabled && v != nil && !safeIsNil(v) {
if args != nil {
name = fmt.Sprintf(name, args...)
}
err("ASSERT: %s was not nil. Got: %+v (type: %T)\n", name, v, v)
}
}

func Equals(expected, actual interface{}, name string, args ...interface{}) {
if debugAssertsEnabled && expected != actual {
if args != nil {
name = fmt.Sprintf(name, args...)
}
err("ASSERT: %s was not the expected value.\nExpected: %+v (type: %T)\nGot: %+v (type: %T)\n",
name, expected, expected, actual, actual)
}
}
18 changes: 18 additions & 0 deletions brush.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package gxui

var WhiteBrush = CreateBrush(White)
var TransparentBrush = CreateBrush(Transparent)
var BlackBrush = CreateBrush(Black)
var DefaultBrush = WhiteBrush

type Brush struct {
Color Color
}

func CreateBrush(color Color) Brush {
return Brush{color}
}
15 changes: 15 additions & 0 deletions bubble_overlay.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package gxui

import (
"gaze/gxui/math"
)

type BubbleOverlay interface {
Control
Show(control Control, target math.Point)
Hide()
}
22 changes: 22 additions & 0 deletions button.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package gxui

type ButtonType int

const (
PushButton ButtonType = iota
ToggleButton
)

type Button interface {
LinearLayout
Text() string
SetText(string)
Type() ButtonType
SetType(ButtonType)
IsChecked() bool
SetChecked(bool)
}
27 changes: 27 additions & 0 deletions canvas.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package gxui

import (
"gaze/gxui/math"
)

type Canvas interface {
Size() math.Size
Complete()
Push()
Pop()
AddClip(math.Rect)
Clear(Color)
DrawCanvas(c Canvas, position math.Point)
DrawTexture(t Texture, bounds math.Rect)
DrawText(Font, string, Color, math.Rect, HorizontalAlignment, VerticalAlignment)
DrawRunes(font Font, runes []rune, color Color, points []math.Point, origin math.Point)
DrawLines(Polygon, Pen)
DrawPolygon(Polygon, Pen, Brush)
DrawRect(math.Rect, Brush)
DrawRoundedRect(rect math.Rect, tl, tr, bl, br float32, p Pen, b Brush)
Release()
}
50 changes: 50 additions & 0 deletions channeled_event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package gxui

import (
"reflect"
"sync"
)

type ChanneledEvent struct {
sync.RWMutex
base EventBase
channel chan func()
}

func CreateChanneledEvent(signature interface{}, channel chan func()) Event {
e := &ChanneledEvent{
channel: channel,
}
e.base.init(signature)
baseUnlisten := e.base.unlisten
e.base.unlisten = func(id int) {
e.RLock()
baseUnlisten(id)
e.RUnlock()
}
return e
}

func (e *ChanneledEvent) Fire(args ...interface{}) {
e.base.VerifyArguments(args)
e.channel <- func() {
e.RLock()
e.base.InvokeListeners(args)
e.RUnlock()
}
}

func (e *ChanneledEvent) Listen(listener interface{}) EventSubscription {
e.Lock()
res := e.base.Listen(listener)
e.Unlock()
return res
}

func (e *ChanneledEvent) ParameterTypes() []reflect.Type {
return e.base.ParameterTypes()
}
30 changes: 30 additions & 0 deletions code_editor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package gxui

import "gaze/gxui/interval"

type CodeSuggestion interface {
Name() string
Code() string
}

type CodeSuggestionProvider interface {
SuggestionsAt(runeIndex int) []CodeSuggestion
}

type CodeEditor interface {
TextBox
SetSyntaxLayer(index int, layer CodeSyntaxLayer)
ClearSyntaxLayers()
TabWidth() int
SetTabWidth(int)
SpanAt(layerIdx, runeIdx int) *interval.IntData
SpansAt(runeIdx int) []interval.IntData
SuggestionProvider() CodeSuggestionProvider
SetSuggestionProvider(CodeSuggestionProvider)
ShowSuggestionList()
HideSuggestionList()
}
Loading

0 comments on commit abe1063

Please sign in to comment.