New song dialog: auto focus on pop up + reset search box

This commit is contained in:
YohananDiamond 2023-04-03 00:05:25 -03:00
parent 5026f62713
commit 72ef39db60
2 changed files with 12 additions and 0 deletions

View File

@ -4840,6 +4840,7 @@ bool FurnaceGUI::loop() {
} }
if (displayNew) { if (displayNew) {
newSongQuery = "";
displayNew=false; displayNew=false;
ImGui::OpenPopup("New Song"); ImGui::OpenPopup("New Song");
} }

View File

@ -23,6 +23,9 @@
#include <algorithm> #include <algorithm>
void FurnaceGUI::drawNewSong() { void FurnaceGUI::drawNewSong() {
// Be sure to reset this to true when the popup is closed
static bool firstFrame = true;
bool accepted=false; bool accepted=false;
ImGui::PushFont(bigFont); ImGui::PushFont(bigFont);
@ -34,6 +37,10 @@ void FurnaceGUI::drawNewSong() {
avail.y-=ImGui::GetFrameHeightWithSpacing(); avail.y-=ImGui::GetFrameHeightWithSpacing();
if (ImGui::BeginChild("sysPickerC",avail,false,ImGuiWindowFlags_NoScrollWithMouse|ImGuiWindowFlags_NoScrollbar)) { if (ImGui::BeginChild("sysPickerC",avail,false,ImGuiWindowFlags_NoScrollWithMouse|ImGuiWindowFlags_NoScrollbar)) {
if (firstFrame) {
ImGui::SetKeyboardFocusHere();
firstFrame = false;
}
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
if (ImGui::InputTextWithHint("##SysSearch","Search...",&newSongQuery)) { if (ImGui::InputTextWithHint("##SysSearch","Search...",&newSongQuery)) {
String lowerCase=newSongQuery; String lowerCase=newSongQuery;
@ -122,10 +129,12 @@ void FurnaceGUI::drawNewSong() {
if (ImGui::Button("I'm feeling lucky")) { if (ImGui::Button("I'm feeling lucky")) {
if (sysCategories.size()==0) { if (sysCategories.size()==0) {
firstFrame = true;
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} else { } else {
FurnaceGUISysCategory* newSystemCat=&sysCategories[rand()%sysCategories.size()]; FurnaceGUISysCategory* newSystemCat=&sysCategories[rand()%sysCategories.size()];
if (newSystemCat->systems.size()==0) { if (newSystemCat->systems.size()==0) {
firstFrame = true;
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} else { } else {
unsigned int selection=rand()%newSystemCat->systems.size(); unsigned int selection=rand()%newSystemCat->systems.size();
@ -139,6 +148,7 @@ void FurnaceGUI::drawNewSong() {
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Cancel")) { if (ImGui::Button("Cancel")) {
firstFrame = true;
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} }
@ -157,6 +167,7 @@ void FurnaceGUI::drawNewSong() {
selEnd=SelectionPoint(); selEnd=SelectionPoint();
cursor=SelectionPoint(); cursor=SelectionPoint();
updateWindowTitle(); updateWindowTitle();
firstFrame = true;
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} }
} }