Skip to content

Commit

Permalink
feat: use sheet dialog instead of overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
jgillich committed Jul 12, 2024
1 parent 908c04c commit 221d296
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 68 deletions.
2 changes: 1 addition & 1 deletion api/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import (
type Column struct {
Name string
Priority int8
Bind func(listitem *gtk.ListItem, object client.Object)
Bind func(cell *gtk.ColumnViewCell, object client.Object)
Compare func(a, b client.Object) int
}
8 changes: 4 additions & 4 deletions extension/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (e *Apps) CreateColumns(ctx context.Context, resource *metav1.APIResource,
api.Column{
Name: "Status",
Priority: 70,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
listitem.SetChild(widget.ObjectStatus(object).Icon())
},
Compare: func(a, b client.Object) int {
Expand All @@ -49,7 +49,7 @@ func (e *Apps) CreateColumns(ctx context.Context, resource *metav1.APIResource,
api.Column{
Name: "Available",
Priority: 60,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
deployment := object.(*appsv1.Deployment)
label := gtk.NewLabel(fmt.Sprintf("%d/%d", deployment.Status.AvailableReplicas, deployment.Status.Replicas))
label.SetHAlign(gtk.AlignStart)
Expand All @@ -62,7 +62,7 @@ func (e *Apps) CreateColumns(ctx context.Context, resource *metav1.APIResource,
api.Column{
Name: "Status",
Priority: 70,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
listitem.SetChild(widget.ObjectStatus(object).Icon())
},
Compare: func(a, b client.Object) int {
Expand All @@ -78,7 +78,7 @@ func (e *Apps) CreateColumns(ctx context.Context, resource *metav1.APIResource,
api.Column{
Name: "Available",
Priority: 60,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
statefulSet := object.(*appsv1.StatefulSet)
label := gtk.NewLabel(fmt.Sprintf("%d/%d", statefulSet.Status.AvailableReplicas, statefulSet.Status.Replicas))
label.SetHAlign(gtk.AlignStart)
Expand Down
32 changes: 16 additions & 16 deletions extension/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (e *Core) CreateColumns(ctx context.Context, res *metav1.APIResource, colum
api.Column{
Name: "Status",
Priority: 70,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
box := gtk.NewBox(gtk.OrientationHorizontal, 4)
for _, icon := range widget.ObjectStatus(object).Icons() {
box.Append(icon)
Expand All @@ -62,7 +62,7 @@ func (e *Core) CreateColumns(ctx context.Context, res *metav1.APIResource, colum
api.Column{
Name: "Memory",
Priority: 50,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
pod := object.(*corev1.Pod)
req := resource.NewQuantity(0, resource.DecimalSI)
for _, container := range pod.Spec.Containers {
Expand All @@ -83,7 +83,7 @@ func (e *Core) CreateColumns(ctx context.Context, res *metav1.APIResource, colum
api.Column{
Name: "CPU",
Priority: 40,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
pod := object.(*corev1.Pod)
req := resource.NewQuantity(0, resource.DecimalSI)
for _, container := range pod.Spec.Containers {
Expand All @@ -107,7 +107,7 @@ func (e *Core) CreateColumns(ctx context.Context, res *metav1.APIResource, colum
api.Column{
Name: "Size",
Priority: 70,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
pvc := object.(*corev1.PersistentVolumeClaim)
label := gtk.NewLabel(pvc.Spec.Resources.Requests.Storage().String())
label.SetHAlign(gtk.AlignStart)
Expand All @@ -117,7 +117,7 @@ func (e *Core) CreateColumns(ctx context.Context, res *metav1.APIResource, colum
api.Column{
Name: "Class",
Priority: 60,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
pvc := object.(*corev1.PersistentVolumeClaim)
label := gtk.NewLabel(ptr.Deref(pvc.Spec.StorageClassName, ""))
label.SetHAlign(gtk.AlignStart)
Expand All @@ -130,7 +130,7 @@ func (e *Core) CreateColumns(ctx context.Context, res *metav1.APIResource, colum
api.Column{
Name: "Size",
Priority: 70,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
pv := object.(*corev1.PersistentVolume)
label := gtk.NewLabel(pv.Spec.Capacity.Storage().String())
label.SetHAlign(gtk.AlignStart)
Expand All @@ -140,7 +140,7 @@ func (e *Core) CreateColumns(ctx context.Context, res *metav1.APIResource, colum
api.Column{
Name: "Phase",
Priority: 70,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
pv := object.(*corev1.PersistentVolume)
label := gtk.NewLabel(string(pv.Status.Phase))
label.SetHAlign(gtk.AlignStart)
Expand All @@ -150,7 +150,7 @@ func (e *Core) CreateColumns(ctx context.Context, res *metav1.APIResource, colum
api.Column{
Name: "Claim",
Priority: 70,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
pv := object.(*corev1.PersistentVolume)
if pv.Spec.ClaimRef != nil {
label := gtk.NewLabel(string(pv.Spec.ClaimRef.Name))
Expand All @@ -166,7 +166,7 @@ func (e *Core) CreateColumns(ctx context.Context, res *metav1.APIResource, colum
api.Column{
Name: "Status",
Priority: 70,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
listitem.SetChild(widget.ObjectStatus(object).Icon())
},
Compare: func(a, b client.Object) int {
Expand All @@ -182,7 +182,7 @@ func (e *Core) CreateColumns(ctx context.Context, res *metav1.APIResource, colum
api.Column{
Name: "Pods",
Priority: 60,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
pod := object.(*corev1.Node)
var pods corev1.PodList
e.List(ctx, &pods, client.MatchingFieldsSelector{Selector: fields.OneTermEqualSelector("spec.nodeName", pod.Name)})
Expand All @@ -194,7 +194,7 @@ func (e *Core) CreateColumns(ctx context.Context, res *metav1.APIResource, colum
api.Column{
Name: "Memory",
Priority: 50,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
node := object.(*corev1.Node)
metrics := e.Metrics.Node(node.Name)
if metrics == nil {
Expand All @@ -208,7 +208,7 @@ func (e *Core) CreateColumns(ctx context.Context, res *metav1.APIResource, colum
api.Column{
Name: "CPU",
Priority: 40,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
node := object.(*corev1.Node)
metrics := e.Metrics.Node(node.Name)
if metrics == nil {
Expand All @@ -225,7 +225,7 @@ func (e *Core) CreateColumns(ctx context.Context, res *metav1.APIResource, colum
api.Column{
Name: "Phase",
Priority: 70,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
ns := object.(*corev1.Namespace)
label := gtk.NewLabel(string(ns.Status.Phase))
label.SetHAlign(gtk.AlignStart)
Expand All @@ -238,7 +238,7 @@ func (e *Core) CreateColumns(ctx context.Context, res *metav1.APIResource, colum
api.Column{
Name: "Keys",
Priority: 70,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
configmap := object.(*corev1.ConfigMap)
var keys []string
for key := range configmap.Data {
Expand All @@ -256,7 +256,7 @@ func (e *Core) CreateColumns(ctx context.Context, res *metav1.APIResource, colum
api.Column{
Name: "Keys",
Priority: 70,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
secret := object.(*corev1.Secret)
var keys []string
for key := range secret.Data {
Expand All @@ -274,7 +274,7 @@ func (e *Core) CreateColumns(ctx context.Context, res *metav1.APIResource, colum
api.Column{
Name: "Type",
Priority: 70,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
service := object.(*corev1.Service)
label := gtk.NewLabel(string(service.Spec.Type))
label.SetHAlign(gtk.AlignStart)
Expand Down
6 changes: 3 additions & 3 deletions extension/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (e *Meta) CreateColumns(ctx context.Context, resource *metav1.APIResource,
columns = append(columns, api.Column{
Name: "Name",
Priority: 100,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
label := gtk.NewLabel(object.GetName())
label.SetHAlign(gtk.AlignStart)
label.SetEllipsize(pango.EllipsizeEnd)
Expand All @@ -45,7 +45,7 @@ func (e *Meta) CreateColumns(ctx context.Context, resource *metav1.APIResource,
columns = append(columns, api.Column{
Name: "Namespace",
Priority: 90,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
label := gtk.NewLabel(object.GetNamespace())
label.SetHAlign(gtk.AlignStart)
label.SetEllipsize(pango.EllipsizeEnd)
Expand All @@ -60,7 +60,7 @@ func (e *Meta) CreateColumns(ctx context.Context, resource *metav1.APIResource,
columns = append(columns, api.Column{
Name: "Age",
Priority: 80,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
duration := time.Since(object.GetCreationTimestamp().Time)
label := gtk.NewLabel(util.HumanizeApproximateDuration(duration))
label.SetHAlign(gtk.AlignStart)
Expand Down
2 changes: 1 addition & 1 deletion extension/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (e *Networking) CreateColumns(ctx context.Context, resource *metav1.APIReso
api.Column{
Name: "Hosts",
Priority: 70,
Bind: func(listitem *gtk.ListItem, object client.Object) {
Bind: func(listitem *gtk.ColumnViewCell, object client.Object) {
ingress := object.(*networkingv1.Ingress)
var hosts []string
for _, r := range ingress.Spec.Rules {
Expand Down
2 changes: 1 addition & 1 deletion internal/style/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ dropdown.kind-dropdown>button {
.navigation-sidebar entry.search {
min-height: 29px;
font-size: 0.9em;
box-shadow: inset 0 1px var(--sidebar-border-color);
box-shadow: inset 0 1px @sidebar_border_color;
border-radius: 0 0 0 11px; /* var(--window-radius) */
}
2 changes: 1 addition & 1 deletion internal/style/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func Load() {
func getProvider(name string) *gtk.CSSProvider {
provider := gtk.NewCSSProvider()
style, _ := fs.ReadFile(name)
provider.LoadFromData(string(style))
provider.LoadFromString(string(style))
return provider
}

Expand Down
56 changes: 24 additions & 32 deletions internal/ui/cluster_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ui
import (
"context"
"fmt"
"math"
"time"

"github.com/diamondburned/gotk4-adwaita/pkg/adw"
Expand All @@ -26,7 +27,7 @@ type ClusterWindow struct {
listView *list.List
objectView *ObjectView
toastOverlay *adw.ToastOverlay
overlay *adw.OverlaySplitView
dialog *adw.Dialog
}

func NewClusterWindow(ctx context.Context, app *gtk.Application, state *common.ClusterState) *ClusterWindow {
Expand Down Expand Up @@ -72,17 +73,22 @@ func NewClusterWindow(ctx context.Context, app *gtk.Application, state *common.C
paned.SetShrinkEndChild(false)
w.toastOverlay.SetChild(paned)

// replace split view with sheet dialog? in adw 1.5
// https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1-latest/class.Dialog.html
w.overlay = adw.NewOverlaySplitView()
w.overlay.SetEnableHideGesture(true)
w.overlay.SetEnableShowGesture(true)
w.overlay.SetCollapsed(true)
w.overlay.SetSidebarPosition(gtk.PackEnd)
w.overlay.NotifyProperty("show-sidebar", w.resizeOverlay)

w.listView = list.NewList(ctx, w.ClusterState, w.overlay, editor)
w.overlay.SetContent(w.listView)
w.dialog = adw.NewDialog()
w.dialog.SetPresentationMode(adw.DialogBottomSheet)
w.dialog.SetFollowsContentSize(true)
go func() {
for {
select {
case <-ctx.Done():
return
default:
glib.IdleAdd(func() {
w.dialog.SetSizeRequest(int(math.Min(float64(w.Width())*0.6, 1000)), -1)
})
}
time.Sleep(time.Second)
}
}()

w.navigation = NewNavigation(ctx, w.ClusterState, viewStack, editor)
w.navigation.SetSizeRequest(225, -1)
Expand All @@ -92,11 +98,11 @@ func NewClusterWindow(ctx context.Context, app *gtk.Application, state *common.C
w.objectView = NewObjectView(ctx, w.ClusterState, editor, navView, w.navigation)
navView.Add(w.objectView.NavigationPage)
navView.SetHExpand(true)
navView.SetSizeRequest(400, -1)
w.overlay.SetSidebar(navView)
w.dialog.SetChild(navView)

viewStack.AddChild(w.overlay).SetName("list")
viewStack.SetVisibleChild(w.overlay)
w.listView = list.NewList(ctx, w.ClusterState, w.dialog, editor)
viewStack.AddChild(w.listView).SetName("list")
viewStack.SetVisibleChild(w.listView)
paned.SetEndChild(viewStack)

w.createActions()
Expand Down Expand Up @@ -130,28 +136,14 @@ func (w *ClusterWindow) createActions() {
action.ConnectActivate(func(_ *glib.Variant) {
prefs := NewPreferencesWindow(w.ctx, w.State)
prefs.SetTransientFor(&w.Window)
prefs.Show()
prefs.Present()
})
w.AddAction(action)

action = gio.NewSimpleAction("about", nil)
action.ConnectActivate(func(_ *glib.Variant) {
NewAboutWindow(&w.Window).Show()
NewAboutWindow(&w.Window).Present()
})
w.AddAction(action)

}

func (w *ClusterWindow) resizeOverlay() {
w.overlay.SetMaxSidebarWidth(float64(w.Width()-w.navigation.Width()) - 150)
// Workaround for lack of window resize signals
// could probably use size_allocate when subclassing is available
go func() {
time.Sleep(250 * time.Millisecond)
glib.IdleAdd(func() {
if w.overlay.ShowSidebar() {
w.resizeOverlay()
}
})
}()
}
Loading

0 comments on commit 221d296

Please sign in to comment.