Stagger popup panels

When opening a popup panel on top of another one, offset the new one a little
bit down and to the right.
This commit is contained in:
Stefan Haller 2024-06-26 08:02:56 +02:00
parent 1ab1fb3599
commit 4b6479b25f

View file

@ -116,15 +116,23 @@ func wrapMessageToWidth(wrap bool, message string, width int) []string {
return wrappedLines return wrappedLines
} }
func (self *ConfirmationHelper) getPopupPanelDimensionsForContentHeight(panelWidth, contentHeight int) (int, int, int, int) { func (self *ConfirmationHelper) getPopupPanelDimensionsForContentHeight(panelWidth, contentHeight int, parentPopupContext types.Context) (int, int, int, int) {
return self.getPopupPanelDimensionsAux(panelWidth, contentHeight) return self.getPopupPanelDimensionsAux(panelWidth, contentHeight, parentPopupContext)
} }
func (self *ConfirmationHelper) getPopupPanelDimensionsAux(panelWidth int, panelHeight int) (int, int, int, int) { func (self *ConfirmationHelper) getPopupPanelDimensionsAux(panelWidth int, panelHeight int, parentPopupContext types.Context) (int, int, int, int) {
width, height := self.c.GocuiGui().Size() width, height := self.c.GocuiGui().Size()
if panelHeight > height*3/4 { if panelHeight > height*3/4 {
panelHeight = height * 3 / 4 panelHeight = height * 3 / 4
} }
if parentPopupContext != nil {
// If there's already a popup on the screen, offset the new one from its
// parent so that it's clearly distinguished from the parent
x0, y0, _, _ := parentPopupContext.GetView().Dimensions()
x0 += 2
y0 += 1
return x0, y0, x0 + panelWidth, y0 + panelHeight + 1
}
return width/2 - panelWidth/2, return width/2 - panelWidth/2,
height/2 - panelHeight/2 - panelHeight%2 - 1, height/2 - panelHeight/2 - panelHeight%2 - 1,
width/2 + panelWidth/2, width/2 + panelWidth/2,
@ -316,19 +324,22 @@ func (self *ConfirmationHelper) getSelectedSuggestionValue() string {
} }
func (self *ConfirmationHelper) ResizeCurrentPopupPanels() { func (self *ConfirmationHelper) ResizeCurrentPopupPanels() {
var parentPopupContext types.Context
for _, c := range self.c.CurrentPopupContexts() { for _, c := range self.c.CurrentPopupContexts() {
switch c { switch c {
case self.c.Contexts().Menu: case self.c.Contexts().Menu:
self.resizeMenu() self.resizeMenu(parentPopupContext)
case self.c.Contexts().Confirmation, self.c.Contexts().Suggestions: case self.c.Contexts().Confirmation, self.c.Contexts().Suggestions:
self.resizeConfirmationPanel() self.resizeConfirmationPanel(parentPopupContext)
case self.c.Contexts().CommitMessage, self.c.Contexts().CommitDescription: case self.c.Contexts().CommitMessage, self.c.Contexts().CommitDescription:
self.ResizeCommitMessagePanels() self.ResizeCommitMessagePanels(parentPopupContext)
} }
parentPopupContext = c
} }
} }
func (self *ConfirmationHelper) resizeMenu() { func (self *ConfirmationHelper) resizeMenu(parentPopupContext types.Context) {
// we want the unfiltered length here so that if we're filtering we don't // we want the unfiltered length here so that if we're filtering we don't
// resize the window // resize the window
itemCount := self.c.Contexts().Menu.UnfilteredLen() itemCount := self.c.Contexts().Menu.UnfilteredLen()
@ -336,7 +347,7 @@ func (self *ConfirmationHelper) resizeMenu() {
panelWidth := self.getPopupPanelWidth() panelWidth := self.getPopupPanelWidth()
contentWidth := panelWidth - 2 // minus 2 for the frame contentWidth := panelWidth - 2 // minus 2 for the frame
promptLinesCount := self.layoutMenuPrompt(contentWidth) promptLinesCount := self.layoutMenuPrompt(contentWidth)
x0, y0, x1, y1 := self.getPopupPanelDimensionsForContentHeight(panelWidth, itemCount+offset+promptLinesCount) x0, y0, x1, y1 := self.getPopupPanelDimensionsForContentHeight(panelWidth, itemCount+offset+promptLinesCount, parentPopupContext)
menuBottom := y1 - offset menuBottom := y1 - offset
_, _ = self.c.GocuiGui().SetView(self.c.Views().Menu.Name(), x0, y0, x1, menuBottom, 0) _, _ = self.c.GocuiGui().SetView(self.c.Views().Menu.Name(), x0, y0, x1, menuBottom, 0)
@ -379,7 +390,7 @@ func (self *ConfirmationHelper) layoutMenuPrompt(contentWidth int) int {
return len(promptLines) return len(promptLines)
} }
func (self *ConfirmationHelper) resizeConfirmationPanel() { func (self *ConfirmationHelper) resizeConfirmationPanel(parentPopupContext types.Context) {
suggestionsViewHeight := 0 suggestionsViewHeight := 0
if self.c.Views().Suggestions.Visible { if self.c.Views().Suggestions.Visible {
suggestionsViewHeight = 11 suggestionsViewHeight = 11
@ -392,7 +403,7 @@ func (self *ConfirmationHelper) resizeConfirmationPanel() {
wrap = false wrap = false
} }
panelHeight := getMessageHeight(wrap, prompt, panelWidth) + suggestionsViewHeight panelHeight := getMessageHeight(wrap, prompt, panelWidth) + suggestionsViewHeight
x0, y0, x1, y1 := self.getPopupPanelDimensionsAux(panelWidth, panelHeight) x0, y0, x1, y1 := self.getPopupPanelDimensionsAux(panelWidth, panelHeight, parentPopupContext)
confirmationViewBottom := y1 - suggestionsViewHeight confirmationViewBottom := y1 - suggestionsViewHeight
_, _ = self.c.GocuiGui().SetView(self.c.Views().Confirmation.Name(), x0, y0, x1, confirmationViewBottom, 0) _, _ = self.c.GocuiGui().SetView(self.c.Views().Confirmation.Name(), x0, y0, x1, confirmationViewBottom, 0)
@ -400,7 +411,7 @@ func (self *ConfirmationHelper) resizeConfirmationPanel() {
_, _ = self.c.GocuiGui().SetView(self.c.Views().Suggestions.Name(), x0, suggestionsViewTop, x1, suggestionsViewTop+suggestionsViewHeight, 0) _, _ = self.c.GocuiGui().SetView(self.c.Views().Suggestions.Name(), x0, suggestionsViewTop, x1, suggestionsViewTop+suggestionsViewHeight, 0)
} }
func (self *ConfirmationHelper) ResizeCommitMessagePanels() { func (self *ConfirmationHelper) ResizeCommitMessagePanels(parentPopupContext types.Context) {
panelWidth := self.getPopupPanelWidth() panelWidth := self.getPopupPanelWidth()
content := self.c.Views().CommitDescription.TextArea.GetContent() content := self.c.Views().CommitDescription.TextArea.GetContent()
summaryViewHeight := 3 summaryViewHeight := 3
@ -409,7 +420,7 @@ func (self *ConfirmationHelper) ResizeCommitMessagePanels() {
if panelHeight < minHeight { if panelHeight < minHeight {
panelHeight = minHeight panelHeight = minHeight
} }
x0, y0, x1, y1 := self.getPopupPanelDimensionsAux(panelWidth, panelHeight) x0, y0, x1, y1 := self.getPopupPanelDimensionsAux(panelWidth, panelHeight, parentPopupContext)
_, _ = self.c.GocuiGui().SetView(self.c.Views().CommitMessage.Name(), x0, y0, x1, y0+summaryViewHeight-1, 0) _, _ = self.c.GocuiGui().SetView(self.c.Views().CommitMessage.Name(), x0, y0, x1, y0+summaryViewHeight-1, 0)
_, _ = self.c.GocuiGui().SetView(self.c.Views().CommitDescription.Name(), x0, y0+summaryViewHeight, x1, y1+summaryViewHeight, 0) _, _ = self.c.GocuiGui().SetView(self.c.Views().CommitDescription.Name(), x0, y0+summaryViewHeight, x1, y1+summaryViewHeight, 0)