mirror of
https://github.com/diamondburned/cchat-gtk.git
synced 2024-12-23 20:56:42 +00:00
41 lines
548 B
Go
41 lines
548 B
Go
package singlestack
|
|
|
|
import (
|
|
"github.com/gotk3/gotk3/gtk"
|
|
)
|
|
|
|
type Stack struct {
|
|
*gtk.Stack
|
|
current gtk.IWidget
|
|
}
|
|
|
|
func NewStack() *Stack {
|
|
stack, _ := gtk.StackNew()
|
|
return &Stack{stack, nil}
|
|
}
|
|
|
|
func (s *Stack) Add(w gtk.IWidget) {
|
|
if s.current == w {
|
|
return
|
|
}
|
|
|
|
if w != nil {
|
|
s.Stack.Add(w)
|
|
s.Stack.SetVisibleChild(w)
|
|
}
|
|
|
|
if s.current != nil {
|
|
s.Stack.Remove(s.current)
|
|
}
|
|
|
|
s.current = w
|
|
}
|
|
|
|
func (s *Stack) SetVisibleChild(w gtk.IWidget) {
|
|
s.Add(w)
|
|
}
|
|
|
|
func (s *Stack) GetChild() (gtk.IWidget, error) {
|
|
return s.current, nil
|
|
}
|