1 /*
2     Copyright © 2020, Inochi2D Project
3     Distributed under the 2-Clause BSD License, see LICENSE file.
4     
5     Authors: Luna Nielsen
6 */
7 module creator.widgets.statusbar;
8 import bindbc.sdl;
9 import bindbc.imgui;
10 import creator.core;
11 import creator.widgets;
12 import creator.utils.link;
13 import app : incUpdateNoEv;
14 import std.string;
15 
16 private {
17     size_t itemIdx;
18     ToolTipItem[] items;
19 
20     struct ToolTipItem {
21         string action;
22         string key;
23     }
24 }
25 
26 void incStatusTooltip(string action, string key) {
27     if (itemIdx >= items.length) items.length = itemIdx+1;
28     items[itemIdx++] = ToolTipItem(action, key);
29 }
30 
31 /**
32     Draws the custom titlebar
33 */
34 void incStatusbar() {
35     auto flags = 
36         ImGuiWindowFlags.NoSavedSettings |
37         ImGuiWindowFlags.NoScrollbar |
38         ImGuiWindowFlags.MenuBar;
39     
40     if (incGetDarkMode()) igPushStyleColor(ImGuiCol.MenuBarBg, ImVec4(0.1, 0.1, 0.1, 1));
41     else igPushStyleColor(ImGuiCol.MenuBarBg, ImVec4(0.9, 0.9, 0.9, 1));
42     if (igBeginViewportSideBar("##Statusbar", igGetMainViewport(), ImGuiDir.Down, 22, flags)) {
43         if (igBeginMenuBar()) {
44             
45             igPushStyleColor(ImGuiCol.Separator, ImVec4(1.000f, 1.000f, 1.000f, 0.098f));
46                 foreach(i, item; items) {
47 
48                     // We've reached the end
49                     if (i == itemIdx) break;
50                     
51                     float startX = igGetCursorPosX();
52 
53                     // Render the tooltip
54                     ImVec2 size = incMeasureString(item.action);
55                     incText(item.action);
56                     igSameLine(startX+(size.x-8), 0);
57                     incText(":");
58                     igSameLine(0, 4);
59                     incText(item.key);
60 
61                     igSeparator(); 
62                 }
63             igPopStyleColor();
64 
65             if (incTaskLength() > 0) {
66                 if (incTaskGetProgress() >= 0) {
67                     igProgressBar(incTaskGetProgress(), ImVec2(128, 0));
68                 }
69 
70                 incText(incTaskGetStatus());
71 
72                 if (incGetStatus().length > 0) {
73                     igSpacing();
74                     igSeparator();
75                     igSpacing();
76                 }
77             }
78             
79             incText(incGetStatus());
80 
81             igEndMenuBar();
82         }
83         incEnd();
84     }
85     igPopStyleColor();
86 
87     itemIdx = 0;
88 }