7#include <imgui/imgui.h>
13auto filename_char_filter(ImGuiInputTextCallbackData* data) ->
int
15 auto c = data->EventChar;
16 if(c ==
'<' || c ==
'>' || c ==
':' || c ==
'"' || c ==
'/' || c ==
'\\' || c ==
'|' || c ==
'?' || c ==
'*')
28auto layout_panel::get_window_flags() const -> ImGuiWindowFlags
39 if(ImGui::Button(
ICON_MDI_PLUS " Create Layout", ImVec2(-1, 0)))
41 open_create_popup_ =
true;
42 create_name_buf_.fill(
'\0');
47 lm.reset_to_default();
58 fs::show_in_graphical_env(lm.get_layouts_directory());
64void layout_panel::draw_create_popup()
66 if(open_create_popup_)
68 ImGui::OpenPopup(
"Create Layout");
69 open_create_popup_ =
false;
72 auto* viewport = ImGui::GetMainViewport();
73 ImGui::SetNextWindowPos(ImVec2(viewport->GetCenter().x, viewport->GetCenter().y),
76 ImGui::SetNextWindowSize(ImVec2(400, 0), ImGuiCond_Appearing);
78 if(!ImGui::BeginPopupModal(
"Create Layout",
nullptr, ImGuiWindowFlags_AlwaysAutoResize))
85 ImGui::TextWrapped(
"Enter the name of the layout you want to create");
88 ImGui::AlignTextToFramePadding();
89 ImGui::Text(
"Layout Name");
91 ImGui::SetNextItemWidth(-1);
93 bool enter_pressed = ImGui::InputText(
"##create_name",
94 create_name_buf_.data(),
95 create_name_buf_.size(),
96 ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackCharFilter,
97 filename_char_filter);
99 bool name_empty = (create_name_buf_[0] ==
'\0');
100 bool already_exists = !name_empty && lm.has_preset(create_name_buf_.data());
104 ImGui::TextColored(ImVec4(1.0f, 0.7f, 0.0f, 1.0f),
ICON_MDI_ALERT " A preset with this name already exists and will be overwritten.");
109 float button_width = 120.0f;
110 float total_width = button_width * 2 + ImGui::GetStyle().ItemSpacing.x;
111 ImGui::SetCursorPosX(ImGui::GetContentRegionAvail().
x - total_width + ImGui::GetCursorPosX());
113 if(ImGui::Button(
"Create", ImVec2(button_width, 0)) || (enter_pressed && !name_empty))
117 lm.save_preset(create_name_buf_.data());
118 ImGui::CloseCurrentPopup();
124 if(ImGui::Button(
"Cancel", ImVec2(button_width, 0)))
126 ImGui::CloseCurrentPopup();
132void layout_panel::draw_presets_list()
135 auto presets = lm.get_preset_names();
137 ImGui::Text(
"Saved Layouts:");
141 ImGui::TextDisabled(
"No saved layouts yet.");
145 for(
const auto&
name : presets)
147 ImGui::PushID(
name.c_str());
149 float icon_btn_width = ImGui::CalcTextSize(
ICON_MDI_DELETE).x + ImGui::GetStyle().FramePadding.x * 2;
150 float apply_width = ImGui::GetContentRegionAvail().x - icon_btn_width * 2 - ImGui::GetStyle().ItemSpacing.x * 2;
152 if(ImGui::Button(
name.c_str(), ImVec2(apply_width, 0)))
154 lm.load_preset(
name);
156 ImGui::SetItemTooltipEx(
"Click to apply \"%s\"",
name.c_str());
162 lm.save_preset(
name);
164 ImGui::SetItemTooltipEx(
"Update \"%s\" with current layout",
name.c_str());
168 ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.6f, 0.15f, 0.15f, 0.65f));
169 ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 0.8f));
170 ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.9f, 0.1f, 0.1f, 1.0f));
173 auto preset_name =
name;
174 auto* panels = parent_;
177 fmt::format(
"Delete layout preset \"{}\"?\n\nThis cannot be undone.", preset_name),
182 panels->get_layout_manager().delete_preset(preset_name);
186 ImGui::PopStyleColor(3);
187 ImGui::SetItemTooltipEx(
"Delete \"%s\"",
name.c_str());
auto get_layout_manager() -> layout_manager &
layout_panel(imgui_panels *parent, const char *name)
void draw_ui(rtti::context &ctx) override
#define ICON_MDI_FOLDER_OPEN
std::vector< size_t > parent_
ModalResult
Modal result flags for message box buttons.
auto ShowDeleteConfirmation(const std::string &title, const std::string &message, std::function< void(ModalResult)> callback) -> std::shared_ptr< MsgBox >
Show a delete confirmation dialog with Delete/Cancel buttons.