Keel v0.5.1 中文 GitHub

ResizableGroup

Live example: a real Keel application compiled to WebAssembly. Interact with it here. The initial download is about 10 MB.Open full screen
Example sourceGo · Copyable

This is the complete source for the gallery example above.examples/components/resizable_group.go

Reuse the component construction and Render methods in a scaffolded project. The example’s registerSection and shared helpers are provided by the component gallery.

package main

import (
	"github.com/dyike/keel/ui/core"
	"github.com/dyike/keel/ui/el"
	"github.com/dyike/keel/ui/kit"
	"github.com/dyike/keel/ui/theme"
)

func init() {
	registerSection("resizable_group", "shell", func() core.Widget {
		pane := func(label string) el.View {
			return el.ViewFunc(func(*el.Context) el.Element {
				return el.Div().Grow().ScrollY().Bg(theme.Surface).P(12).Child(el.Text(label))
			})
		}
		g := kit.ResizableGroup(kit.ResizablePanel{ID: "files", Content: pane(demoText("Files", "文件")), Size: 120, Min: 60, Max: 180}, kit.ResizablePanel{ID: "editor", Content: kit.Input(demoText("Edit content", "编辑内容")), Min: 100}, kit.ResizablePanel{ID: "preview", Content: pane(demoText("Preview", "预览")), Size: 120, Min: 60})
		visible := true
		compact := false
		sizes := [2]map[string]float32{g.Sizes(), {"files": 100, "editor": 160, "preview": 120}}
		return el.Root(el.ViewFunc(func(cx *el.Context) el.Element {
			width, _ := cx.ViewportSize()
			narrow := width < 640*max(float32(1), cx.TextScale())
			if narrow != compact {
				old, next := 0, 1
				if compact {
					old, next = 1, 0
				}
				sizes[old] = g.Sizes()
				g.SetVertical(narrow).SetSizes(sizes[next])
				compact = narrow
			}
			height := float32(320)
			if compact {
				height = 480 * max(float32(1), cx.TextScale())
			}
			label := demoText("Hide preview", "隐藏预览")
			if !visible {
				label = demoText("Show preview", "显示预览")
			}
			return el.Div().ScrollY().P(24).Gap(12).Items(el.Stretch).Child(kit.Button(label, func() { visible = !visible; g.SetVisible("preview", visible) }).Size(44).Render(cx), el.Div().H(el.Dp(height)).Items(el.Stretch).Child(g.Render(cx)))
		}))
	})
}

Independent multi-panel split container supports horizontal and vertical arrangement and nesting. Coexists with double-sided Resizable.

g := kit.ResizableGroup(
    kit.ResizablePanel{ID: "files", Content: files, Size: 180, Min: 100, Max: 300},
    kit.ResizablePanel{ID: "editor", Content: editor, Min: 160},
    kit.ResizablePanel{ID: "preview", Content: preview, Size: 240, Min: 100},
)

The default is horizontal layout; Vertical changes to vertical layout. The ID must be non-empty and unique. Empty IDs and subsequent entries with duplicate IDs are ignored. Size is the initial dp, 0 initially divides the remaining space outside the specified size panel; Min defaults to 0, and Max is 0, which means there is no upper limit. When the upper limit is less than Min, Min shall prevail. Put into a parent container of certain size.

Dragging only changes the two adjacent visible panels, leaving other panels unchanged. Arrow keys 16dp each time, Home/End to adjacent range boundary; cancel to retain the last valid size. SetDisabled disables both the handle and the content, and HandleAppearance uses the same handle configuration as Resizable.

Window changes allocate margin from the last visible panel forward, retaining the size of the front panel; leaving the tail empty when the upper limit is reached. When there is not enough space to accommodate the minimum size, it will be compressed according to the Min ratio, but each 6dp handle will still be retained. Request next frame convergence after first measurement.

Sizes Returns a copy of the size indexed by ID. SetSizes sets a limited non-negative size of a known ID, does not trigger a callback, and converges to the container range in the next frame; explicit 0 is no longer used as an automatic equalization. OnChange only returns a full size copy after the user has actually resized it.

SetVisible(id, visible) controls the visibility of a single panel, and the hidden content continues to be declared and retains its status and size; the remaining panels reallocate space, and one side still adheres to its own Max. SetPanels replaces/rearranges the configuration, retains the size of the same ID, and uses Size for new IDs; use SetSizes to change the size of existing IDs. The status of removed panels and handles has been cleaned up. OnChange is not triggered by visibility, configuration, and window changes.

SetVertical(bool) switches axes at runtime without replacing pane content or firing OnChange. Sizes and limits apply to the new axis; save separate sizes in the application if each orientation should remember its own arrangement. The Gallery stacks panels on narrow screens and restores each orientation’s saved sizes.