@@ -28,13 +28,16 @@ void FractalExplorer::display(const Window& window, vec2 mousePos) {
2828 for (auto it = panels.begin (); it != panels.end (); ++it) {
2929 it->imguiBegin (window);
3030
31- bool remove = ImGui::Button (" Remove Fractal View" );
31+ ImGui::PushStyleColor (ImGuiCol_Button, ImVec4 (0 .4f , 0 .2f , 0 .2f , 1 .0f ));
32+ ImGui::PushStyleColor (ImGuiCol_ButtonHovered, ImVec4 (0 .7f , 0 .3f , 0 .3f , 1 .0f ));
33+ ImGui::PushStyleColor (ImGuiCol_ButtonActive, ImVec4 (1 .0f , 0 .4f , 0 .4f , 1 .0f ));
34+ bool remove = ImGui::Button (" Remove Fractal" );
35+ ImGui::PopStyleColor (3 );
3236
3337 it->imguiBody (window);
3438 it->imguiEnd ();
3539
3640 if (remove) {
37- cachedFractals.push_back (it->extract ());
3841 panels.erase (it);
3942 reorganize (window);
4043 goto reset_display;
@@ -44,12 +47,14 @@ void FractalExplorer::display(const Window& window, vec2 mousePos) {
4447 }
4548
4649 // First get what we need from the compiler GUI.
47- auto id = compilerGUI.display (window);
48- if (id >= 0 && id < fractal::totalFractalNum) {
49- instantiateNewFractalPanel (id);
50+ auto result = compilerGUI.display (window, panels.size ());
51+ if (result == FractalCompilerGUI::NEW_FRACTAL_PANEL) {
52+ instantiateFractalPanel (compilerGUI.currentFractalSelection , true );
53+ reorganize (window);
54+ } else if (result == FractalCompilerGUI::INPLACE_FRACTAL) {
55+ instantiateFractalPanel (compilerGUI.currentFractalSelection , false );
5056 reorganize (window);
5157 }
52-
5358}
5459
5560void FractalExplorer::reorganize (const Window& window) {
@@ -85,47 +90,32 @@ void FractalExplorer::onMouseWheel(const Window& window, const Mouse& mouse) {
8590 cursor.onMouseWheel (window, mouse, panels);
8691}
8792
88- void FractalExplorer::instantiateNewFractalPanel (fractal_id id) {
89- auto targetPanel = panels.size ();
90-
91- if (targetPanel >= fractal::maxFractalViews) {
92- // If we already have the max number of views on the screen, steal the
93- // existing fractal from the current view
94- targetPanel = fractal::maxFractalViews - 1 ;
95- if (auto ptr = panels[targetPanel].extract ()) {
96- cachedFractals.push_back (std::move (ptr));
93+ void FractalExplorer::instantiateFractalPanel (const fractal_id id, bool newPanel) {
94+ size_t targetPanel = panels.size ();
95+ if (newPanel || panels.empty ()) {
96+ if (targetPanel >= fractal::maxFractalViews) {
97+ targetPanel = fractal::maxFractalViews - 1 ;
98+ } else {
99+ panels.emplace_back ();
97100 }
98- } else {
99- // Otherwise just create a new fractalViewer
101+ } else if (panels.empty ()) {
100102 panels.emplace_back ();
103+ } else {
104+ targetPanel--;
101105 }
102106
103- auto it = locateCachedFractal (id);
104- if (it != cachedFractals.end ()) {
105- panels[targetPanel].embed (std::move (*it));
106- cachedFractals.erase (it);
107+ try {
108+ auto unique = Fractal::make_unique (
109+ fractal::fractalInfo[id]
110+ );
111+ panels[targetPanel].embed (std::move (unique));
107112 compilerGUI.clearCompileError ();
108- } else {
109- try {
110- auto unique = Fractal::make_unique (
111- fractal::fractalInfo[id]
112- );
113- panels[targetPanel].embed (std::move (unique));
114- compilerGUI.clearCompileError ();
115- } catch (...) {
116- compilerGUI.reportCompileError ();
117- panels.pop_back ();
118- }
113+ } catch (...) {
114+ compilerGUI.reportCompileError ();
115+ panels.pop_back ();
119116 }
120117
121118 if (!panels.empty ()) {
122119 std::println (" {}" , panels.back ().checkHealth ());
123120 }
124- }
125-
126- std::vector<std::unique_ptr<Fractal>>::iterator FractalExplorer::locateCachedFractal (fractal_id id) {
127- auto targetName = fractal::fractalInfo[id].name ;
128- auto it = std::ranges::find_if (cachedFractals,
129- [&](const auto & f) { return f->name == targetName; });
130- return it;
131121}
0 commit comments