~f4814n/frost

11a4a659a3378675e98e51373c097ef52404e0c6 — Fabian Geiselhart 4 months ago c582ddc
Add navigation drawer
3 files changed, 35 insertions(+), 0 deletions(-)

M cmd/frost/main.go
M events.go
M view/roomlist/roomlist.go
M cmd/frost/main.go => cmd/frost/main.go +22 -0
@@ 3,6 3,7 @@ package main
import (
	"context"
	"net/http"
	"time"

	"gioui.org/app"
	"gioui.org/font/gofont"


@@ 14,6 15,7 @@ import (
	"git.sr.ht/~f4814n/frost"
	"git.sr.ht/~f4814n/frost/component/cache"
	"git.sr.ht/~f4814n/frost/platform"
	"git.sr.ht/~f4814n/frost/util"
	"git.sr.ht/~f4814n/frost/view/login"
	"git.sr.ht/~f4814n/frost/view/memberlist"
	"git.sr.ht/~f4814n/frost/view/roomhistory"


@@ 21,6 23,7 @@ import (
	"git.sr.ht/~f4814n/matrix"
	"git.sr.ht/~whereswaldon/materials"
	"go.uber.org/zap"
	"golang.org/x/exp/shiny/materialdesign/icons"
)

var theme *material.Theme


@@ 30,6 33,11 @@ type (
	Dims = layout.Dimensions
)

const (
	tagNavSettings byte = iota
	tagNavRooms
)

type App struct {
	window   *app.Window
	cli      *matrix.Client


@@ 44,6 52,7 @@ type App struct {
	fullID, leftID, middleID, rightID uint

	modalLayer *materials.ModalLayer
	drawer     *materials.ModalNavDrawer
}

func newApp() *App {


@@ 72,6 81,17 @@ func newApp() *App {
	}

	a.cache = cache.New(a.cli, platformCache, logger.Named("cache"))
	a.drawer = materials.NewModalNav(a.modalLayer, "Frost", "Here be dragons")
	a.drawer.AddNavItem(materials.NavItem{
		Name: "Rooms",
		Icon: util.MustIcon(icons.SocialGroup),
		Tag:  tagNavRooms,
	})
	a.drawer.AddNavItem(materials.NavItem{
		Name: "Settings",
		Icon: util.MustIcon(icons.ActionSettings),
		Tag:  tagNavSettings,
	})

	return a
}


@@ 134,6 154,8 @@ func (a *App) run() error {
				go a.login(e)
			case frost.InvalidationEvent:
				a.window.Invalidate()
			case frost.ToggleNavigation:
				a.drawer.Appear(time.Now())
			case frost.ShowRoomEvent:
				if a.middle != nil {
					a.middle.Stop()

M events.go => events.go +4 -0
@@ 29,3 29,7 @@ func (s InvalidationEvent) FrostEvent() {}
type BackEvent struct{}

func (s BackEvent) FrostEvent() {}

type ToggleNavigation struct{}

func (s ToggleNavigation) FrostEvent() {}

M view/roomlist/roomlist.go => view/roomlist/roomlist.go +9 -0
@@ 19,6 19,7 @@ import (
	fwidget "git.sr.ht/~f4814n/frost/widget"
	"git.sr.ht/~f4814n/matrix"
	"git.sr.ht/~whereswaldon/materials"
	"golang.org/x/exp/shiny/materialdesign/icons"
)

type (


@@ 44,6 45,7 @@ type view struct {
func New(cli *matrix.Client, modalLayer *materials.ModalLayer, theme *material.Theme, logger *zap.Logger) frost.View {
	appBar := materials.NewAppBar(modalLayer)
	appBar.Title = "Frost"
	appBar.NavigationIcon = util.MustIcon(icons.NavigationMenu)

	return &view{
		cli:          cli,


@@ 82,6 84,13 @@ func (l *view) update(gtx g) {
		}
	}

	for _, event := range l.appBar.Events(gtx) {
		switch event.(type) {
		case materials.AppBarNavigationClicked:
			l.tx <- frost.ToggleNavigation{}
		}
	}

	for {
		select {
		case <-l.rx: