1
1
#include " xpano/gui/panels/warning_pane.h"
2
2
3
3
#include < imgui.h>
4
+ #include < spdlog/fmt/fmt.h>
4
5
#include < spdlog/spdlog.h>
5
6
6
7
#include " xpano/constants.h"
7
- #include " xpano/gui/action.h"
8
+ #include " xpano/utils/imgui_.h"
9
+ #include " xpano/version_fmt.h"
8
10
9
11
namespace xpano ::gui {
10
12
@@ -15,18 +17,17 @@ const char* WarningMessage(WarningType warning) {
15
17
return " Only 8-bit stitching pipeline is implemented!\n Higher bit depth "
16
18
" images are converted to 8-bit." ;
17
19
case WarningType::kFirstTimeLaunch :
18
- return " Your friendly panorama stitching app:\n "
19
- " - default settings are designed to work out of the box with "
20
- " most images\n "
21
- " - hover over the little question marks for detailed "
22
- " instructions" ;
20
+ return " Your friendly panorama stitching app" ;
23
21
case WarningType::kUserPrefBreakingChange :
24
- return " The user settings format has changed, reverting to defaults." ;
22
+ return " The user settings format has "
23
+ " changed, reverting to defaults." ;
25
24
case WarningType::kUserPrefCouldntLoad :
26
25
return " Couldn't load user settings, reverting to defaults." ;
27
26
case WarningType::kUserPrefResetOnRequest :
28
27
return " User settings were reset to default values,\n you can keep "
29
28
" experimenting!" ;
29
+ case WarningType::kNewVersion :
30
+ return " Xpano was updated!" ;
30
31
default :
31
32
return " " ;
32
33
}
@@ -36,6 +37,8 @@ const char* Title(WarningType warning) {
36
37
switch (warning) {
37
38
case WarningType::kFirstTimeLaunch :
38
39
return " Welcome to Xpano!" ;
40
+ case WarningType::kNewVersion :
41
+ return " Version update" ;
39
42
case WarningType::kUserPrefResetOnRequest :
40
43
return " Info" ;
41
44
default :
@@ -51,10 +54,14 @@ bool EnableSnooze(WarningType warning) {
51
54
return false ;
52
55
}
53
56
}
57
+
54
58
} // namespace
55
59
56
60
void WarningPane::Draw () {
57
- if (current_warning_ == WarningType::kNone && !pending_warnings_.empty ()) {
61
+ if (current_warning_ == WarningType::kNone ) {
62
+ if (pending_warnings_.empty ()) {
63
+ return ;
64
+ }
58
65
Show (pending_warnings_.front ());
59
66
pending_warnings_.pop ();
60
67
}
@@ -65,12 +72,12 @@ void WarningPane::Draw() {
65
72
if (ImGui::BeginPopupModal (Title (current_warning_), nullptr ,
66
73
ImGuiWindowFlags_AlwaysAutoResize)) {
67
74
ImGui::TextUnformatted (WarningMessage (current_warning_));
75
+ DrawExtra (current_warning_);
68
76
ImGui::Spacing ();
69
77
ImGui::Separator ();
70
78
ImGui::Spacing ();
71
79
72
- const auto text_base_width = ImGui::CalcTextSize (" A" ).x ;
73
- if (ImGui::Button (" OK" , ImVec2 (text_base_width * kWideButtonWidth , 0 ))) {
80
+ if (ImGui::Button (" OK" , utils::imgui::DpiAwareSize (kWideButtonWidth , 0 ))) {
74
81
ImGui::CloseCurrentPopup ();
75
82
current_warning_ = WarningType::kNone ;
76
83
}
@@ -89,10 +96,48 @@ void WarningPane::Draw() {
89
96
}
90
97
}
91
98
99
+ void WarningPane::DrawExtra (WarningType warning) {
100
+ switch (warning) {
101
+ case WarningType::kFirstTimeLaunch : {
102
+ ImGui::Text (
103
+ " - default settings are designed to work out of the box with most "
104
+ " images" );
105
+ ImGui::Text (
106
+ " - hover over the little question marks for detailed instructions:" );
107
+ ImGui::SameLine ();
108
+ utils::imgui::InfoMarker (
109
+ " (?)" , " You can try importing a whole directory at once" );
110
+ break ;
111
+ }
112
+ case WarningType::kNewVersion : {
113
+ ImGui::TextUnformatted (new_version_message_.c_str ());
114
+ if (changelog_) {
115
+ ImGui::Spacing ();
116
+ ImGui::Separator ();
117
+ ImGui::Spacing ();
118
+ utils::imgui::DrawScrollableText (
119
+ " Changelog" , changelog_->lines ,
120
+ utils::imgui::DpiAwareSize (kAboutBoxWidth , kAboutBoxHeight / 2 ));
121
+ }
122
+ break ;
123
+ }
124
+ default :
125
+ break ;
126
+ }
127
+ }
128
+
92
129
void WarningPane::Queue (WarningType warning) {
93
130
pending_warnings_.push (warning);
94
131
}
95
132
133
+ void WarningPane::QueueNewVersion (version::Triplet previous_version,
134
+ std::optional<utils::Text> changelog) {
135
+ pending_warnings_.push (WarningType::kNewVersion );
136
+ new_version_message_ = fmt::format (" - from version {} to version {}" ,
137
+ previous_version, version::Current ());
138
+ changelog_ = std::move (changelog);
139
+ }
140
+
96
141
void WarningPane::Show (WarningType warning) {
97
142
if (!dont_show_again_.contains (warning)) {
98
143
ImGui::OpenPopup (Title (warning));
0 commit comments