Unify panel search behavior and polish console UI
This commit is contained in:
@@ -16,6 +16,9 @@ namespace Editor {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr float kProjectToolbarHeight = 26.0f;
|
||||
constexpr float kProjectToolbarPaddingY = 3.0f;
|
||||
|
||||
template <typename Fn>
|
||||
void QueueDeferredAction(std::function<void()>& pendingAction, Fn&& fn) {
|
||||
if (!pendingAction) {
|
||||
@@ -234,16 +237,17 @@ void ProjectPanel::Render() {
|
||||
void ProjectPanel::RenderToolbar() {
|
||||
UI::PanelToolbarScope toolbar(
|
||||
"ProjectToolbar",
|
||||
UI::ProjectPanelToolbarHeight(),
|
||||
kProjectToolbarHeight,
|
||||
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse,
|
||||
true,
|
||||
UI::ToolbarPadding(),
|
||||
ImVec2(UI::ToolbarPadding().x, kProjectToolbarPaddingY),
|
||||
UI::ToolbarItemSpacing(),
|
||||
UI::ProjectPanelToolbarBackgroundColor());
|
||||
if (!toolbar.IsOpen()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(0.0f, 0.0f));
|
||||
if (ImGui::BeginTable("##ProjectToolbarLayout", 2, ImGuiTableFlags_NoSavedSettings | ImGuiTableFlags_SizingStretchProp)) {
|
||||
ImGui::TableSetupColumn("##Spacer", ImGuiTableColumnFlags_WidthStretch);
|
||||
ImGui::TableSetupColumn("##Search", ImGuiTableColumnFlags_WidthFixed, 220.0f);
|
||||
@@ -257,6 +261,7 @@ void ProjectPanel::RenderToolbar() {
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
|
||||
void ProjectPanel::RenderFolderTreePane(IProjectManager& manager) {
|
||||
@@ -359,13 +364,13 @@ void ProjectPanel::RenderBrowserPane(IProjectManager& manager) {
|
||||
|
||||
std::vector<AssetItemPtr> visibleItems;
|
||||
const auto& items = manager.GetCurrentItems();
|
||||
const std::string search = m_searchBuffer;
|
||||
const UI::SearchQuery searchQuery(m_searchBuffer);
|
||||
if (m_renameState.IsActive() && manager.FindCurrentItemIndex(m_renameState.Item()) < 0) {
|
||||
CancelRename();
|
||||
}
|
||||
visibleItems.reserve(items.size());
|
||||
for (const auto& item : items) {
|
||||
if ((m_renameState.IsActive() && item && item->fullPath == m_renameState.Item()) || MatchesSearch(item, search)) {
|
||||
if ((m_renameState.IsActive() && item && item->fullPath == m_renameState.Item()) || MatchesSearch(item, searchQuery)) {
|
||||
visibleItems.push_back(item);
|
||||
}
|
||||
}
|
||||
@@ -375,7 +380,10 @@ void ProjectPanel::RenderBrowserPane(IProjectManager& manager) {
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, UI::ProjectBrowserPaneBackgroundColor());
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, UI::ProjectBrowserPanePadding());
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, UI::AssetGridSpacing());
|
||||
const bool bodyOpen = ImGui::BeginChild("ProjectBrowserBody", ImVec2(0.0f, 0.0f), false);
|
||||
const bool bodyOpen = ImGui::BeginChild(
|
||||
"ProjectBrowserBody",
|
||||
ImVec2(0.0f, 0.0f),
|
||||
ImGuiChildFlags_AlwaysUseWindowPadding);
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGui::PopStyleColor();
|
||||
if (!bodyOpen) {
|
||||
@@ -424,7 +432,7 @@ void ProjectPanel::RenderBrowserPane(IProjectManager& manager) {
|
||||
ImGui::SetCursorPosY(gridOrigin.y + rowCount * tileHeight + (rowCount - 1) * rowSpacing);
|
||||
}
|
||||
|
||||
if (visibleItems.empty() && !search.empty()) {
|
||||
if (visibleItems.empty() && !searchQuery.Empty()) {
|
||||
UI::DrawEmptyState(
|
||||
"No Search Results",
|
||||
"No assets match the current search");
|
||||
@@ -521,7 +529,12 @@ ProjectPanel::AssetItemInteraction ProjectPanel::RenderAssetItem(const AssetItem
|
||||
isDraggingThisItem,
|
||||
[&](ImDrawList* drawList, const ImVec2& iconMin, const ImVec2& iconMax) {
|
||||
if (item && item->canUseImagePreview &&
|
||||
UI::DrawTextureAssetPreview(drawList, iconMin, iconMax, item->fullPath)) {
|
||||
UI::DrawTextureAssetPreview(
|
||||
drawList,
|
||||
iconMin,
|
||||
iconMax,
|
||||
item->fullPath,
|
||||
m_context ? m_context->GetProjectPath() : std::string())) {
|
||||
return;
|
||||
}
|
||||
UI::DrawAssetIcon(drawList, iconMin, iconMax, iconKind);
|
||||
@@ -584,23 +597,15 @@ ProjectPanel::AssetItemInteraction ProjectPanel::RenderAssetItem(const AssetItem
|
||||
return interaction;
|
||||
}
|
||||
|
||||
bool ProjectPanel::MatchesSearch(const AssetItemPtr& item, const std::string& search) {
|
||||
bool ProjectPanel::MatchesSearch(const AssetItemPtr& item, const UI::SearchQuery& searchQuery) {
|
||||
if (!item) {
|
||||
return false;
|
||||
}
|
||||
if (search.empty()) {
|
||||
if (searchQuery.Empty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto toLower = [](unsigned char c) {
|
||||
return static_cast<char>(std::tolower(c));
|
||||
};
|
||||
|
||||
std::string itemName = item->name;
|
||||
std::string searchText = search;
|
||||
std::transform(itemName.begin(), itemName.end(), itemName.begin(), toLower);
|
||||
std::transform(searchText.begin(), searchText.end(), searchText.begin(), toLower);
|
||||
return itemName.find(searchText) != std::string::npos;
|
||||
return searchQuery.Matches(item->name);
|
||||
}
|
||||
|
||||
bool ProjectPanel::IsCurrentTreeBranch(const std::string& currentFolderPath, const std::string& folderPath) {
|
||||
|
||||
Reference in New Issue
Block a user