From 451ff64b6ff94d6b522ec0e7c837e94eb609b920 Mon Sep 17 00:00:00 2001 From: Bruno Date: Sat, 1 May 2021 16:39:01 +0200 Subject: [PATCH] Cosmetics Moved string truncate to BaseToolkit, fixed SystemToolkit max memory, clean left panel UI --- BaseToolkit.cpp | 13 +++- BaseToolkit.h | 4 +- ImGuiVisitor.cpp | 4 +- SystemToolkit.cpp | 12 +--- SystemToolkit.h | 6 +- UserInterfaceManager.cpp | 136 +++++++++++++++++++++++++-------------- defines.h | 2 +- 7 files changed, 108 insertions(+), 69 deletions(-) diff --git a/BaseToolkit.cpp b/BaseToolkit.cpp index 6b00a34..0547c62 100644 --- a/BaseToolkit.cpp +++ b/BaseToolkit.cpp @@ -49,7 +49,7 @@ std::string BaseToolkit::uniqueName(const std::string &basename, std::list N ) { + trunc = std::string("...") + path.substr( l - N + 3 ); + } + return trunc; +} diff --git a/BaseToolkit.h b/BaseToolkit.h index ecef3b0..7992fb8 100644 --- a/BaseToolkit.h +++ b/BaseToolkit.h @@ -14,7 +14,7 @@ uint64_t uniqueId(); std::string uniqueName(const std::string &basename, std::list existingnames); // get a transliteration to Latin of any string -std::string transliterate(std::string input); +std::string transliterate(const std::string &input); // get a string to display memory size with unit KB, MB, GB, TB std::string byte_to_string(long b); @@ -22,6 +22,8 @@ std::string byte_to_string(long b); // get a string to display bit size with unit Kbit, MBit, Gbit, Tbit std::string bits_to_string(long b); +// Truncate a string to display the right most N characters (e.g. ./home/me/toto.mpg -> ...ome/me/toto.mpg) +std::string trunc_string(const std::string& path, int N); } diff --git a/ImGuiVisitor.cpp b/ImGuiVisitor.cpp index 4926612..a7c7ad4 100644 --- a/ImGuiVisitor.cpp +++ b/ImGuiVisitor.cpp @@ -555,7 +555,7 @@ void ImGuiVisitor::visit (MediaSource& s) UserInterface::manager().showMediaPlayer( s.mediaplayer()); std::string path = SystemToolkit::path_filename(s.path()); - std::string label = SystemToolkit::trunc_filename(path, 25); + std::string label = BaseToolkit::trunc_string(path, 25); label = BaseToolkit::transliterate(label); ImGuiToolkit::ButtonOpenUrl( label.c_str(), path.c_str(), ImVec2(IMGUI_RIGHT_ALIGN, 0) ); @@ -590,7 +590,7 @@ void ImGuiVisitor::visit (SessionFileSource& s) ImGui::Text("File"); std::string path = SystemToolkit::path_filename(s.path()); - std::string label = SystemToolkit::trunc_filename(path, 25); + std::string label = BaseToolkit::trunc_string(path, 25); label = BaseToolkit::transliterate(label); ImGuiToolkit::ButtonOpenUrl( label.c_str(), path.c_str(), ImVec2(IMGUI_RIGHT_ALIGN, 0) ); diff --git a/SystemToolkit.cpp b/SystemToolkit.cpp index d4ac174..74bbf67 100644 --- a/SystemToolkit.cpp +++ b/SystemToolkit.cpp @@ -84,7 +84,7 @@ long SystemToolkit::memory_max_usage() { struct rusage r_usage; getrusage(RUSAGE_SELF,&r_usage); - return r_usage.ru_maxrss; + return 1024 * r_usage.ru_maxrss; // return r_usage.ru_isrss; } @@ -132,16 +132,6 @@ string SystemToolkit::path_filename(const string& path) return path.substr(0, path.find_last_of(PATH_SEP) + 1); } -string SystemToolkit::trunc_filename(const string& path, int lenght) -{ - string trunc = path; - int l = path.size(); - if ( l > lenght ) { - trunc = string("...") + path.substr( l - lenght + 3 ); - } - return trunc; -} - string SystemToolkit::extension_filename(const string& filename) { string ext = filename.substr(filename.find_last_of(".") + 1); diff --git a/SystemToolkit.h b/SystemToolkit.h index a5db2e4..0bf3809 100644 --- a/SystemToolkit.h +++ b/SystemToolkit.h @@ -42,9 +42,6 @@ namespace SystemToolkit // extract the path of a filename from a full URI (e.g. file:://home/me/toto.mpg -> file:://home/me/) std::string path_filename(const std::string& path); - // Truncate a full filename to display the right part (e.g. file:://home/me/toto.mpg -> ...ome/me/toto.mpg) - std::string trunc_filename(const std::string& path, int lenght); - // extract the extension of a filename std::string extension_filename(const std::string& filename); @@ -69,8 +66,9 @@ namespace SystemToolkit // try to execute a command void execute(const std::string& command); - // return memory resident set size used (in bytes) + // return memory used (in bytes) long memory_usage(); + // return maximum memory resident set size used (in bytes) long memory_max_usage(); } diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index b61b32a..dcc97df 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -1880,7 +1880,7 @@ void ToolBox::Render() ImGui::PlotLines("LinesRender", recorded_values[0], PLOT_ARRAY_SIZE, values_index, overlay, recorded_bounds[0][0], recorded_bounds[0][1], plot_size); sprintf(overlay, "Update time %.1f ms (%.1f FPS)", recorded_sum[1] / float(PLOT_ARRAY_SIZE), (float(PLOT_ARRAY_SIZE) * 1000.f) / recorded_sum[1]); ImGui::PlotHistogram("LinesMixer", recorded_values[1], PLOT_ARRAY_SIZE, values_index, overlay, recorded_bounds[1][0], recorded_bounds[1][1], plot_size); - sprintf(overlay, "Memory %.1f MB", recorded_values[2][(values_index+PLOT_ARRAY_SIZE-1) % PLOT_ARRAY_SIZE] ); + sprintf(overlay, "Memory %.1f MB / %s", recorded_values[2][(values_index+PLOT_ARRAY_SIZE-1) % PLOT_ARRAY_SIZE], BaseToolkit::byte_to_string(SystemToolkit::memory_max_usage()).c_str() ); ImGui::PlotLines("LinesMemo", recorded_values[2], PLOT_ARRAY_SIZE, values_index, overlay, recorded_bounds[2][0], recorded_bounds[2][1], plot_size); ImGui::End(); @@ -2705,7 +2705,7 @@ void Navigator::RenderNewPannel() Log::Notify("No file selected."); } else { std::string label = BaseToolkit::transliterate( open_filename ); - label = label.substr( label.size() - MIN( 35, label.size()) ); + label = BaseToolkit::trunc_string(label, 35); new_source_preview_.setSource( Mixer::manager().createSourceFile(open_filename), label); } } @@ -2721,7 +2721,7 @@ void Navigator::RenderNewPannel() std::string recentpath(*path); if ( SystemToolkit::file_exists(recentpath)) { std::string label = BaseToolkit::transliterate( recentpath ); - label = SystemToolkit::trunc_filename(label, 35); + label = BaseToolkit::trunc_string(label, 35); if (ImGui::Selectable( label.c_str() )) { new_source_preview_.setSource( Mixer::manager().createSourceFile(recentpath.c_str()), label); } @@ -2874,20 +2874,57 @@ void Navigator::RenderMainPannelVimix() ImGui::EndMenu(); } - // Session panel ImGui::SetCursorPosY(width_); - ImGui::Text("Sessions"); +// // +// // Buttons to show WINDOWS +// // +// ImGui::Spacing(); +// ImGui::Text("Windows"); +// ImGui::Spacing(); + +// ImGuiToolkit::PushFont(ImGuiToolkit::FONT_LARGE); +// std::string tooltip_ = ""; + +// if ( ImGuiToolkit::IconButton( Rendering::manager().mainWindow().isFullscreen() ? ICON_FA_COMPRESS_ALT : ICON_FA_EXPAND_ALT ) ) +// Rendering::manager().mainWindow().toggleFullscreen(); +// if (ImGui::IsItemHovered()) +// tooltip_ = "Fullscreen " CTRL_MOD "Shift+F"; + +// ImGui::SameLine(0, 40); +// if ( ImGuiToolkit::IconButton( ICON_FA_STICKY_NOTE ) ) +// Mixer::manager().session()->addNote(); +// if (ImGui::IsItemHovered()) +// tooltip_ = "New note " CTRL_MOD "Shift+N"; + +// ImGui::SameLine(0, 40); +// if ( ImGuiToolkit::IconButton( ICON_FA_FILM ) ) +// Settings::application.widget.media_player = true; +// if (ImGui::IsItemHovered()) +// tooltip_ = "Player " CTRL_MOD "P"; + +// ImGui::SameLine(0, 40); +// if ( ImGuiToolkit::IconButton( ICON_FA_DESKTOP ) ) +// Settings::application.widget.preview = true; +// if (ImGui::IsItemHovered()) +// tooltip_ = "Output " CTRL_MOD "D"; + +// ImGui::PopFont(); +// if (!tooltip_.empty()) { +// ImGuiToolkit::ToolTip(tooltip_.substr(0, tooltip_.size()-12).c_str(), tooltip_.substr(tooltip_.size()-12, 12).c_str()); +// } + + // + // SESSION panel + // + ImGui::Spacing(); + ImGui::Text("Sessions"); static bool selection_session_mode_changed = true; static int selection_session_mode = 0; - // - // Session quick selection & fading - // - // Show combo box of quick selection modes ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); - if (ImGui::BeginCombo("##SelectionSession", SystemToolkit::trunc_filename(Settings::application.recentFolders.path, 25).c_str() )) { + if (ImGui::BeginCombo("##SelectionSession", BaseToolkit::trunc_string(Settings::application.recentFolders.path, 25).c_str() )) { // Option 0 : recent files if (ImGui::Selectable( ICON_FA_CLOCK IMGUI_LABEL_RECENT_FILES) ) { @@ -2898,7 +2935,7 @@ void Navigator::RenderMainPannelVimix() // Options 1 : known folders for(auto foldername = Settings::application.recentFolders.filenames.begin(); foldername != Settings::application.recentFolders.filenames.end(); foldername++) { - std::string f = std::string(ICON_FA_FOLDER) + " " + SystemToolkit::trunc_filename( *foldername, 40); + std::string f = std::string(ICON_FA_FOLDER) + " " + BaseToolkit::trunc_string( *foldername, 40); if (ImGui::Selectable( f.c_str() )) { // remember which path was selected Settings::application.recentFolders.path.assign(*foldername); @@ -3094,44 +3131,10 @@ void Navigator::RenderMainPannelVimix() // come back... ImGui::SetCursorPos(pos_bot); + // - // Buttons to show WINDOWS + // Status // - ImGui::Spacing(); - ImGui::Text("Windows"); - ImGui::Spacing(); - - ImGuiToolkit::PushFont(ImGuiToolkit::FONT_LARGE); - std::string tooltip_ = ""; - - if ( ImGuiToolkit::IconButton( Rendering::manager().mainWindow().isFullscreen() ? ICON_FA_COMPRESS_ALT : ICON_FA_EXPAND_ALT ) ) - Rendering::manager().mainWindow().toggleFullscreen(); - if (ImGui::IsItemHovered()) - tooltip_ = "Fullscreen " CTRL_MOD "Shift+F"; - - ImGui::SameLine(0, 40); - if ( ImGuiToolkit::IconButton( ICON_FA_STICKY_NOTE ) ) - Mixer::manager().session()->addNote(); - if (ImGui::IsItemHovered()) - tooltip_ = "New note " CTRL_MOD "Shift+N"; - - ImGui::SameLine(0, 40); - if ( ImGuiToolkit::IconButton( ICON_FA_FILM ) ) - Settings::application.widget.media_player = true; - if (ImGui::IsItemHovered()) - tooltip_ = "Player " CTRL_MOD "P"; - - ImGui::SameLine(0, 40); - if ( ImGuiToolkit::IconButton( ICON_FA_DESKTOP ) ) - Settings::application.widget.preview = true; - if (ImGui::IsItemHovered()) - tooltip_ = "Output " CTRL_MOD "D"; - - ImGui::PopFont(); - if (!tooltip_.empty()) { - ImGuiToolkit::ToolTip(tooltip_.substr(0, tooltip_.size()-12).c_str(), tooltip_.substr(tooltip_.size()-12, 12).c_str()); - } - ImGui::Spacing(); ImGui::Text("Status"); ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); @@ -3139,7 +3142,6 @@ void Navigator::RenderMainPannelVimix() // // UNDO History - // if (Settings::application.pannel_history_mode > 0) { static uint _over = 0; @@ -3227,7 +3229,6 @@ void Navigator::RenderMainPannelVimix() } // // SNAPSHOTS - // else { static uint64_t _over = 0; static bool _tooltip = 0; @@ -3369,6 +3370,43 @@ void Navigator::RenderMainPannelVimix() // } } + // + // Buttons to show WINDOWS + // + ImGui::Spacing(); + ImGui::Text("Windows"); + ImGui::Spacing(); + + ImGuiToolkit::PushFont(ImGuiToolkit::FONT_LARGE); + std::string tooltip_ = ""; + + if ( ImGuiToolkit::IconButton( Rendering::manager().mainWindow().isFullscreen() ? ICON_FA_COMPRESS_ALT : ICON_FA_EXPAND_ALT ) ) + Rendering::manager().mainWindow().toggleFullscreen(); + if (ImGui::IsItemHovered()) + tooltip_ = "Fullscreen " CTRL_MOD "Shift+F"; + + ImGui::SameLine(0, 40); + if ( ImGuiToolkit::IconButton( ICON_FA_STICKY_NOTE ) ) + Mixer::manager().session()->addNote(); + if (ImGui::IsItemHovered()) + tooltip_ = "New note " CTRL_MOD "Shift+N"; + + ImGui::SameLine(0, 40); + if ( ImGuiToolkit::IconButton( ICON_FA_FILM ) ) + Settings::application.widget.media_player = true; + if (ImGui::IsItemHovered()) + tooltip_ = "Player " CTRL_MOD "P"; + + ImGui::SameLine(0, 40); + if ( ImGuiToolkit::IconButton( ICON_FA_DESKTOP ) ) + Settings::application.widget.preview = true; + if (ImGui::IsItemHovered()) + tooltip_ = "Output " CTRL_MOD "D"; + + ImGui::PopFont(); + if (!tooltip_.empty()) { + ImGuiToolkit::ToolTip(tooltip_.substr(0, tooltip_.size()-12).c_str(), tooltip_.substr(tooltip_.size()-12, 12).c_str()); + } } diff --git a/defines.h b/defines.h index 69b304a..250882d 100644 --- a/defines.h +++ b/defines.h @@ -69,7 +69,7 @@ #define IMGUI_TITLE_SHADEREDITOR ICON_FA_CODE " Code Editor" #define IMGUI_TITLE_PREVIEW ICON_FA_DESKTOP " Ouput" #define IMGUI_TITLE_DELETE ICON_FA_BROOM " Delete?" -#define IMGUI_LABEL_RECENT_FILES " Select recent" +#define IMGUI_LABEL_RECENT_FILES " Recent files" #define IMGUI_RIGHT_ALIGN -3.5f * ImGui::GetTextLineHeightWithSpacing() #define IMGUI_TOP_ALIGN 10 #define IMGUI_COLOR_OVERLAY IM_COL32(5, 5, 5, 150)