1
0
Fork 0
forked from Mirrors/gomuks

Add rudimentary RosterView

This commit is contained in:
FIGBERT 2023-02-25 12:39:14 -08:00
parent 1f62926e0e
commit 5fae3fedb9
No known key found for this signature in database
GPG key ID: 67F1598D607A844B
2 changed files with 95 additions and 1 deletions

View file

@ -45,6 +45,7 @@ type MainView struct {
roomList *RoomList
roomView *mauview.Box
rosterView *RosterView
currentRoom *RoomView
rooms map[id.RoomID]*RoomView
roomsLock sync.RWMutex
@ -73,6 +74,7 @@ func (ui *GomuksUI) NewMainView() mauview.Component {
parent: ui,
}
mainView.roomList = NewRoomList(mainView)
mainView.rosterView = NewRosterView(mainView)
mainView.cmdProcessor = NewCommandProcessor(mainView)
mainView.flex.
@ -103,7 +105,9 @@ func (view *MainView) HideModal() {
}
func (view *MainView) Draw(screen mauview.Screen) {
if view.config.Preferences.HideRoomList {
if view.config.Preferences.DisplayMode == config.DisplayModeModern {
view.rosterView.Draw(screen)
} else if view.config.Preferences.HideRoomList {
view.roomView.Draw(screen)
} else {
view.flex.Draw(screen)

90
ui/view-roster.go Normal file
View file

@ -0,0 +1,90 @@
// gomuks - A terminal Matrix client written in Go.
// Copyright (C) 2020 Tulir Asokan
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package ui
import (
"go.mau.fi/mauview"
"go.mau.fi/tcell"
"maunium.net/go/gomuks/matrix/rooms"
"maunium.net/go/gomuks/ui/widget"
)
type RosterView struct {
mauview.Component
selected *rooms.Room
height, width int
// The item main text color.
mainTextColor tcell.Color
// The text color for selected items.
selectedTextColor tcell.Color
// The background color for selected items.
selectedBackgroundColor tcell.Color
parent *MainView
}
func NewRosterView(mainView *MainView) *RosterView {
rstr := &RosterView{
parent: mainView,
}
return rstr
}
func (rstr *RosterView) Draw(screen mauview.Screen) {
rstr.width, rstr.height = screen.Size()
y := 0
for _, room := range rstr.parent.rooms {
if room.Room.IsReplaced() {
continue
}
renderHeight := 1
if y+renderHeight >= rstr.height {
renderHeight = rstr.height - y
}
isSelected := room.Room == rstr.selected
style := tcell.StyleDefault.
Foreground(rstr.mainTextColor).
Bold(room.Room.HasNewMessages())
if isSelected {
style = style.
Foreground(rstr.selectedTextColor).
Background(rstr.selectedBackgroundColor)
}
widget.WriteLinePadded(
screen,
mauview.AlignLeft,
room.Room.GetTitle(),
0, y, rstr.width,
style,
)
y += renderHeight
if y >= rstr.height {
break
}
}
}