windowstate
import "github.com/tangoui/tango/sys/windowstate"本页由
site/tools/apigen从源码注释生成(按 darwin 构建标签选文件),请勿手改。
Package windowstate remembers where a window was: its position, size and whether it was maximized, saved as it changes and restored the next time the app starts.
s, _ := app.NewSurface(tango.SurfaceOptions{Hidden: true, Resizable: true})
windowstate.Track(s, "main", nil) // nil: <UserConfigDir>/<App.ID>/windows.json
s.Show()
Track before showing the window so it does not jump. A saved position that is no longer on any display (a monitor was unplugged) is not restored; the window keeps its size and is centered instead.
变量
var SaveDelay = 400 * time.MillisecondSaveDelay is how long Track waits after the last change before saving.
函数
func DefaultPath
func DefaultPath(appID string) (string, error)DefaultPath returns <os.UserConfigDir>/<appID>/windows.json. An empty appID uses the executable's name.
func Track
func Track(s *tango.Surface, key string, store Store) errorTrack restores s from store under key, then saves its state whenever it is moved, resized, maximized or restored, and when it closes or the app terminates. A nil store is the shared file at DefaultPath(app ID). It returns tango.ErrUnsupported when the platform cannot place windows.
类型
FileStore
type FileStore struct {
// contains filtered or unexported fields
}FileStore is a Store backed by one JSON file holding every key.
func NewFileStore
func NewFileStore(path string) *FileStoreNewFileStore returns the store for the JSON file at path. Stores for the same path are shared, so windows tracked separately do not overwrite each other's entries.
func (*FileStore) Load
func (fs *FileStore) Load(key string) (State, bool)func (*FileStore) Path
func (fs *FileStore) Path() stringPath returns the file's path.
func (*FileStore) Save
func (fs *FileStore) Save(key string, st State) errorSave records st under key and rewrites the file atomically.
State
type State struct {
X int `json:"x"`
Y int `json:"y"`
Width int `json:"width"`
Height int `json:"height"`
Maximized bool `json:"maximized,omitempty"`
}State is what is remembered of one window. X, Y, Width, Height are the normal (not maximized) bounds, as tango.Surface.Bounds returns them.
Store
type Store interface {
Load(key string) (State, bool)
Save(key string, st State) error
}Store keeps states by key. Implementations must be safe for concurrent use.