From 7883e0026e679eb3bcead547fc6ad7f6fc296095 Mon Sep 17 00:00:00 2001 From: eeeXun Date: Sun, 30 Apr 2023 13:14:54 +0800 Subject: [PATCH] refactor: write show Popout into function --- ui.go | 54 ++++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/ui.go b/ui.go index 31c1ed5..8bb6610 100644 --- a/ui.go +++ b/ui.go @@ -233,6 +233,26 @@ func attachItems(center bool, direction int, items ...Item) *tview.Flex { return container } +func showLangPopout() { + mainPage.HidePage("stylePopOut") + mainPage.HidePage("keyMapPopOut") + mainPage.ShowPage("langPopOut") + app.SetFocus(langCycle.GetCurrentUI()) +} + +func showStylePopout() { + mainPage.HidePage("langPopOut") + mainPage.HidePage("keyMapPopOut") + mainPage.ShowPage("stylePopOut") + app.SetFocus(styleCycle.GetCurrentUI()) +} + +func showKeyMapPopout() { + mainPage.HidePage("langPopOut") + mainPage.HidePage("stylePopOut") + mainPage.ShowPage("keyMapPopOut") +} + func uiInit() { // input/output srcInput.SetBorder(true) @@ -402,23 +422,9 @@ func uiInit() { mainPage.HidePage("keyMapPopOut") } }) - langButton.SetSelectedFunc(func() { - mainPage.HidePage("stylePopOut") - mainPage.HidePage("keyMapPopOut") - mainPage.ShowPage("langPopOut") - app.SetFocus(langCycle.GetCurrentUI()) - }) - styleButton.SetSelectedFunc(func() { - mainPage.HidePage("langPopOut") - mainPage.HidePage("keyMapPopOut") - mainPage.ShowPage("stylePopOut") - app.SetFocus(styleCycle.GetCurrentUI()) - }) - keyMapButton.SetSelectedFunc(func() { - mainPage.HidePage("langPopOut") - mainPage.HidePage("stylePopOut") - mainPage.ShowPage("keyMapPopOut") - }) + langButton.SetSelectedFunc(showLangPopout) + styleButton.SetSelectedFunc(showStylePopout) + keyMapButton.SetSelectedFunc(showKeyMapPopout) } func mainPageHandler(event *tcell.EventKey) *tcell.EventKey { @@ -537,19 +543,11 @@ func popOutHandler(event *tcell.EventKey) *tcell.EventKey { switch ch { case '1': - mainPage.HidePage("stylePopOut") - mainPage.HidePage("keyMapPopOut") - mainPage.ShowPage("langPopOut") - app.SetFocus(langCycle.GetCurrentUI()) + showLangPopout() case '2': - mainPage.HidePage("langPopOut") - mainPage.HidePage("keyMapPopOut") - mainPage.ShowPage("stylePopOut") - app.SetFocus(styleCycle.GetCurrentUI()) + showStylePopout() case '3': - mainPage.HidePage("langPopOut") - mainPage.HidePage("stylePopOut") - mainPage.ShowPage("keyMapPopOut") + showKeyMapPopout() } return event