forked from google/gxui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27d6805
commit abe1063
Showing
191 changed files
with
16,881 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
Oops, something went wrong.