From f4daf9a378bf947494e0bc65aef37063322ae58e Mon Sep 17 00:00:00 2001 From: omartelo Date: Fri, 4 Dec 2026 16:28:43 -0300 Subject: [PATCH] feat(native): the dock's tabs are at its top and the open one says what it holds The tabs move from a pill of icons at the foot into the header. The open one shows its name, its count and, on Review, the lines changed. The comments to send are one bar that unfolds upward, a file's paperclip and discard show under the pointer, and an empty tab says why in its middle. --- CHANGELOG.md | 1 + docs/ceilings.md | 5 +- docs/extensions.md | 6 +- native/DESIGN.md | 33 ++- native/cmd/lich-native/dock.go | 83 ++++---- native/cmd/lich-native/dock_artifacts.go | 2 +- native/cmd/lich-native/dock_comments.go | 200 +++++++++++------- native/cmd/lich-native/dock_hover_test.go | 79 +++++++ native/cmd/lich-native/dock_peek.go | 2 +- native/cmd/lich-native/dock_review.go | 6 +- native/cmd/lich-native/dock_review_badge.go | 88 -------- native/cmd/lich-native/dock_review_body.go | 7 +- native/cmd/lich-native/dock_review_file.go | 57 ++--- .../cmd/lich-native/dock_review_markdown.go | 12 ++ native/cmd/lich-native/dock_tabs.go | 142 +++++++++---- native/cmd/lich-native/dock_tabs_test.go | 85 ++++++-- native/cmd/lich-native/dock_tree_view.go | 4 +- native/cmd/lich-native/main.go | 2 +- native/cmd/lich-native/pulls_files.go | 3 +- native/i18n/locales/en/dock.json | 2 +- native/i18n/locales/es/dock.json | 2 +- native/i18n/locales/ja/dock.json | 2 +- native/i18n/locales/ko/dock.json | 2 +- native/i18n/locales/pt-br/dock.json | 2 +- native/i18n/locales/ru/dock.json | 2 +- native/i18n/locales/zh-cn/dock.json | 2 +- native/ui/icon_button.go | 5 +- 27 files changed, 519 insertions(+), 317 deletions(-) create mode 100644 native/cmd/lich-native/dock_hover_test.go delete mode 100644 native/cmd/lich-native/dock_review_badge.go diff --git a/CHANGELOG.md b/CHANGELOG.md index b789aa694..e9b4aa889 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **The Pulls screen is redrawn, and its list is sorted by what each pull request needs.** Open ones are grouped into Ready to merge, Needs work, In review and Drafts, in place of the All, Ready, Drafts and Failing filters and the Approved state. Inside a pull request, its facts stand beside the description, and Copy link and Copy Markdown are in the `⋯` menu. - **The Git panel shows one thing at a time.** Changes and History are now two tabs, and a commit opens beside the log when you click it. The branches open from the branch's name in the panel's header: click one to check it out, type a new name to create it, and find the rest in its `⋯`. +- **The dock's tabs are at its top, and the open one says what it holds.** Review shows its changed files and lines beside its name, Artifacts its count, and the row of icons at the foot is gone. Comments waiting to be sent are one bar with Send: click the count to read, edit or remove them, and to add a note. - **A finished turn in the chat is your message, the answer and the files it changed.** The calls, thoughts and texts on the way fold under one line with the time they took, like Worked for 4m 6s; click it to read them in order. Each changed file is listed once under the answer, and a click opens all its edits. - **A permission the agent asks for in the chat now waits over the message box.** It says what the agent wants to do and shows the whole command, or each file with its diff, with the answers always in view. Once you answer, only the call is left in the conversation, or a Denied line. - **A command you run with `!` in the chat is one message with its output.** The command and what it printed stand together on your side of the conversation, with the time it took when it is a second or more, and in red when it fails. On Claude Code, Codex and opencode, the agents whose chat runs commands. diff --git a/docs/ceilings.md b/docs/ceilings.md index 222ef47d2..917f97251 100644 --- a/docs/ceilings.md +++ b/docs/ceilings.md @@ -2435,8 +2435,9 @@ work when nobody knows it and that the call site never shows. The mechanism and goes when the extension fails, is removed, or the window restarts. A tree drawn for another checkout than the active one shows a placeholder, and an extension that never draws one for the new checkout leaves it there. - **The dock is never narrower than its tabs** (`native/cmd/lich-native/dock.go`, `fitTabs`): each extension with a - dock surface adds an icon button, 28px and a 2px gap, to the pill at the dock's foot, so with enough of them the - dock cannot be dragged narrow and the terminal beside it loses the columns. The title is only in the tooltip. + dock surface adds an icon button, 28px and a 2px gap, to the dock's header, so from the third extension on the + dock cannot be dragged down to its narrowest and the terminal beside it loses the columns. The title is in the + tooltip, and beside the icon while the tab is open. - **`render` is coalesced, at 30 a second per surface** (`internal/extensions/throttle.go`): the first goes out at once, and while the interval has not passed only the newest is kept and sent when it ends, so a loop of renders costs the window a frame rate and the newest tree always arrives. The older ones in between never reach the diff --git a/docs/extensions.md b/docs/extensions.md index b46a235ac..c14a8bb8b 100644 --- a/docs/extensions.md +++ b/docs/extensions.md @@ -158,9 +158,9 @@ A `dock` or `panel` surface opens from an item of the window's footer, the ballo way Review opens the dock and the branch opens the Git panel. lich puts each new item at the end of the footer's left side; the person can move it or hide it in Settings › Appearance › Footer, and a hidden one stays hidden across updates. A dock surface is a -tab after lich's own, an icon button in the row at the dock's foot with the title in its tooltip, and the dock is -never narrower than that row. A panel surface takes the Git panel's place at the stage's foot, one panel at a time, -each with the height the person dragged it to. +tab after lich's own, an icon button in the dock's header with the title in its tooltip, spelled out beside the icon +while the tab is open, and the dock is never narrower than its tabs. A panel surface takes the Git panel's place at +the stage's foot, one panel at a time, each with the height the person dragged it to. Both follow the session the window has active. lich sends `context` to an extension with such a surface when the active session changes, when the extension starts and when a window attaches, whether the surface is open or not: diff --git a/native/DESIGN.md b/native/DESIGN.md index b15722395..72aea4ffc 100644 --- a/native/DESIGN.md +++ b/native/DESIGN.md @@ -62,7 +62,7 @@ Elements are defined by space, hover and islands, not by enclosure. Inside an island, a change that adds a border, a rule, a pill, a second line or a nested surface is probably wrong. Reach for spacing, a hover state or the tooltip first. The folder tray is the one nested surface, and the reason is written -under it; the dock's tab pill reuses its fill, for the same reason. The footer's balloons are the pills on `Sidebar`: +under it; the bar of comments to send at a panel's foot is the other, set apart from the code it lies under. The footer's balloons are the pills on `Sidebar`: they float over the terminal and need a ground of their own to read on it, standing on `ui.ElevationLow`. The extension and theme catalogs, their Installed tabs included, are the screens of cards, and the reason is written under them. @@ -353,14 +353,27 @@ Space closes the header off from the body, never a rule. ### The dock's tabs -The dock's tabs (Code, Review, Artifacts and an extension's surfaces) are a pill of icon-only `BarIconButton`s -floating at its foot, centred, with the tab's name in a tooltip. The pill is `RadiusLG` on a faint `Accent` tray -(`folderTrayAlpha`; a `Sidebar` pill would vanish on the dock, which is `Sidebar` itself), `Space(1)` of padding, `Space(2)` off the dock's edges; the tab on screen is the -`Accent` fill, the others light on hover. The body stops above the strip, so nothing is covered. The header keeps -only actions at its right (Review's, collapse, full screen). A tab that holds something (Review with -changes, Artifacts with files) wears a 5px dot on its icon, never a count or a pill: `Foreground`, or `ToneWait` -on Review over a checkout with conflicts. The dock is never narrower -than the pill. +The dock's tabs (Code, Review, Artifacts and an extension's surfaces) stand at the left of its header, on the line +of its actions. The tab on screen is spelled out on an `Accent` fill at `RadiusMD`, 28px tall: its icon, its name in +medium, and what it holds, the count muted in `TextXS` and, on Review, the `DiffStat`. The others are icon-only +`BarIconButton`s with their name in a tooltip, and one that holds something (Review with changes, Artifacts with +files) wears a 5px dot on its icon, never a count: `Foreground`, or `ToneWait` on Review over a checkout with +conflicts. In a narrow dock the `DiffStat` goes first, then the count, and then the name is cut; the dock is never +narrower than its actions, the icons and 96px of the open tab. No line under the header repeats what the tab says. + +A tab with nothing to show says why in the middle of its body, muted in `TextSM` under a muted 20px glyph +(`dockEmpty`). Loading and a search with no match stay a `Notice` at the top, where the rows will be. + +### Review's file header and the comments to send + +A file's header is its chevron, its file icon, its name, its folder muted and its `DiffStat`. The paperclip and +discard show only while the pointer is on the header, before the `DiffStat`, so nothing there at rest moves. What the +state asks for stays: a conflict's actions, a Markdown file's preview. On the Pulls screen the paperclip stays too. + +The comments waiting to go to the session are one bar at the panel's foot (`commentBatch`), on `Accent` at +`RadiusLG`, `Space(2)` off the edges: a chevron and the count, then Clear and Send, the panel's `Primary`. A click on +the count unfolds the comments and the note about the whole change over the bar (`ui.Collapse`), so Send never moves. +A comment is one line, its pencil and × only under the pointer. ### The Code tab's tree @@ -1728,6 +1741,6 @@ at once, whatever its row is still doing. - **Pinned project tabs** stay at the left of the top strip, grouped before unpinned tabs with a wider gap between the groups (`tabGroupMargin`), never a rule; they carry a pin glyph and close from their context menu only. -- **Semantic color and the diff language badges**: they carry meaning. +- **Semantic color**: it carries meaning. - **Buttons do not move when pressed**; only their color changes. - **A sidebar row is one line.** Pull request and changes stay on it; a name too long is cut, not wrapped. diff --git a/native/cmd/lich-native/dock.go b/native/cmd/lich-native/dock.go index 6e6ba2884..64f159f1c 100644 --- a/native/cmd/lich-native/dock.go +++ b/native/cmd/lich-native/dock.go @@ -4,8 +4,8 @@ package main // or its Artifacts tab, and the tab it was last on when the window opens. It // never closes: it stands beside the terminal or, collapsed, comes out from // the window's edge. It owns the chrome around the bodies: the drag-resizable -// width (one, persisted, for every tab), full screen, collapse and the pill of -// icon tabs at its foot. +// width (one, persisted, for every tab) and the header: the tabs at its left, +// collapse and full screen at its right. // // The Review tab is a body the dock hands the frame to, through reviewTab: // @@ -68,7 +68,7 @@ const ( dockMinRem = 20 dockMaxRem = 60 dockDefaultRem = 28 - // dockHeaderHeight is the strip the actions sit in, 8dp from the top and + // dockHeaderHeight is the strip the tabs and the actions sit in, 8dp from the top and // from the Separator under it, the inset the sidebar's header keeps. dockHeaderHeight = unit.Dp(44) ) @@ -89,14 +89,20 @@ const ( // dockBuiltinTabs is how many tabs lich's own are, before the extensions'. const dockBuiltinTabs = int(dockArtifacts) -// dockHeaderSpare is what the header needs past its actions: its two insets -// and gaps, and a gap's room to their left. +// dockHeaderSpare is what the header needs past its tabs and actions: its two +// insets and gaps, and a gap's room between the two. var dockHeaderSpare = ui.Space(8) +// dockEmptyIcon is an empty tab's glyph, dockEmptyPad what keeps its line off +// the dock's edges. +var ( + dockEmptyIcon = ui.Space(5) + dockEmptyPad = ui.Space(8) +) + // dockInput is what the dock reads of the active session each frame. checkout // is where the session works now (useActiveSession's path), which is what both // tabs browse and review; git is its status, isGit false outside a repository. -// light is the palette on screen, for what draws with its own theme. type dockInput struct { sessionID string inject func(string) bool @@ -104,7 +110,6 @@ type dockInput struct { checkout string git backend.DiffStats isGit bool - light bool code godemirror.Theme // placed is the extensions' dock surfaces, a tab each after lich's. placed []placedSurface @@ -147,15 +152,12 @@ type dock struct { ext extensionKey extensions *extensionScreen extAct extensionAction - // tabButtons are the pill's buttons, one per tab; placed the extension + // tabButtons are the tabs' buttons, one per tab; placed the extension // tabs they were drawn for, which actTabs picks from. tabButtons []*dockTabButton placed []placedSurface - // actionsWidth and tabBarWidth are the header's actions and the pill with - // its insets, which fitTabs reads once both are laid out. - actionsWidth, tabBarWidth int - // minRem is the width the header's actions and the pill need, measured on - // the last frame: the dock is never narrower, so every tab stays in reach. + // minRem is the width the header's tabs and actions need, as of the last + // frame: the dock is never narrower, so every tab stays in reach. minRem float64 } @@ -248,9 +250,8 @@ func (d *dock) layout(gtx C, th *ui.Theme, root *ui.Root, in dockInput) (saveWid return D{Size: gtx.Constraints.Max} }) }), - layout.Rigid(func(gtx C) D { return d.tabBar(gtx, on, root, in) }), ) - d.fitTabs(gtx, max(d.actionsWidth+gtx.Dp(dockHeaderSpare), d.tabBarWidth)) + d.fitTabs(gtx, tabsNeed(gtx, len(d.tabButtons))) return saveWidth, err } @@ -269,35 +270,47 @@ func (d *dock) body(gtx C, th *ui.Theme, root *ui.Root, in dockInput) error { return nil } -// header is the h-10 strip: at its right the Review tab's actions or the Code -// tab's search, collapse and full screen. The tabs are the pill at the dock's foot. +// dockEmpty is a tab with nothing to show: why, under a quiet glyph, in the +// middle of the body. +func dockEmpty(gtx C, th *ui.Theme, glyph *icons.Icon, why string) D { + return layout.Center.Layout(gtx, func(gtx C) D { + return layout.UniformInset(dockEmptyPad).Layout(gtx, func(gtx C) D { + return layout.Flex{Axis: layout.Vertical, Alignment: layout.Middle}.Layout(gtx, + layout.Rigid(func(gtx C) D { return glyph.Layout(gtx, dockEmptyIcon, th.MutedForeground) }), + ui.VGap(2.5), + layout.Rigid(th.Text(ui.TextSM, why).Muted().Wrapped().Centered().Layout), + ) + }) + }) +} + +// header is the strip over the body: the tabs at its left, and at its right +// the Review tab's actions or the Code tab's search, collapse and full screen. func (d *dock) header(gtx C, th *ui.Theme, root *ui.Root, in dockInput) D { changed := in.isGit && in.git.Files > 0 - actions := 0 fullIcon, fullLabel := icDockMaximize, i18n.T("dock.rightDock.fullScreen") if d.fullscreen { fullIcon, fullLabel = icDockMinimize, i18n.T("dock.rightDock.exitFullScreen") } gtx.Constraints = layout.Exact(image.Pt(gtx.Constraints.Max.X, gtx.Dp(dockHeaderHeight))) - dims := layout.Inset{Left: ui.Space(2), Right: ui.Space(2)}.Layout(gtx, func(gtx C) D { + return layout.Inset{Left: ui.Space(2), Right: ui.Space(2)}.Layout(gtx, func(gtx C) D { return layout.Flex{Alignment: layout.Middle}.Layout(gtx, - layout.Flexed(1, func(gtx C) D { return D{Size: image.Pt(gtx.Constraints.Min.X, 0)} }), + layout.Flexed(1, func(gtx C) D { + width := gtx.Constraints.Max.X + return D{Size: image.Pt(width, d.tabs(gtx, th, root, in).Size.Y)} + }), layout.Rigid(func(gtx C) D { if d.tab != dockReview || !changed { return D{} } - dims := d.review.layoutActions(gtx, th) - actions += dims.Size.X - return dims + return d.review.layoutActions(gtx, th) }), ui.Gap(1), layout.Rigid(func(gtx C) D { if d.tab != dockCode { return D{} } - dims := th.IconAction(root, &d.search, icSearch, i18n.T("dock.filesPanel.search"), d.code.searching).Layout(gtx) - actions += dims.Size.X - return dims + return th.IconAction(root, &d.search, icSearch, i18n.T("dock.filesPanel.search"), d.code.searching).Layout(gtx) }), ui.Gap(1), layout.Rigid(func(gtx C) D { @@ -308,24 +321,18 @@ func (d *dock) header(gtx C, th *ui.Theme, root *ui.Root, in dockInput) D { if d.collapsed { icon, label = icDockExpand, i18n.T("dock.rightDock.expandPanel") } - dims := th.IconAction(root, &d.collapse, icon, label, false).Layout(gtx) - actions += dims.Size.X - return dims + return th.IconAction(root, &d.collapse, icon, label, false).Layout(gtx) }), ui.Gap(1), layout.Rigid(func(gtx C) D { - dims := th.IconAction(root, &d.full, fullIcon, fullLabel, false).Layout(gtx) - actions += dims.Size.X - return dims + return th.IconAction(root, &d.full, fullIcon, fullLabel, false).Layout(gtx) }), ) }) - d.actionsWidth = actions - return dims } -// fitTabs keeps the dock at least as wide as its header's actions and the -// pill of tabs need, px wide, and redraws when that changes. +// fitTabs keeps the dock at least as wide as its header needs, px, and redraws +// when that changes. func (d *dock) fitTabs(gtx C, px int) { need := max(dockMinRem, float64(gtx.Metric.PxToDp(px))/remDp) if need != d.minRem { @@ -359,8 +366,8 @@ func (d *dock) pickTab(index int, placed []placedSurface) { } } -// act runs the header's and the pill's clicks before the stage row reads whether the dock -// is open and how wide, so the frame shows their outcome. +// act runs the header's clicks before the stage row reads whether the dock is +// open and how wide, so the frame shows their outcome. func (d *dock) act(gtx C) { d.actTabs(gtx) for d.search.Click.Clicked(gtx) { diff --git a/native/cmd/lich-native/dock_artifacts.go b/native/cmd/lich-native/dock_artifacts.go index f77891362..7334b4b9f 100644 --- a/native/cmd/lich-native/dock_artifacts.go +++ b/native/cmd/lich-native/dock_artifacts.go @@ -114,7 +114,7 @@ func (t *artifactsTab) motion(owner string) *ui.Presence { func (t *artifactsTab) layout(gtx C, th *ui.Theme, root *ui.Root, active string) D { own, others := t.groups(active) if len(own) == 0 && len(others) == 0 { - return th.Notice(i18n.T("dock.artifacts.empty")).Layout(gtx) + return dockEmpty(gtx, th, icDockArtifacts, i18n.T("dock.artifacts.empty")) } var items []layout.Widget add := func(w layout.Widget) { items = append(items, w) } diff --git a/native/cmd/lich-native/dock_comments.go b/native/cmd/lich-native/dock_comments.go index 89a75a53f..7eafec1ef 100644 --- a/native/cmd/lich-native/dock_comments.go +++ b/native/cmd/lich-native/dock_comments.go @@ -8,7 +8,7 @@ package main // // comments := new(commentStore) // one per window // comments.add(target, path, lines, text) // target is the checkout path -// comments.list(target) // what the strip shows +// comments.list(target) // what the bar holds // comments.beginEdit(target, id) // a row's pencil; the window's commentEditDialog opens on it // // var c commentComposer // one per surface @@ -17,7 +17,7 @@ package main // c.holdsKeys(gtx) // keep the terminal off it; ask before layout // c.layout(gtx, th, comments, target) // the box; files into comments on Add, closes itself // -// var b commentBatch // the strip at a panel's foot +// var b commentBatch // the bar at a panel's foot // b.layout(gtx, th, comments, target, submit, notify) // // nothing at all while the batch is empty // @@ -47,6 +47,7 @@ var ( icBatchRemove = icons.Lucide("x") icBatchEdit = icons.Lucide("pencil") icBatchSend = icons.Lucide("send") + icBatchOpen = icons.Lucide("chevron-up") ) // reviewComment is a place plus what should change there. path and lines are @@ -322,14 +323,18 @@ func (c *commentComposer) box(th *ui.Theme) layout.Widget { } } -// commentBatch is the strip at the foot of a review panel: the comments so -// far, a note about the whole change, and the one action that hands them all -// to the session as one prompt. A comment's pencil opens the window's -// commentEditDialog on it. +// commentBatch is the bar at the foot of a review panel: how many comments +// wait, and the one action that hands them all to the session as one prompt. +// A click on the count unfolds them over it, with a note about the whole +// change. A comment's pencil opens the window's commentEditDialog on it. type commentBatch struct { + open bool + toggle ui.Clickable + fold ui.Collapse list widget.List removes map[int]*ui.Clickable edits map[int]*ui.Clickable + over map[int]*hoverArea note widget.Editor clear, send ui.Clickable // sending is the batch on its way to the session, still in the store: @@ -351,7 +356,17 @@ const batchListMax = unit.Dp(160) // batchNoteMax is the note's max-h-32; a longer note scrolls inside it. const batchNoteMax = unit.Dp(128) -// layout draws the strip for target's batch, or nothing while it is empty. +// batchHoverInk is how much of the foreground stands in for Muted on the bar. +const batchHoverInk = 0.2 + +// The bar's inset from the panel's edges and its own padding. +var ( + batchInset = ui.Space(2) + batchPadX = ui.Space(2) + batchPadY = ui.Space(1.5) +) + +// layout draws the bar for target's batch, or nothing while it is empty. // submit sends the batch as the session's prompt and reports whether one took // it; the comments are the one thing here the user typed, so they stay until // the session has taken them. @@ -359,28 +374,52 @@ func (b *commentBatch) layout(gtx C, th *ui.Theme, store *commentStore, target s b.update(gtx, store, target, submit, notify) comments := store.list(target) if len(comments) == 0 { + b.open = false return D{} } gtx.Constraints.Min.X = gtx.Constraints.Max.X + ground := th.Over(th.Accent) + on := th.On(ground) + // The theme's Muted, a ghost button's hover, can be Accent itself. + on.Muted = th.Over(ui.Alpha(th.Foreground, batchHoverInk)) + return layout.Inset{Left: batchInset, Right: batchInset, Bottom: batchInset}.Layout(gtx, func(gtx C) D { + return layout.Background{}.Layout(gtx, + func(gtx C) D { return ui.Fill(gtx, ground, ui.RadiusLG) }, + func(gtx C) D { + return layout.Inset{Left: batchPadX, Right: batchPadX, Top: batchPadY, Bottom: batchPadY}.Layout(gtx, func(gtx C) D { + return layout.Flex{Axis: layout.Vertical}.Layout(gtx, + layout.Rigid(func(gtx C) D { + return b.fold.Layout(gtx, b.open, func(gtx C) D { return b.comments(gtx, on, comments) }) + }), + layout.Rigid(func(gtx C) D { return b.bar(gtx, on, len(comments)) }), + ) + }) + }, + ) + }) +} + +// comments is what the bar unfolds over it: the comments and the note. +func (b *commentBatch) comments(gtx C, th *ui.Theme, comments []reviewComment) D { return layout.Flex{Axis: layout.Vertical}.Layout(gtx, layout.Rigid(func(gtx C) D { - gtx.Constraints.Max.Y = gtx.Dp(batchListMax) - return layout.UniformInset(ui.Space(1)).Layout(gtx, func(gtx C) D { return b.rows(gtx, th, comments) }) - }), - layout.Rigid(func(gtx C) D { - return layout.Inset{Left: ui.Space(2), Right: ui.Space(2), Top: ui.Space(1)}.Layout(gtx, b.noteField(th)) - }), - layout.Rigid(func(gtx C) D { - return layout.Inset{Left: ui.Space(2), Right: ui.Space(2), Top: ui.Space(1), Bottom: ui.Space(2)}.Layout(gtx, b.footer(th, len(comments))) + gtx.Constraints.Max.Y = min(gtx.Constraints.Max.Y, gtx.Dp(batchListMax)) + return b.rows(gtx, th, comments) }), + ui.VGap(1), + layout.Rigid(b.noteField(th)), + ui.VGap(1.5), ) } -// update runs the strip's clicks against the store before it is drawn. +// update runs the bar's clicks against the store before it is drawn. func (b *commentBatch) update(gtx C, store *commentStore, target string, submit func(api.RequestOptions, func(error)) bool, notify func(ui.Toast)) { b.note.Submit = true if b.removes == nil { - b.removes, b.edits = map[int]*ui.Clickable{}, map[int]*ui.Clickable{} + b.removes, b.edits, b.over = map[int]*ui.Clickable{}, map[int]*ui.Clickable{}, map[int]*hoverArea{} + } + if b.toggle.Clicked(gtx) { + b.open = !b.open } for { ev, ok := b.note.Update(gtx) @@ -397,6 +436,7 @@ func (b *commentBatch) update(gtx C, store *commentStore, target string, submit store.remove(target, id) delete(b.removes, id) delete(b.edits, id) + delete(b.over, id) } } for id, c := range b.edits { @@ -465,73 +505,85 @@ func (b *commentBatch) rows(gtx C, th *ui.Theme, comments []reviewComment) D { }) } -// row is one comment: where (mono, muted), what (truncated), its pencil and -// its ×. +// row is one comment: where (mono, muted), what (truncated), and its pencil +// and × only while the pointer is on it. func (b *commentBatch) row(gtx C, th *ui.Theme, c reviewComment) D { - gtx.Constraints.Min.X = gtx.Constraints.Max.X - edit := th.Button(clickableAt(b.edits, c.id), "") - edit.Icon, edit.Variant, edit.Size = icBatchEdit, ui.VariantGhost, ui.SizeIconXS - remove := th.Button(clickableAt(b.removes, c.id), "") - remove.Icon, remove.Variant, remove.Size = icBatchRemove, ui.VariantGhost, ui.SizeIconXS - return layout.Inset{Left: ui.Space(1.5), Right: ui.Space(1.5), Top: ui.Space(1), Bottom: ui.Space(1)}.Layout(gtx, func(gtx C) D { - return layout.Flex{Alignment: layout.Middle}.Layout(gtx, - layout.Rigid(func(gtx C) D { - if c.path == "" { - return D{} - } - return layout.Inset{Right: ui.Space(2)}.Layout(gtx, - th.Text(ui.TextXS, path.Base(c.path)+":"+c.lines).Mono().Muted().Layout) - }), - layout.Flexed(1, func(gtx C) D { - l := th.Text(ui.TextXS, strings.ReplaceAll(c.txt, "\n", " ")) - l.MaxLines = 1 - return l.Layout(gtx) - }), - ui.Gap(2), - layout.Rigid(edit.Layout), - layout.Rigid(remove.Layout), - ) - }) -} - -// noteField is the note box; Enter adds the note to the batch, Shift+Enter -// is a new line. -func (b *commentBatch) noteField(th *ui.Theme) layout.Widget { - return func(gtx C) D { - ta := th.Textarea(&b.note, i18n.T("diff.commentBatch.notePlaceholder")) - ta.MaxHeight = batchNoteMax - return ta.Layout(gtx) + over, ok := b.over[c.id] + if !ok { + over = new(hoverArea) + b.over[c.id] = over + } + over.read(gtx) + gtx.Constraints.Min = image.Pt(gtx.Constraints.Max.X, 0) + children := []layout.FlexChild{ + layout.Rigid(layout.Spacer{Height: ui.IconActionSize}.Layout), + layout.Rigid(func(gtx C) D { + if c.path == "" { + return D{} + } + return layout.Inset{Right: ui.Space(2)}.Layout(gtx, + th.Text(ui.TextXS, path.Base(c.path)+":"+c.lines).Mono().Muted().Layout) + }), + layout.Flexed(1, func(gtx C) D { + l := th.Text(ui.TextXS, strings.ReplaceAll(c.txt, "\n", " ")) + l.MaxLines = 1 + return l.Layout(gtx) + }), } + if over.over { + edit := th.Button(clickableAt(b.edits, c.id), "") + edit.Icon, edit.Variant, edit.Size = icBatchEdit, ui.VariantGhost, ui.SizeIconXS + remove := th.Button(clickableAt(b.removes, c.id), "") + remove.Icon, remove.Variant, remove.Size = icBatchRemove, ui.VariantGhost, ui.SizeIconXS + children = append(children, ui.Gap(2), layout.Rigid(edit.Layout), layout.Rigid(remove.Layout)) + } + dims := layout.Flex{Alignment: layout.Middle}.Layout(gtx, children...) + over.watch(gtx, image.Rectangle{Max: dims.Size}) + return dims } -// footer is the count, then Clear and Send. -func (b *commentBatch) footer(th *ui.Theme, count int) layout.Widget { +// noteField is the note box, a line tall until it is written in; Enter adds +// the note to the batch, Shift+Enter is a new line. +func (b *commentBatch) noteField(th *ui.Theme) layout.Widget { + on := th.On(th.Sidebar) return func(gtx C) D { - clear := th.Button(&b.clear, i18n.T("diff.commentBatch.clear")) - clear.Variant, clear.Size = ui.VariantGhost, ui.SizeSM - return layout.Flex{Alignment: layout.Middle}.Layout(gtx, - layout.Rigid(th.Text(ui.TextXS, i18n.T("diff.commentBatch.count", i18n.Args{"count": count})).Muted().Layout), - layout.Flexed(1, func(gtx C) D { return D{Size: image.Pt(gtx.Constraints.Min.X, 0)} }), - layout.Rigid(clear.Layout), - ui.Gap(1), - layout.Rigid(func(gtx C) D { return b.sendButton(gtx, th) }), + return layout.Background{}.Layout(gtx, + func(gtx C) D { return ui.Fill(gtx, on.Surface, ui.RadiusMD) }, + func(gtx C) D { + ta := on.Textarea(&b.note, i18n.T("diff.commentBatch.notePlaceholder")) + ta.Bare, ta.MaxHeight = true, batchNoteMax + ta.Size, ta.PadX, ta.PadY = ui.TextXS, ui.Space(2), ui.Space(1.5) + return ta.Layout(gtx) + }, ) } } -// sendButtonFill is the accent's alpha on the Send button at rest. -const sendButtonFill = 0.55 - -func (b *commentBatch) sendButton(gtx C, th *ui.Theme) D { - send := th.Button(&b.send, i18n.T("diff.commentBatch.send")) - send.Icon, send.Variant, send.Size = icBatchSend, ui.VariantGhost, ui.SizeSM - if b.send.Hovered() { - return send.Layout(gtx) +// bar is the count, which opens and shuts the comments, then Clear and Send. +func (b *commentBatch) bar(gtx C, th *ui.Theme, count int) D { + chevron := icBatchOpen + if b.open { + chevron = icChevronDown } - fill := th.Over(ui.Alpha(th.Accent, sendButtonFill)) - return layout.Background{}.Layout(gtx, - func(gtx C) D { return ui.Fill(gtx, fill, ui.RadiusMD) }, - send.Layout, + clear := th.Button(&b.clear, i18n.T("diff.commentBatch.clear")) + clear.Variant, clear.Size = ui.VariantGhost, ui.SizeXS + send := th.Button(&b.send, i18n.T("diff.commentBatch.send")) + send.Icon, send.Size = icBatchSend, ui.SizeXS + return layout.Flex{Alignment: layout.Middle}.Layout(gtx, + layout.Flexed(1, func(gtx C) D { + return b.toggle.Layout(gtx, func(gtx C) D { + return layout.Flex{Alignment: layout.Middle}.Layout(gtx, + layout.Rigid(layout.Spacer{Height: ui.IconActionSize}.Layout), + layout.Rigid(func(gtx C) D { return chevron.Layout(gtx, ui.Space(3.5), th.MutedForeground) }), + ui.Gap(2), + layout.Rigid(th.Text(ui.TextXS, i18n.T("diff.commentBatch.count", i18n.Args{"count": count})).Truncated().Layout), + ) + }) + }), + ui.Gap(2), + layout.Rigid(clear.Layout), + ui.Gap(1), + layout.Rigid(send.Layout), ) } diff --git a/native/cmd/lich-native/dock_hover_test.go b/native/cmd/lich-native/dock_hover_test.go new file mode 100644 index 000000000..9ba6c9f73 --- /dev/null +++ b/native/cmd/lich-native/dock_hover_test.go @@ -0,0 +1,79 @@ +package main + +import ( + "image" + "testing" + + "gioui.org/io/input" + + "github.com/lichdotdev/lich/native/i18n" + "github.com/lichdotdev/lich/native/ui" +) + +// smallControlsBeside counts the 24px controls on label's line. +func smallControlsBeside(t *testing.T, r *frameRig, label string) int { + t.Helper() + y := int(r.glyphAt(t, label).Y) + found := map[image.Rectangle]bool{} + for _, n := range r.nodes() { + b := n.Desc.Bounds + if n.Desc.Gestures&input.ClickGesture != 0 && b.Dx() == int(ui.IconActionSize) && b.Min.Y <= y && y < b.Max.Y { + found[b] = true + } + } + return len(found) +} + +func TestReviewFileShowsItsActionsUnderThePointerOnly(t *testing.T) { + _, r := diffRig(t, changedInput) + counts := r.at(t, "+2") + if got := smallControlsBeside(t, r, "a.go"); got != 0 { + t.Errorf("%d actions on a file's header at rest, want none", got) + } + r.hover(r.at(t, "a.go")) + r.frames(2) + if got := smallControlsBeside(t, r, "a.go"); got != 2 { + t.Errorf("%d actions under the pointer, want the paperclip and discard", got) + } + if got := r.at(t, "+2"); got != counts { + t.Errorf("the line counts moved from %v to %v as the actions came", counts, got) + } + writeShot(t, r, "dock-file-hover.png") +} + +func TestCommentBatchOpensOverItsBar(t *testing.T) { + p, r := diffRig(t, changedInput) + p.comments.add("/repo", "a.go", "2", "Say why it shouts") + p.comments.add("/repo", "a.go", "11", "One more line of it") + p.invalidate() + r.settle(t) + send, count := r.at(t, i18n.T("diff.commentBatch.send")), i18n.T("diff.commentBatch.count", i18n.Args{"count": 2}) + if r.shows("Say why it shouts") { + t.Error("the comments show before the bar is opened") + } + writeShot(t, r, "dock-batch-shut.png") + + r.clickLabel(t, count) + r.settle(t) + if !r.shows("Say why it shouts") { + t.Fatalf("a click on the count did not open the comments:\n%s", r.drawn()) + } + if got := r.at(t, i18n.T("diff.commentBatch.send")); got != send { + t.Errorf("Send moved from %v to %v as the comments opened", send, got) + } + if got := smallControlsBeside(t, r, "Say why it shouts"); got != 0 { + t.Errorf("%d controls on a comment at rest, want none", got) + } + r.hover(r.glyphAt(t, "Say why it shouts")) + r.frames(2) + if got := smallControlsBeside(t, r, "Say why it shouts"); got != 2 { + t.Errorf("%d controls on a comment under the pointer, want its pencil and ×", got) + } + writeShot(t, r, "dock-batch-open.png") + + r.clickLabel(t, count) + r.settle(t) + if r.shows("Say why it shouts") { + t.Error("a second click on the count left the comments open") + } +} diff --git a/native/cmd/lich-native/dock_peek.go b/native/cmd/lich-native/dock_peek.go index 5e3ea7db7..b7b03e2fb 100644 --- a/native/cmd/lich-native/dock_peek.go +++ b/native/cmd/lich-native/dock_peek.go @@ -172,7 +172,7 @@ func (u *window) dockPeek(gtx C, v stageView) error { // layoutDock lays the dock out in gtx.Constraints.Max and keeps what it // asked for: a width to store, an extension's action. func (u *window) layoutDock(gtx C, v stageView) error { - in := dockInput{sessionID: v.in.sessionID, inject: u.injector(v.in.sessionID), submit: u.terms.submitter(v.in.sessionID), checkout: v.in.path, git: v.in.git, isGit: v.in.isGit, light: u.light, code: u.code, placed: placedIn(v.in.placed, extension.PlaceDock)} + in := dockInput{sessionID: v.in.sessionID, inject: u.injector(v.in.sessionID), submit: u.terms.submitter(v.in.sessionID), checkout: v.in.path, git: v.in.git, isGit: v.in.isGit, code: u.code, placed: placedIn(v.in.placed, extension.PlaceDock)} save, err := u.dock.layout(gtx, u.theme, &u.root, in) u.applyExtension(u.dock.takeExtensionAction()) if save { diff --git a/native/cmd/lich-native/dock_review.go b/native/cmd/lich-native/dock_review.go index df5e6924a..747884030 100644 --- a/native/cmd/lich-native/dock_review.go +++ b/native/cmd/lich-native/dock_review.go @@ -76,7 +76,6 @@ type reviewPanel struct { // the comment batch, a pull request's page when its branch has no // checkout; checkout is always a clone the files are read from. th *ui.Theme - light bool code godemirror.Theme target string // resolveNext is a conflicted file to open in the resolver on the next @@ -245,7 +244,7 @@ func (p *reviewPanel) composing() bool { // layoutBody is the panel under the dock's header: the checkout's // working-tree diff, and the comment batch at its foot. func (p *reviewPanel) layoutBody(gtx C, th *ui.Theme, in dockInput) error { - p.th, p.light, p.code, p.target, p.checkout = th, in.light, in.code, in.checkout, in.checkout + p.th, p.code, p.target, p.checkout = th, in.code, in.checkout, in.checkout p.git = in.git p.takeResolvers() if rel := p.resolveNext; rel != "" { @@ -274,7 +273,6 @@ type reviewLook struct { version uint64 checkout, branch, merging string conflicted string - light bool code godemirror.Theme } @@ -283,7 +281,7 @@ var reviewLookSeed = maphash.MakeSeed() func (p *reviewPanel) memoVersion(in dockInput) uint64 { return maphash.Comparable(reviewLookSeed, reviewLook{ version: p.version.Load(), checkout: in.checkout, branch: in.git.Branch, merging: in.git.Merging, - conflicted: strings.Join(in.git.Conflicted, "\x00"), light: in.light, code: in.code, + conflicted: strings.Join(in.git.Conflicted, "\x00"), code: in.code, }) } diff --git a/native/cmd/lich-native/dock_review_badge.go b/native/cmd/lich-native/dock_review_badge.go deleted file mode 100644 index 5b8246a72..000000000 --- a/native/cmd/lich-native/dock_review_badge.go +++ /dev/null @@ -1,88 +0,0 @@ -package main - -import ( - "image/color" - "path" - "strings" - - "github.com/lichdotdev/lich/native/ui" -) - -// tailwindHue is a Tailwind color's 400, 500 and 600 shades, the three a -// language badge reads. -type tailwindHue struct{ c400, c500, c600 color.NRGBA } - -func hue(l4, c4, h4, l5, c5, h5, l6, c6, h6 float64) tailwindHue { - return tailwindHue{ui.OKLCH(l4, c4, h4, 1), ui.OKLCH(l5, c5, h5, 1), ui.OKLCH(l6, c6, h6, 1)} -} - -// Tailwind v4's palette, the shades the language badges use. -var ( - twBlue = hue(0.707, 0.165, 254.624, 0.623, 0.214, 259.815, 0.546, 0.245, 262.881) - twYellow = hue(0.852, 0.199, 91.936, 0.795, 0.184, 86.047, 0.681, 0.162, 75.834) - twCyan = hue(0.789, 0.154, 211.53, 0.715, 0.143, 215.221, 0.609, 0.126, 221.723) - twSky = hue(0.746, 0.16, 232.661, 0.685, 0.169, 237.323, 0.588, 0.158, 241.966) - twOrange = hue(0.75, 0.183, 55.934, 0.705, 0.213, 47.604, 0.646, 0.222, 41.116) - twAmber = hue(0.828, 0.189, 84.429, 0.769, 0.188, 70.08, 0.666, 0.179, 58.318) - twViolet = hue(0.702, 0.183, 293.541, 0.606, 0.25, 292.717, 0.541, 0.281, 293.009) - twRose = hue(0.712, 0.194, 13.428, 0.645, 0.246, 16.439, 0.586, 0.253, 17.585) - twEmerald = hue(0.765, 0.177, 163.223, 0.696, 0.17, 162.48, 0.596, 0.145, 163.225) - twTeal = hue(0.777, 0.152, 181.912, 0.704, 0.14, 182.503, 0.6, 0.118, 184.704) - twIndigo = hue(0.673, 0.182, 276.935, 0.585, 0.233, 277.117, 0.511, 0.262, 276.966) - twStone = hue(0.709, 0.01, 56.259, 0.553, 0.013, 58.071, 0.444, 0.011, 73.639) -) - -type langBadge struct { - abbr string - tint *tailwindHue // nil: muted background and text -} - -// langBadges maps a file extension to its badge. -var langBadges = map[string]langBadge{ - "ts": {"TS", &twBlue}, "tsx": {"TS", &twBlue}, - "js": {"JS", &twYellow}, "jsx": {"JS", &twYellow}, - "go": {"GO", &twCyan}, "css": {"CSS", &twSky}, "html": {"HTM", &twOrange}, - "json": {"{}", &twAmber}, "md": {"MD", &twViolet}, - "yaml": {"YML", &twRose}, "yml": {"YML", &twRose}, - "sh": {"SH", &twEmerald}, "py": {"PY", &twTeal}, "rs": {"RS", &twOrange}, - "sql": {"SQL", &twIndigo}, "toml": {"TML", &twStone}, -} - -// extname is a path's lowercased extension without the dot, "" for none or -// a dotfile. -func extname(p string) string { - base := path.Base(p) - dot := strings.LastIndexByte(base, '.') - if dot <= 0 { - return "" - } - return strings.ToLower(base[dot+1:]) -} - -// languageAbbr picks a path's badge: a known extension's, else its first -// letters, else a neutral dot. -func languageAbbr(p string) langBadge { - ext := extname(p) - if b, ok := langBadges[ext]; ok { - return b - } - if ext == "" { - return langBadge{abbr: "•"} - } - return langBadge{abbr: strings.ToUpper(ext[:min(len(ext), 3)])} -} - -// badgeTintAlpha is bg-X-500/15. -const badgeTintAlpha = 0.15 - -// colors are the badge's fill and text on th. -func (b langBadge) colors(th *ui.Theme, light bool) (bg, fg color.NRGBA) { - if b.tint == nil { - return th.Over(th.Muted), th.MutedForeground - } - fg = b.tint.c400 - if light { - fg = b.tint.c600 - } - return th.Over(ui.Alpha(b.tint.c500, badgeTintAlpha)), fg -} diff --git a/native/cmd/lich-native/dock_review_body.go b/native/cmd/lich-native/dock_review_body.go index 8e2abecb8..143b10cce 100644 --- a/native/cmd/lich-native/dock_review_body.go +++ b/native/cmd/lich-native/dock_review_body.go @@ -15,6 +15,9 @@ var ( icCollapseAll = icons.Lucide("chevrons-down-up") icExpandAll = icons.Lucide("chevrons-up-down") icSplit = icons.Lucide("columns-2") + // The glyphs over a Review with nothing to show. + icNoChanges = icons.Lucide("check") + icNoRepository = icons.Lucide("git-branch") ) func loadHideWhitespace(ctx context.Context, c *backend.Client) (bool, error) { @@ -82,9 +85,9 @@ func (p *reviewPanel) panelBody(gtx C, th *ui.Theme) { case r == nil: th.Notice(i18n.T("diff.reviewPanel.loading")).Layout(gtx) case r.failed: - th.Notice(i18n.T("diff.reviewPanel.notRepository")).Layout(gtx) + dockEmpty(gtx, th, icNoRepository, i18n.T("diff.reviewPanel.notRepository")) case len(p.order) == 0: - th.Notice(i18n.T("diff.reviewPanel.noChanges")).Layout(gtx) + dockEmpty(gtx, th, icNoChanges, i18n.T("diff.reviewPanel.noChanges")) default: p.fileList(gtx, th) } diff --git a/native/cmd/lich-native/dock_review_file.go b/native/cmd/lich-native/dock_review_file.go index 6eaddf44f..1a22aa321 100644 --- a/native/cmd/lich-native/dock_review_file.go +++ b/native/cmd/lich-native/dock_review_file.go @@ -9,7 +9,6 @@ import ( "gioui.org/op" "gioui.org/op/clip" "gioui.org/op/paint" - "gioui.org/unit" "github.com/lichdotdev/godemirror" "github.com/lichdotdev/lich/native/i18n" @@ -61,6 +60,7 @@ type fileCard struct { toggle ui.Clickable attach, discard ui.IconActionState + over hoverArea resolve ui.Clickable preview ui.IconActionState menu ui.MenuState @@ -180,6 +180,7 @@ func (c *fileCard) header(gtx C, p *reviewPanel) D { if p.pr != nil { on = p.th.On(p.th.Background) } + c.over.read(gtx) gtx.Constraints.Min.X = gtx.Constraints.Max.X dims := layout.Background{}.Layout(gtx, func(gtx C) D { return ui.Fill(gtx, on.Surface, 0) }, @@ -189,17 +190,22 @@ func (c *fileCard) header(gtx C, p *reviewPanel) D { }) }, ) + c.over.watch(gtx, image.Rectangle{Max: dims.Size}) c.headerHeight = dims.Size.Y return dims } func (c *fileCard) headerRow(gtx C, th *ui.Theme, p *reviewPanel) D { children := []layout.FlexChild{ + layout.Rigid(layout.Spacer{Height: ui.IconActionSize}.Layout), layout.Flexed(1, func(gtx C) D { - return c.toggle.Layout(gtx, func(gtx C) D { return c.title(gtx, th, p.light, p.pr != nil && p.pr.changedSinceReview(c)) }) + return c.toggle.Layout(gtx, func(gtx C) D { return c.title(gtx, th, p.pr != nil && p.pr.changedSinceReview(c)) }) }), } conflicted := p.conflicted(c.git.path) + if p.pr == nil && c.over.over { + children = append(children, c.hoverActions(th, p, conflicted)...) + } if !c.git.binary && !conflicted { children = append(children, ui.Gap(2), layout.Rigid(func(gtx C) D { if c.onlyWhitespace() { @@ -208,33 +214,43 @@ func (c *fileCard) headerRow(gtx C, th *ui.Theme, p *reviewPanel) D { return th.DiffStat(c.patch.Added, c.patch.Deleted).Layout(gtx) })) } - attachGap := ui.Gap(2) if c.previewsMarkdown() { children = append(children, ui.Gap(2), layout.Rigid(func(gtx C) D { return c.previewToggle(gtx, th, p) })) - attachGap = ui.Gap(1) } - children = append(children, - attachGap, layout.Rigid(func(gtx C) D { - return th.IconAction(p.root, &c.attach, icAttach, i18n.T("diff.fileDiff.addAsContext"), false).Layout(gtx) - })) switch { case p.pr != nil: + attachGap := ui.Gap(2) + if c.previewsMarkdown() { + attachGap = ui.Gap(1) + } + children = append(children, attachGap, c.attachAction(th, p)) if p.pr.base == "" { children = append(children, ui.Gap(2), layout.Rigid(func(gtx C) D { return c.viewedTick(gtx, th, p) })) } case conflicted: children = append(children, c.conflictActions(th, p)...) - case p.reverts(c.git.path): - children = append(children, ui.Gap(1), layout.Rigid(func(gtx C) D { - return th.IconAction(p.root, &c.discard, icDiscard, i18n.T("diff.fileDiff.discard"), false).Layout(gtx) - })) } return layout.Flex{Alignment: layout.Middle}.Layout(gtx, children...) } -// title is the toggle's face: chevron, language badge, name, directory, and +func (c *fileCard) attachAction(th *ui.Theme, p *reviewPanel) layout.FlexChild { + return layout.Rigid(th.IconAction(p.root, &c.attach, icAttach, i18n.T("diff.fileDiff.addAsContext"), false).Layout) +} + +// hoverActions stand before the line counts, so what is there at rest does not +// move as they come and go. +func (c *fileCard) hoverActions(th *ui.Theme, p *reviewPanel, conflicted bool) []layout.FlexChild { + actions := []layout.FlexChild{ui.Gap(2), c.attachAction(th, p)} + if !conflicted && p.reverts(c.git.path) { + actions = append(actions, ui.Gap(1), + layout.Rigid(th.IconAction(p.root, &c.discard, icDiscard, i18n.T("diff.fileDiff.discard"), false).Layout)) + } + return actions +} + +// title is the toggle's face: chevron, file icon, name, directory, and // in a pull request whether the file changed since the review. -func (c *fileCard) title(gtx C, th *ui.Theme, light, changed bool) D { +func (c *fileCard) title(gtx C, th *ui.Theme, changed bool) D { chevron := icChevronRight if c.open { chevron = icChevronDown @@ -247,11 +263,7 @@ func (c *fileCard) title(gtx C, th *ui.Theme, light, changed bool) D { return layout.Flex{Alignment: layout.Middle}.Layout(gtx, layout.Rigid(func(gtx C) D { return chevron.Layout(gtx, ui.Space(3.5), th.MutedForeground) }), ui.Gap(2), - layout.Rigid(func(gtx C) D { - b := languageAbbr(c.git.path) - bg, fg := b.colors(th, light) - return th.AbbrBadge(b.abbr, bg, fg).Layout(gtx) - }), + layout.Rigid(th.FileIcon(c.git.path, reviewFileIcon).Layout), ui.Gap(2), layout.Rigid(func(gtx C) D { return th.Text(ui.TextXS, base).Weight(font.Medium).Truncated().Layout(gtx) }), ui.Gap(2), @@ -271,11 +283,8 @@ func (c *fileCard) title(gtx C, th *ui.Theme, light, changed bool) D { }) } -// badgeSize and badgeText are the badge's size-5 and text-[0.5625rem]. -const ( - badgeSize = unit.Dp(20) - badgeText = unit.Sp(9) -) +// reviewFileIcon is the icon's side in a file's header. +var reviewFileIcon = ui.Space(4) // body is what opening the file reveals: the binary line, the Markdown // preview, the whitespace line, or the diff with its right-click menu. diff --git a/native/cmd/lich-native/dock_review_markdown.go b/native/cmd/lich-native/dock_review_markdown.go index eeaeba504..c19081dc2 100644 --- a/native/cmd/lich-native/dock_review_markdown.go +++ b/native/cmd/lich-native/dock_review_markdown.go @@ -5,6 +5,7 @@ package main import ( "context" + "path" "path/filepath" "strings" @@ -144,3 +145,14 @@ func (u *window) openChatLink(session string, notify func(ui.Toast), url string) u.openBrowser(session) }, func(url string) { openLink(u.client, notify, url) }) } + +// extname is a path's lowercased extension without the dot, "" for none or +// a dotfile. +func extname(p string) string { + base := path.Base(p) + dot := strings.LastIndexByte(base, '.') + if dot <= 0 { + return "" + } + return strings.ToLower(base[dot+1:]) +} diff --git a/native/cmd/lich-native/dock_tabs.go b/native/cmd/lich-native/dock_tabs.go index fc228a181..f83b801be 100644 --- a/native/cmd/lich-native/dock_tabs.go +++ b/native/cmd/lich-native/dock_tabs.go @@ -2,7 +2,9 @@ package main import ( "image" + "strconv" + "gioui.org/font" "gioui.org/layout" "gioui.org/op/clip" "gioui.org/op/paint" @@ -12,15 +14,18 @@ import ( "github.com/lichdotdev/lich/native/ui/icons" ) -// The dock's tabs are a pill of icon-only buttons at its foot, centred: the -// dock's width follows the drag, and the pill stays where the eye looks for it. -// The pill sits on the dock's own Sidebar surface, so it is the folder's tray -// (folderTrayAlpha) to read against it. +// The dock's tabs stand at the left of its header: the one on screen spells +// out its name and what it holds, the others are icons. var ( - dockTabPillPad = ui.Space(1) - dockTabPillGap = ui.Space(0.5) - // dockTabBarInset keeps the pill off the dock's bottom and side edges. - dockTabBarInset = ui.Space(2) + dockTabGap = ui.Space(0.5) + // dockTabPadX, dockTabPartGap and dockTabIcon are the open tab's side + // padding, the gap between its parts and its glyph. + dockTabPadX = ui.Space(2.5) + dockTabPartGap = ui.Space(1.5) + dockTabIcon = ui.Space(3.5) + // dockTabOpenMin is the least room the open tab is left with: its icon and + // most of a short name. + dockTabOpenMin = ui.Space(24) // dockTabMark is the dot on a tab that holds something, near the icon's // top right corner. dockTabMark = ui.Space(1.25) @@ -33,23 +38,30 @@ type dockTabButton struct { tip ui.Tooltip } -// dockTabSpec is a tab as the pill draws it; mark puts a dot on its icon -// while the tab holds something (changes, artifacts), in ToneWait while -// waiting is set: Review over a checkout with conflicts. +// dockTabSpec is a tab as the header draws it. count is how much the tab +// holds (changed files, artifacts): a dot on its icon, in ToneWait while +// waiting is set (Review over a checkout with conflicts), and the number on +// the open tab, with added and deleted after it. type dockTabSpec struct { - glyph icons.Glyph - label string - mark bool - waiting bool + glyph icons.Glyph + label string + count int + added, deleted int + waiting bool } // tabSpecs are lich's tabs and then the extensions', in the order selectedTab // and pickTab count them. func (d *dock) tabSpecs(in dockInput) []dockTabSpec { + review := dockTabSpec{glyph: icDockReview, label: i18n.T("dock.rightDock.tabReview")} + if in.isGit { + review.count, review.added, review.deleted = in.git.Files, in.git.Added, in.git.Deleted + review.waiting = len(in.git.Conflicted) > 0 + } specs := []dockTabSpec{ {glyph: icDockCode, label: i18n.T("dock.rightDock.tabCode")}, - {glyph: icDockReview, label: i18n.T("dock.rightDock.tabReview"), mark: in.isGit && in.git.Files > 0, waiting: in.isGit && len(in.git.Conflicted) > 0}, - {glyph: icDockArtifacts, label: i18n.T("dock.rightDock.tabArtifacts"), mark: d.artifacts.count(in.sessionID) > 0}, + review, + {glyph: icDockArtifacts, label: i18n.T("dock.rightDock.tabArtifacts"), count: d.artifacts.count(in.sessionID)}, } for _, p := range in.placed { specs = append(specs, dockTabSpec{glyph: p.glyph, label: p.title}) @@ -67,9 +79,8 @@ func (d *dock) actTabs(gtx C) { } } -// tabBar is the strip under the body that holds the pill. It records the -// pill's width, which fitTabs keeps the dock from going under. -func (d *dock) tabBar(gtx C, th *ui.Theme, root *ui.Root, in dockInput) D { +// tabs is the row of tabs at the header's left, in the room its actions leave. +func (d *dock) tabs(gtx C, th *ui.Theme, root *ui.Root, in dockInput) D { specs := d.tabSpecs(in) d.placed = in.placed for len(d.tabButtons) < len(specs) { @@ -77,38 +88,79 @@ func (d *dock) tabBar(gtx C, th *ui.Theme, root *ui.Root, in dockInput) D { } d.tabButtons = d.tabButtons[:len(specs)] selected := d.selectedTab(in.placed) - pill := func(gtx C) D { - return layout.UniformInset(dockTabPillPad).Layout(gtx, func(gtx C) D { - var row []layout.FlexChild - for i, s := range specs { - if i > 0 { - row = append(row, layout.Rigid(layout.Spacer{Width: dockTabPillGap}.Layout)) - } - row = append(row, layout.Rigid(func(gtx C) D { return dockTabButtonLayout(gtx, th, root, d.tabButtons[i], s, i == selected) })) + room := gtx.Constraints.Max.X - (len(specs)-1)*gtx.Dp(ui.BarButtonSize+dockTabGap) + gtx.Constraints.Min = image.Point{} + var row []layout.FlexChild + for i, s := range specs { + if i > 0 { + row = append(row, layout.Rigid(layout.Spacer{Width: dockTabGap}.Layout)) + } + row = append(row, layout.Rigid(func(gtx C) D { + if i == selected { + gtx.Constraints.Max.X = room + return openDockTab(gtx, th, d.tabButtons[i], s) + } + return dockTabButtonLayout(gtx, th, root, d.tabButtons[i], s) + })) + } + return layout.Flex{Alignment: layout.Middle}.Layout(gtx, row...) +} + +// tabsNeed is the header's width with n tabs and the three actions a tab has +// at most in a dock too narrow to split. +func tabsNeed(gtx C, n int) int { + const actions = 3 + return gtx.Dp(dockTabOpenMin) + (n-1)*gtx.Dp(ui.BarButtonSize+dockTabGap) + actions*gtx.Dp(ui.IconActionSize) + gtx.Dp(dockHeaderSpare) +} + +// openDockTab is the tab on screen: its icon, its name, how much it holds and +// the lines changed. What does not fit goes, the lines first and then the +// count, and a name too long is cut. +func openDockTab(gtx C, th *ui.Theme, b *dockTabButton, s dockTabSpec) D { + ground := th.Over(th.Accent) + on := th.On(ground) + face := openDockTabFace(on, s) + for len(face) > 1 && naturalWidth(gtx, openDockTabRow(on, s, face)) > gtx.Constraints.Max.X { + face = face[:len(face)-1] + } + return b.click.Layout(gtx, func(gtx C) D { + return layout.Background{}.Layout(gtx, + func(gtx C) D { return ui.Fill(gtx, ground, ui.RadiusMD) }, + openDockTabRow(on, s, face)) + }) +} + +// openDockTabFace is what the open tab says after its icon, the last of it +// the first to go. +func openDockTabFace(th *ui.Theme, s dockTabSpec) []layout.Widget { + face := []layout.Widget{th.Text(ui.TextSM, s.label).Weight(font.Medium).Truncated().Layout} + if s.count > 0 { + face = append(face, th.Text(ui.TextXS, strconv.Itoa(s.count)).Muted().Layout) + } + if s.added > 0 || s.deleted > 0 { + face = append(face, th.DiffStat(s.added, s.deleted).Layout) + } + return face +} + +func openDockTabRow(th *ui.Theme, s dockTabSpec, face []layout.Widget) layout.Widget { + return func(gtx C) D { + return layout.Inset{Left: dockTabPadX, Right: dockTabPadX}.Layout(gtx, func(gtx C) D { + row := []layout.FlexChild{layout.Rigid(layout.Spacer{Height: ui.BarButtonSize}.Layout), layout.Rigid(func(gtx C) D { return s.glyph.Layout(gtx, dockTabIcon, th.Foreground) })} + for _, w := range face { + row = append(row, layout.Rigid(layout.Spacer{Width: dockTabPartGap}.Layout), layout.Rigid(w)) } return layout.Flex{Alignment: layout.Middle}.Layout(gtx, row...) }) } - var size image.Point - gtx.Constraints.Min.X = gtx.Constraints.Max.X - dims := layout.Center.Layout(gtx, func(gtx C) D { - return layout.UniformInset(dockTabBarInset).Layout(gtx, func(gtx C) D { - dims := layout.Background{}.Layout(gtx, - func(gtx C) D { return ui.Fill(gtx, th.Over(ui.Alpha(th.Accent, folderTrayAlpha)), ui.RadiusLG) }, pill) - size = dims.Size - return dims - }) - }) - d.tabBarWidth = size.X + 2*gtx.Dp(dockTabBarInset) - return dims } -// dockTabButtonLayout is one tab's button: the bar's icon button, accent while its tab is -// on screen, with the tab's name in a tooltip. -func dockTabButtonLayout(gtx C, th *ui.Theme, root *ui.Root, b *dockTabButton, s dockTabSpec, on bool) D { - button := func(gtx C) D { return th.BarIconButton(&b.click, s.glyph, on).Layout(gtx) } +// dockTabButtonLayout is a tab not on screen: the bar's icon button, with the +// tab's name in a tooltip. +func dockTabButtonLayout(gtx C, th *ui.Theme, root *ui.Root, b *dockTabButton, s dockTabSpec) D { + button := func(gtx C) D { return th.BarIconButton(&b.click, s.glyph, false).Layout(gtx) } tipped := func(gtx C) D { return th.Tooltip(root, &b.tip, s.label).Layout(gtx, button) } - if !s.mark { + if s.count == 0 { return tipped(gtx) } return layout.Stack{Alignment: layout.NE}.Layout(gtx, diff --git a/native/cmd/lich-native/dock_tabs_test.go b/native/cmd/lich-native/dock_tabs_test.go index 68561d39c..7e3c33bad 100644 --- a/native/cmd/lich-native/dock_tabs_test.go +++ b/native/cmd/lich-native/dock_tabs_test.go @@ -2,6 +2,7 @@ package main import ( "image" + "maps" "slices" "sort" "testing" @@ -10,19 +11,22 @@ import ( "gioui.org/f32" "gioui.org/io/input" "gioui.org/io/pointer" + "gioui.org/layout" "github.com/lichdotdev/lich/native/backend" "github.com/lichdotdev/lich/native/i18n" + "github.com/lichdotdev/lich/native/ui" ) -// tabButtonsOf are the centres of the pill's buttons, left to right: the -// clickables in the dock's bottom strip, each button once: the semantic tree -// lists it twice, under the tooltip's trigger and its own. +// tabButtonsOf are the centres of the dock's tabs, left to right: the +// clickables in its header as tall as a tab, which the actions are not, each +// once: the semantic tree lists a button twice, under the tooltip's trigger +// and its own. func tabButtonsOf(r *frameRig) []f32.Point { - strip := image.Rect(rigWindow.X/2, rigWindow.Y-80, rigWindow.X, rigWindow.Y) + strip := image.Rect(rigWindow.X/2, 0, rigWindow.X, 60) var found []image.Rectangle for _, n := range r.nodes() { - if b := n.Desc.Bounds; n.Desc.Gestures&input.ClickGesture != 0 && b.In(strip) && !slices.Contains(found, b) { + if b := n.Desc.Bounds; n.Desc.Gestures&input.ClickGesture != 0 && b.In(strip) && b.Dy() == int(ui.BarButtonSize) && !slices.Contains(found, b) { found = append(found, b) } } @@ -43,19 +47,19 @@ func TestDockTabButtonOpensItsTabInTheFrameThatTookTheClick(t *testing.T) { r.waitFor(t, "No uncommitted changes") u.dock.tab = dockCode r.settle(t) - buttons := tabButtonsOf(r) - if len(buttons) != dockBuiltinTabs { - t.Fatalf("%d tab buttons at the dock's foot, want %d", len(buttons), dockBuiltinTabs) + if got := len(tabButtonsOf(r)); got != dockBuiltinTabs { + t.Fatalf("%d tabs in the dock's header, want %d", got, dockBuiltinTabs) } for i, want := range []dockTab{dockReview, dockArtifacts, dockCode} { // The first Review frame starts a diff read, so its result may update the next frame. - r.queueClick(buttons[int(want)-1]) + // The open tab is wider than the others, so each click moves them. + r.queueClick(tabButtonsOf(r)[int(want)-1]) r.frame() if u.dock.tab != want { t.Fatalf("click %d: dock on %v, want %v", i, u.dock.tab, want) } if got := u.dock.selectedTab(nil); got != int(want)-1 { - t.Errorf("click %d: pill lights tab %d, want %d", i, got, int(want)-1) + t.Errorf("click %d: header lights tab %d, want %d", i, got, int(want)-1) } } } @@ -82,11 +86,68 @@ func TestDockReviewTabWaitsOverConflicts(t *testing.T) { d := &dock{artifacts: newArtifactsTab(new(artifactStore))} in := dockInput{isGit: true, git: backend.DiffStats{Files: 1, Conflicted: []string{"a.go"}}} review := d.tabSpecs(in)[1] - if !review.mark || !review.waiting { - t.Fatalf("Review over a conflict: mark %v, waiting %v; want both", review.mark, review.waiting) + if review.count != 1 || !review.waiting { + t.Fatalf("Review over a conflict: count %d, waiting %v; want 1, true", review.count, review.waiting) } in.git.Conflicted = nil if d.tabSpecs(in)[1].waiting { t.Error("Review without conflicts still waits") } } + +// headerSays is the text in the dock's header, left to right. +func headerSays(r *frameRig) []string { + strip := image.Rect(rigWindow.X/2, 0, rigWindow.X, 60) + at := map[string]int{} + for _, n := range r.nodes() { + if n.Desc.Label != "" && n.Desc.Bounds.In(strip) { + at[n.Desc.Label] = n.Desc.Bounds.Min.X + } + } + says := slices.Collect(maps.Keys(at)) + sort.Slice(says, func(i, j int) bool { return at[says[i]] < at[says[j]] }) + return says +} + +var changedInput = footerInput{path: "/repo", checkout: "/repo", isGit: true, git: backend.DiffStats{Files: 2, Added: 9, Deleted: 1}} + +func TestOpenDockTabSaysItsNameAndWhatItHolds(t *testing.T) { + _, r := diffRig(t, changedInput) + want := []string{i18n.T("dock.rightDock.tabReview"), "2", "+9", "-1"} + if got := headerSays(r); !slices.Equal(got, want) { + t.Errorf("the header says %q, want %q", got, want) + } + writeShot(t, r, "dock-review.png") +} + +func TestOpenDockTabDropsTheLinesBeforeItsName(t *testing.T) { + spec := dockTabSpec{glyph: icDockReview, label: "Review", count: 2, added: 9, deleted: 1} + says := func(width int) []string { + r := newFrameRig(rigWindow, func(gtx C, th *ui.Theme) { + gtx.Constraints = layout.Constraints{Max: image.Pt(width, rigWindow.Y)} + if d := openDockTab(gtx, th, new(dockTabButton), spec); d.Size.X > width { + t.Errorf("a tab %dpx wide in %dpx", d.Size.X, width) + } + }) + r.frame() + var out []string + for _, n := range r.nodes() { + if n.Desc.Label != "" && !slices.Contains(out, n.Desc.Label) { + out = append(out, n.Desc.Label) + } + } + return out + } + for _, c := range []struct { + width int + want []string + }{ + {300, []string{"Review", "2", "+9", "-1"}}, + {120, []string{"Review", "2"}}, + {int(dockTabOpenMin) - 10, []string{"Review"}}, + } { + if got := says(c.width); !slices.Equal(got, c.want) { + t.Errorf("in %dpx the tab says %q, want %q", c.width, got, c.want) + } + } +} diff --git a/native/cmd/lich-native/dock_tree_view.go b/native/cmd/lich-native/dock_tree_view.go index f4b2530e4..c2e4fe1bf 100644 --- a/native/cmd/lich-native/dock_tree_view.go +++ b/native/cmd/lich-native/dock_tree_view.go @@ -29,7 +29,7 @@ func (c *codeTab) treeBody(gtx C, th *ui.Theme) D { data, loading, err := c.tree.get() switch { case err != nil: - return th.Notice(i18n.T("dock.filesPanel.readFailed")).Layout(gtx) + return dockEmpty(gtx, th, icFolder, i18n.T("dock.filesPanel.readFailed")) case loading || data == nil: return th.Notice(i18n.T("dock.filesPanel.loading")).Layout(gtx) } @@ -41,7 +41,7 @@ func (c *codeTab) treeBody(gtx C, th *ui.Theme) D { layout.Flexed(1, func(gtx C) D { gtx.Constraints.Min = gtx.Constraints.Max if len(rows) == 0 { - return th.Notice(i18n.T("dock.filesPanel.empty")).Layout(gtx) + return dockEmpty(gtx, th, icFolder, i18n.T("dock.filesPanel.empty")) } return c.treeList(gtx, th, rows) }), diff --git a/native/cmd/lich-native/main.go b/native/cmd/lich-native/main.go index fb8fc74ad..6db0b5e88 100644 --- a/native/cmd/lich-native/main.go +++ b/native/cmd/lich-native/main.go @@ -930,7 +930,7 @@ func (u *window) body(gtx C, v stageView) (int, sidebarAction, error) { return D{Size: gtx.Constraints.Max} } if u.pulls.open && !v.home { - u.pulls.files = filesInput{activeID: v.in.sessionID, injector: u.injector, submitter: u.terms.submitter, light: u.light, code: u.code} + u.pulls.files = filesInput{activeID: v.in.sessionID, injector: u.injector, submitter: u.terms.submitter, code: u.code} u.applyPulls(u.pulls.layout(gtx, u.theme)) return D{Size: gtx.Constraints.Max} } diff --git a/native/cmd/lich-native/pulls_files.go b/native/cmd/lich-native/pulls_files.go index 464b28273..24a91aafc 100644 --- a/native/cmd/lich-native/pulls_files.go +++ b/native/cmd/lich-native/pulls_files.go @@ -70,7 +70,6 @@ type filesInput struct { activeID string injector func(id string) func(string) bool submitter func(id string) func(api.RequestOptions, func(error)) bool - light bool code godemirror.Theme } @@ -147,7 +146,7 @@ func (v *pullView) filesTab(gtx C, th *ui.Theme, p *pullsScreen, d backend.PRDet if target != d.URL { files.comments.move(d.URL, target) } - files.th, files.light, files.code, files.target, files.checkout = th.On(th.Sidebar), in.light, in.code, target, p.prCheckout(d) + files.th, files.code, files.target, files.checkout = th.On(th.Sidebar), in.code, target, p.prCheckout(d) files.inject, files.submit = in.injector(session), in.submitter(session) switch { // The cards fold by their ticks when first read, so they wait for them. diff --git a/native/i18n/locales/en/dock.json b/native/i18n/locales/en/dock.json index f67b97e8e..a88083557 100644 --- a/native/i18n/locales/en/dock.json +++ b/native/i18n/locales/en/dock.json @@ -24,7 +24,7 @@ "showSource": "Show source" }, "artifacts": { - "empty": "Pages and files this session's agent makes to show you appear here, with those of the project's other open sessions.", + "empty": "Pages and files the agents make appear here", "thisSession": "This session", "otherSessions": "Other sessions", "options": "Options for {name}", diff --git a/native/i18n/locales/es/dock.json b/native/i18n/locales/es/dock.json index 460aa1c2c..1270c2ffc 100644 --- a/native/i18n/locales/es/dock.json +++ b/native/i18n/locales/es/dock.json @@ -24,7 +24,7 @@ "showSource": "Mostrar código fuente" }, "artifacts": { - "empty": "Aquí aparecen las páginas y los archivos que el agente de esta sesión crea para mostrarte, junto con los de las otras sesiones abiertas del proyecto.", + "empty": "Aquí aparecen las páginas y los archivos que crean los agentes", "thisSession": "Esta sesión", "otherSessions": "Otras sesiones", "options": "Opciones de {name}", diff --git a/native/i18n/locales/ja/dock.json b/native/i18n/locales/ja/dock.json index 2cbeecd76..d255146d0 100644 --- a/native/i18n/locales/ja/dock.json +++ b/native/i18n/locales/ja/dock.json @@ -24,7 +24,7 @@ "showSource": "ソースを表示" }, "artifacts": { - "empty": "このセッションのエージェントが表示用に作ったページやファイルが、プロジェクト内でほかに開いているセッションの分と一緒にここに並びます。", + "empty": "エージェントが作ったページやファイルがここに並びます", "thisSession": "このセッション", "otherSessions": "ほかのセッション", "options": "{name} のオプション", diff --git a/native/i18n/locales/ko/dock.json b/native/i18n/locales/ko/dock.json index 105d4eefb..74623e3d3 100644 --- a/native/i18n/locales/ko/dock.json +++ b/native/i18n/locales/ko/dock.json @@ -24,7 +24,7 @@ "showSource": "소스 보기" }, "artifacts": { - "empty": "이 세션의 에이전트가 보여 주려고 만든 페이지와 파일이 여기에 나타납니다. 프로젝트에 열려 있는 다른 세션의 것도 함께 표시됩니다.", + "empty": "에이전트가 만든 페이지와 파일이 여기에 나타납니다", "thisSession": "이 세션", "otherSessions": "다른 세션", "options": "{name} 옵션", diff --git a/native/i18n/locales/pt-br/dock.json b/native/i18n/locales/pt-br/dock.json index 4e40ff0dd..34268ceaa 100644 --- a/native/i18n/locales/pt-br/dock.json +++ b/native/i18n/locales/pt-br/dock.json @@ -24,7 +24,7 @@ "showSource": "Mostrar código-fonte" }, "artifacts": { - "empty": "As páginas e os arquivos que o agente desta sessão cria para mostrar a você aparecem aqui, junto com os das outras sessões abertas do projeto.", + "empty": "As páginas e os arquivos que os agentes criam aparecem aqui", "thisSession": "Esta sessão", "otherSessions": "Outras sessões", "options": "Opções de {name}", diff --git a/native/i18n/locales/ru/dock.json b/native/i18n/locales/ru/dock.json index 1e4b2ed4e..10ae49410 100644 --- a/native/i18n/locales/ru/dock.json +++ b/native/i18n/locales/ru/dock.json @@ -24,7 +24,7 @@ "showSource": "Показать исходный код" }, "artifacts": { - "empty": "Здесь появляются страницы и файлы, которые агент этой сессии подготовил, чтобы показать вам. Рядом лежат артефакты других открытых сессий проекта.", + "empty": "Здесь появляются страницы и файлы, которые создают агенты", "thisSession": "Эта сессия", "otherSessions": "Другие сессии", "options": "Действия для {name}", diff --git a/native/i18n/locales/zh-cn/dock.json b/native/i18n/locales/zh-cn/dock.json index 351f62c7c..d2eec5246 100644 --- a/native/i18n/locales/zh-cn/dock.json +++ b/native/i18n/locales/zh-cn/dock.json @@ -24,7 +24,7 @@ "showSource": "显示源码" }, "artifacts": { - "empty": "此会话的智能体生成给你看的页面和文件会显示在这里,项目中其他已打开会话生成的也会一并列出。", + "empty": "智能体生成的页面和文件会显示在这里", "thisSession": "此会话", "otherSessions": "其他会话", "options": "{name} 的选项", diff --git a/native/ui/icon_button.go b/native/ui/icon_button.go index 7772ee177..34d74083e 100644 --- a/native/ui/icon_button.go +++ b/native/ui/icon_button.go @@ -35,7 +35,7 @@ func (a IconActionStyle) Layout(gtx C) D { tip := th.Tooltip(a.Root, &s.Tip, a.Label) return tip.Layout(gtx, func(gtx C) D { return s.Click.Layout(gtx, func(gtx C) D { - side := gtx.Dp(Space(6)) + side := gtx.Dp(IconActionSize) gtx.Constraints = layout.Exact(image.Pt(side, side)) fg := th.MutedForeground if a.Pressed || s.Click.Hovered() { @@ -83,6 +83,9 @@ func (b CornerButtonStyle) Layout(gtx C) D { }) } +// IconActionSize is the side of IconAction. +var IconActionSize = Space(6) + // BarButtonSize is the side of BarIconButton, the size-7 icon buttons of the // top strip. var BarButtonSize = Space(7)