Compare commits

...

7 Commits

Author SHA1 Message Date
608a898be3 Fix deadlock in Stop 2024-08-16 17:40:39 -04:00
91a8ae2fa5 Add some new icons
Closes #23
2024-08-16 17:08:28 -04:00
cacfd20a8a Describe IconUnknown 2024-08-16 17:05:11 -04:00
d08fe845fc Add Bounds, InnerBounds to Window
Closes #22
2024-08-16 17:03:24 -04:00
e23a688103 Remove checkbox icons 2024-08-13 12:30:47 -04:00
f4cc47eb16 Fix meaningless panics 2024-08-13 12:17:54 -04:00
43fb3b8feb Remove AttrIcon
- Has no compelling use case (all use cases need the texture size
  which this attribute cannot provide)
- Duplicates functionality
- The rationale for adding it initially was never that strong
2024-08-11 22:23:42 -04:00
4 changed files with 38 additions and 28 deletions

View File

@@ -15,7 +15,6 @@ type Attr interface {
type AttrKind int; const (
AttrKindColor AttrKind = iota
AttrKindIcon
AttrKindTexture
AttrKindTextureMode
AttrKindBorder
@@ -33,9 +32,6 @@ type AttrKind int; const (
// AttrColor sets the background color of a box.
type AttrColor struct { color.Color }
// AttrIcon sets the icon of a box to a named icon. It has the same end result
// as setting the texture of a box to a centered icon texture.
type AttrIcon struct { Icon Icon; Size IconSize }
// AttrTexture sets the texture of a box to a texture.
type AttrTexture struct { canvas.Texture }
// AttrTextureMode sets the rendering mode of a box's texture.
@@ -67,10 +63,6 @@ type AttrLayout struct { Layout }
func AColor (col color.Color) AttrColor {
return AttrColor { Color: col }
}
// AIcon is a convenience constructor for the icon attribute.
func AIcon (icon Icon, size IconSize) AttrIcon {
return AttrIcon { Icon: icon, Size: size }
}
// ATexture is a convenience constructor for the texture attribute.
func ATexture (texture canvas.Texture) AttrTexture {
return AttrTexture { Texture: texture }
@@ -133,14 +125,6 @@ func (this AttrColor) Equals (other Attr) bool {
}
}
// Equals returns true if both attributes can reasonably be declared equal.
func (this AttrIcon) Equals (other Attr) bool {
if other, ok := other.(AttrIcon); ok {
return this == other
} else {
return false
}
}
// Equals returns true if both attributes can reasonably be declared equal.
func (this AttrTexture) Equals (other Attr) bool {
if other, ok := other.(AttrTexture); ok {
return this == other
@@ -251,7 +235,6 @@ func (this AttrLayout) Equals (other Attr) bool {
}
func (AttrColor) Kind () AttrKind { return AttrKindColor }
func (AttrIcon) Kind () AttrKind { return AttrKindIcon }
func (AttrTexture) Kind () AttrKind { return AttrKindTexture }
func (AttrTextureMode) Kind () AttrKind { return AttrKindTextureMode }
func (AttrBorder) Kind () AttrKind { return AttrKindBorder }
@@ -267,7 +250,6 @@ func (AttrOverflow) Kind () AttrKind { return AttrKindOverflow }
func (AttrLayout) Kind () AttrKind { return AttrKindLayout }
func (AttrColor) attr () { }
func (AttrIcon) attr () { }
func (AttrTexture) attr () { }
func (AttrTextureMode) attr () { }
func (AttrBorder) attr () { }

View File

@@ -16,6 +16,7 @@ type Icon string
// A list of standard icon IDs. This is roughly based off of the XDG Icon Naming
// Specification (https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html).
const (
// IconUnknown should be a blank space the size of a regular icon.
IconUnknown Icon = ""
// actions
@@ -90,6 +91,9 @@ const (
// actions: list
IconListAdd Icon = "ListAdd"
IconListRemove Icon = "ListRemove"
IconListChoose Icon = "ListChoose"
IconListExpand Icon = "ListExpand"
IconListContract Icon = "ListExpand"
// actions: mail
IconMailForward Icon = "MailForward"
IconMailMarkImportant Icon = "MailMarkImportant"
@@ -275,9 +279,6 @@ const (
IconPlaceHistory Icon = "PlaceHistory"
IconPlacePreferences Icon = "PlacePreferences"
// status: checkbox
IconCheckboxChecked Icon = "CheckboxChecked"
IconCheckboxUnchecked Icon = "CheckboxUnchecked"
// status: appointments
IconAppointmentMissed Icon = "AppointmentMissed"
IconAppointmentSoon Icon = "AppointmentSoon"

View File

@@ -287,6 +287,13 @@ type BoxArranger interface {
// themselves are completely transparent, and become opaque once an opaque
// object is added as their root.
type Window interface {
// Bounds returns the bounds of the window including its frame, if
// possible. This means that the top-left point of the bounds will be
// either zero or negative.
Bounds () image.Rectangle
// InnerBounds returns the inner bounds of the window, not including its
// frame. This means that the top-left point of the bounds will be zero.
InnerBounds () image.Rectangle
// SetRoot sets the root child of the window. There can only be one at
// a time, and setting it will remove the current child if there is one.
SetRoot (Object)

34
tomo.go
View File

@@ -1,24 +1,44 @@
package tomo
import "sync"
import "image"
import "git.tebibyte.media/tomo/tomo/canvas"
// Stop stops the backend, unblocking run. Run may be called again after calling
// Stop.
// TODO this really sucks. It might be a good idea to have Do be the entry point
// for every off-thread call, and Stop should just call backend.Stop within
// backend.Do. This is because Do is a queue and is not vulnerable to recursive
// locking.
var stopping bool
var stoppingLock sync.Mutex
func isStopping () bool {
stoppingLock.Lock()
defer stoppingLock.Unlock()
return stopping
}
func setStopping (is bool) {
stoppingLock.Lock()
defer stoppingLock.Unlock()
stopping = is
}
// Stop stops the currently running backend.
func Stop () {
assertBackend()
backend.Stop()
if isStopping() { return }
setStopping(true)
backendLock.Lock()
defer backendLock.Unlock()
if backend == nil { return }
backend.Stop()
backend = nil
backendLock.Unlock()
setStopping(false)
}
// Do performs a callback function in the event loop thread as soon as possible.
func Do (callback func ()) {
backendLock.Lock()
defer backendLock.Unlock()
if backend != nil { backend.Do(callback) }
backendLock.Unlock()
}
// NewWindow creates and returns a window within the specified bounds on screen.