[nostalgia/core] Cleanup TileSheetEditor with new ImGui util functions
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Build / build (push) Successful in 2m21s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Build / build (push) Successful in 2m21s
				
			This commit is contained in:
		@@ -10,26 +10,30 @@
 | 
			
		||||
 | 
			
		||||
namespace studio::ig {
 | 
			
		||||
 | 
			
		||||
inline constexpr auto BtnSz = ImVec2{50, 22};
 | 
			
		||||
inline constexpr auto BtnSz = ImVec2{52, 22};
 | 
			
		||||
 | 
			
		||||
template<typename T>
 | 
			
		||||
class IDStackItem {
 | 
			
		||||
	private:
 | 
			
		||||
		T m_id;
 | 
			
		||||
	public:
 | 
			
		||||
		explicit IDStackItem(T id) noexcept: m_id(id) {
 | 
			
		||||
			ImGui::PushID(m_id);
 | 
			
		||||
		}
 | 
			
		||||
		~IDStackItem() noexcept {
 | 
			
		||||
			ImGui::PopID();
 | 
			
		||||
		}
 | 
			
		||||
		explicit IDStackItem(int id) noexcept;
 | 
			
		||||
		explicit IDStackItem(const char *id) noexcept;
 | 
			
		||||
		explicit IDStackItem(ox::CStringView id) noexcept;
 | 
			
		||||
		~IDStackItem() noexcept;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void centerNextWindow(turbine::Context &ctx) noexcept;
 | 
			
		||||
 | 
			
		||||
bool PushButton(ox::CStringView lbl, ImVec2 const&btnSz = BtnSz) noexcept;
 | 
			
		||||
 | 
			
		||||
void PopupBtns(float popupWidth, bool &popupOpen);
 | 
			
		||||
enum class PopupResponse {
 | 
			
		||||
	None,
 | 
			
		||||
	OK,
 | 
			
		||||
	Cancel,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
PopupResponse PopupControlsOkCancel(float popupWidth, bool &popupOpen);
 | 
			
		||||
 | 
			
		||||
[[nodiscard]]
 | 
			
		||||
bool BeginPopup(turbine::Context &ctx, ox::CStringView popupName, bool &show, ImVec2 const&sz = {285, 0});
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 *
 | 
			
		||||
 
 | 
			
		||||
@@ -10,6 +10,20 @@
 | 
			
		||||
 | 
			
		||||
namespace studio::ig {
 | 
			
		||||
 | 
			
		||||
IDStackItem::IDStackItem(int id) noexcept {
 | 
			
		||||
	ImGui::PushID(id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
IDStackItem::IDStackItem(const char *id) noexcept {
 | 
			
		||||
	ImGui::PushID(id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
IDStackItem::IDStackItem(ox::CStringView id) noexcept: IDStackItem(id.c_str()) {}
 | 
			
		||||
 | 
			
		||||
IDStackItem::~IDStackItem() noexcept {
 | 
			
		||||
	ImGui::PopID();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void centerNextWindow(turbine::Context &ctx) noexcept {
 | 
			
		||||
	auto const sz = turbine::getScreenSize(ctx);
 | 
			
		||||
	auto const screenW = static_cast<float>(sz.width);
 | 
			
		||||
@@ -22,19 +36,31 @@ bool PushButton(ox::CStringView lbl, ImVec2 const&btnSz) noexcept {
 | 
			
		||||
	return ImGui::Button(lbl.c_str(), btnSz);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void PopupBtns(float popupWidth, bool &popupOpen) {
 | 
			
		||||
PopupResponse PopupControlsOkCancel(float popupWidth, bool &popupOpen) {
 | 
			
		||||
	auto out = PopupResponse::None;
 | 
			
		||||
	constexpr auto btnSz = ImVec2{50, BtnSz.y};
 | 
			
		||||
	ImGui::Separator();
 | 
			
		||||
	ImGui::SetCursorPosX(popupWidth - 118);
 | 
			
		||||
	if (ImGui::Button("OK", btnSz)) {
 | 
			
		||||
		ImGui::CloseCurrentPopup();
 | 
			
		||||
		popupOpen = false;
 | 
			
		||||
		out = PopupResponse::OK;
 | 
			
		||||
	}
 | 
			
		||||
	ImGui::SameLine();
 | 
			
		||||
	if (ImGui::Button("Cancel", btnSz)) {
 | 
			
		||||
	if (ImGui::IsKeyDown(ImGuiKey_Escape) || ImGui::Button("Cancel", btnSz)) {
 | 
			
		||||
		ImGui::CloseCurrentPopup();
 | 
			
		||||
		popupOpen = false;
 | 
			
		||||
		out = PopupResponse::Cancel;
 | 
			
		||||
	}
 | 
			
		||||
	return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool BeginPopup(turbine::Context &ctx, ox::CStringView popupName, bool &show, ImVec2 const&sz) {
 | 
			
		||||
	constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
 | 
			
		||||
	ig::centerNextWindow(ctx);
 | 
			
		||||
	ImGui::OpenPopup(popupName.c_str());
 | 
			
		||||
	ImGui::SetNextWindowSize(sz);
 | 
			
		||||
	return ImGui::BeginPopupModal(popupName.c_str(), &show, modalFlags);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ComboBox(
 | 
			
		||||
@@ -48,7 +74,6 @@ bool ComboBox(
 | 
			
		||||
			const auto selected = (selectedIdx == i);
 | 
			
		||||
			if (ImGui::Selectable(list[i].c_str(), selected) && selectedIdx != i) {
 | 
			
		||||
				selectedIdx = i;
 | 
			
		||||
				//oxLogError(m_model.setPalette(list[n]));
 | 
			
		||||
				out = true;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user