summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-12-15 09:28:39 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-12-15 09:29:01 +0200
commit618e415be858313404d1217cbc6c2d14480889a5 (patch)
treef64dd5ce7093d2c362e7063837f79a3535974b6a /src/ui
parent4c9b64718665381f491edbdcb6ffc8bcc5dbda4d (diff)
Window: Show a little animation during downloads
The Stop/Reload button shows a little Unicode animation during downloads. IssueID #101
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/util.c6
-rw-r--r--src/ui/window.c79
-rw-r--r--src/ui/window.h1
3 files changed, 74 insertions, 12 deletions
diff --git a/src/ui/util.c b/src/ui/util.c
index 6c9d75dc..e1db3129 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -370,6 +370,7 @@ static iBool isCommandIgnoredByMenus_(const char *cmd) {
370 return equal_Command(cmd, "media.updated") || equal_Command(cmd, "media.player.update") || 370 return equal_Command(cmd, "media.updated") || equal_Command(cmd, "media.player.update") ||
371 startsWith_CStr(cmd, "feeds.update.") || 371 startsWith_CStr(cmd, "feeds.update.") ||
372 equal_Command(cmd, "document.request.updated") || equal_Command(cmd, "window.resized") || 372 equal_Command(cmd, "document.request.updated") || equal_Command(cmd, "window.resized") ||
373 equal_Command(cmd, "window.reload.update") ||
373 (equal_Command(cmd, "mouse.clicked") && !arg_Command(cmd)); /* button released */ 374 (equal_Command(cmd, "mouse.clicked") && !arg_Command(cmd)); /* button released */
374} 375}
375 376
@@ -748,11 +749,6 @@ iWidget *makeSheet_Widget(const char *id) {
748 749
749void centerSheet_Widget(iWidget *sheet) { 750void centerSheet_Widget(iWidget *sheet) {
750 arrange_Widget(sheet->parent); 751 arrange_Widget(sheet->parent);
751// const iInt2 rootSize = rootSize_Window(get_Window());
752// const iInt2 orig = localCoord_Widget(
753// sheet->parent,
754// init_I2(rootSize.x / 2 - sheet->rect.size.x / 2, bounds_Widget(sheet).pos.y));
755// sheet->rect.pos = orig;
756 postRefresh_App(); 752 postRefresh_App();
757} 753}
758 754
diff --git a/src/ui/window.c b/src/ui/window.c
index 6199c4e2..d2ec6822 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -193,7 +193,38 @@ static const iMenuItem identityButtonMenuItems_[] = {
193}; 193};
194 194
195static const char *reloadCStr_ = "\U0001f503"; 195static const char *reloadCStr_ = "\U0001f503";
196static const char *stopCStr_ = uiTextCaution_ColorEscape "\U0001f310"; 196static const char *stopSeqCStr_[] = {
197 uiTextCaution_ColorEscape "\U0001fb00",
198 uiTextCaution_ColorEscape "\U0001fb01",
199 uiTextCaution_ColorEscape "\U0001fb07",
200 uiTextCaution_ColorEscape "\U0001fb1e",
201 uiTextCaution_ColorEscape "\U0001fb0f",
202 uiTextCaution_ColorEscape "\U0001fb03",
203 uiTextCaution_ColorEscape "\U0001fb00",
204 uiTextCaution_ColorEscape "\U0001fb01",
205 uiTextCaution_ColorEscape "\U0001fb07",
206 uiTextCaution_ColorEscape "\U0001fb1e",
207 uiTextCaution_ColorEscape "\U0001fb0f",
208 uiTextCaution_ColorEscape "\U0001fb03",
209
210 uiTextCaution_ColorEscape "\U0001fb7d",
211 uiTextCaution_ColorEscape "\U0001fb7e",
212 uiTextCaution_ColorEscape "\U0001fb7f",
213 uiTextCaution_ColorEscape "\U0001fb7c",
214 uiTextCaution_ColorEscape "\U0001fb7d",
215 uiTextCaution_ColorEscape "\U0001fb7e",
216 uiTextCaution_ColorEscape "\U0001fb7f",
217 uiTextCaution_ColorEscape "\U0001fb7c",
218
219 uiTextCaution_ColorEscape "\U0001fb00",
220 uiTextCaution_ColorEscape "\U0001fb01",
221 uiTextCaution_ColorEscape "\U0001fb07",
222 uiTextCaution_ColorEscape "\U0001fb03",
223 uiTextCaution_ColorEscape "\U0001fb0f",
224 uiTextCaution_ColorEscape "\U0001fb1e",
225 uiTextCaution_ColorEscape "\U0001fb07",
226 uiTextCaution_ColorEscape "\U0001fb03",
227};
197 228
198static void updateNavBarIdentity_(iWidget *navBar) { 229static void updateNavBarIdentity_(iWidget *navBar) {
199 const iGmIdentity *ident = 230 const iGmIdentity *ident =
@@ -210,6 +241,37 @@ static void updateNavBarIdentity_(iWidget *navBar) {
210 setFlags_Widget(as_Widget(idItem), disabled_WidgetFlag, !ident); 241 setFlags_Widget(as_Widget(idItem), disabled_WidgetFlag, !ident);
211} 242}
212 243
244static const int loadAnimIntervalMs_ = 200;
245static int loadAnimIndex_ = 0;
246
247static const char *loadAnimationCStr_(void) {
248 return stopSeqCStr_[loadAnimIndex_ % iElemCount(stopSeqCStr_)];
249}
250
251static uint32_t updateReloadAnimation_Window_(uint32_t interval, void *window) {
252 iUnused(window);
253 loadAnimIndex_++;
254 postCommand_App("window.reload.update");
255 return interval;
256}
257
258static void setReloadLabel_Window_(iWindow *d, iBool animating) {
259 updateTextCStr_LabelWidget(findChild_Widget(d->root, "reload"),
260 animating ? loadAnimationCStr_() : reloadCStr_);
261}
262
263static void checkLoadAnimation_Window_(iWindow *d) {
264 const iBool isOngoing = isRequestOngoing_DocumentWidget(document_App());
265 if (isOngoing && !d->loadAnimTimer) {
266 d->loadAnimTimer = SDL_AddTimer(loadAnimIntervalMs_, updateReloadAnimation_Window_, d);
267 }
268 else if (!isOngoing && d->loadAnimTimer) {
269 SDL_RemoveTimer(d->loadAnimTimer);
270 d->loadAnimTimer = 0;
271 }
272 setReloadLabel_Window_(d, isOngoing);
273}
274
213static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) { 275static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) {
214 if (equal_Command(cmd, "window.resized")) { 276 if (equal_Command(cmd, "window.resized")) {
215 const iBool isNarrow = width_Rect(bounds_Widget(navBar)) / gap_UI < 140; 277 const iBool isNarrow = width_Rect(bounds_Widget(navBar)) / gap_UI < 140;
@@ -230,6 +292,10 @@ static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) {
230 postCommand_Widget(navBar, "layout.changed id:navbar"); 292 postCommand_Widget(navBar, "layout.changed id:navbar");
231 return iFalse; 293 return iFalse;
232 } 294 }
295 else if (equal_Command(cmd, "window.reload.update")) {
296 checkLoadAnimation_Window_(get_Window());
297 return iTrue;
298 }
233 else if (equal_Command(cmd, "navigate.focus")) { 299 else if (equal_Command(cmd, "navigate.focus")) {
234 iWidget *url = findChild_Widget(navBar, "url"); 300 iWidget *url = findChild_Widget(navBar, "url");
235 if (focus_Widget() != url) { 301 if (focus_Widget() != url) {
@@ -267,25 +333,24 @@ static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) {
267 else if (startsWith_CStr(cmd, "document.")) { 333 else if (startsWith_CStr(cmd, "document.")) {
268 /* React to the current document only. */ 334 /* React to the current document only. */
269 if (document_Command(cmd) == document_App()) { 335 if (document_Command(cmd) == document_App()) {
270 iLabelWidget *reloadButton = findChild_Widget(navBar, "reload");
271 if (equal_Command(cmd, "document.changed")) { 336 if (equal_Command(cmd, "document.changed")) {
272 iInputWidget *url = findWidget_App("url"); 337 iInputWidget *url = findWidget_App("url");
273 const iString *urlStr = collect_String(suffix_Command(cmd, "url")); 338 const iString *urlStr = collect_String(suffix_Command(cmd, "url"));
274 visitUrl_Visited(visited_App(), urlStr, 0); 339 visitUrl_Visited(visited_App(), urlStr, 0);
275 postCommand_App("visited.changed"); /* sidebar will update */ 340 postCommand_App("visited.changed"); /* sidebar will update */
276 setText_InputWidget(url, urlStr); 341 setText_InputWidget(url, urlStr);
277 updateTextCStr_LabelWidget(reloadButton, reloadCStr_); 342 checkLoadAnimation_Window_(get_Window());
278 updateNavBarIdentity_(navBar); 343 updateNavBarIdentity_(navBar);
279 return iFalse; 344 return iFalse;
280 } 345 }
281 else if (equal_Command(cmd, "document.request.cancelled")) { 346 else if (equal_Command(cmd, "document.request.cancelled")) {
282 updateTextCStr_LabelWidget(reloadButton, reloadCStr_); 347 checkLoadAnimation_Window_(get_Window());
283 return iFalse; 348 return iFalse;
284 } 349 }
285 else if (equal_Command(cmd, "document.request.started")) { 350 else if (equal_Command(cmd, "document.request.started")) {
286 iInputWidget *url = findChild_Widget(navBar, "url"); 351 iInputWidget *url = findChild_Widget(navBar, "url");
287 setTextCStr_InputWidget(url, suffixPtr_Command(cmd, "url")); 352 setTextCStr_InputWidget(url, suffixPtr_Command(cmd, "url"));
288 updateTextCStr_LabelWidget(reloadButton, stopCStr_); 353 checkLoadAnimation_Window_(get_Window());
289 return iFalse; 354 return iFalse;
290 } 355 }
291 } 356 }
@@ -295,8 +360,7 @@ static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) {
295 iDocumentWidget *doc = document_App(); 360 iDocumentWidget *doc = document_App();
296 if (doc) { 361 if (doc) {
297 setText_InputWidget(findChild_Widget(navBar, "url"), url_DocumentWidget(doc)); 362 setText_InputWidget(findChild_Widget(navBar, "url"), url_DocumentWidget(doc));
298 updateTextCStr_LabelWidget(findChild_Widget(navBar, "reload"), 363 checkLoadAnimation_Window_(get_Window());
299 isRequestOngoing_DocumentWidget(doc) ? stopCStr_ : reloadCStr_);
300 updateNavBarIdentity_(navBar); 364 updateNavBarIdentity_(navBar);
301 } 365 }
302 setFocus_Widget(NULL); 366 setFocus_Widget(NULL);
@@ -642,6 +706,7 @@ void init_Window(iWindow *d, iRect rect) {
642 d->root = new_Widget(); 706 d->root = new_Widget();
643 d->presentTime = 0.0; 707 d->presentTime = 0.0;
644 d->frameTime = SDL_GetTicks(); 708 d->frameTime = SDL_GetTicks();
709 d->loadAnimTimer = 0;
645 setId_Widget(d->root, "root"); 710 setId_Widget(d->root, "root");
646 init_Text(d->render); 711 init_Text(d->render);
647 setupUserInterface_Window(d); 712 setupUserInterface_Window(d);
diff --git a/src/ui/window.h b/src/ui/window.h
index 2b68d7aa..4b6a6e7a 100644
--- a/src/ui/window.h
+++ b/src/ui/window.h
@@ -47,6 +47,7 @@ struct Impl_Window {
47 double presentTime; 47 double presentTime;
48 SDL_Cursor * cursors[SDL_NUM_SYSTEM_CURSORS]; 48 SDL_Cursor * cursors[SDL_NUM_SYSTEM_CURSORS];
49 SDL_Cursor * pendingCursor; 49 SDL_Cursor * pendingCursor;
50 int loadAnimTimer;
50}; 51};
51 52
52iBool processEvent_Window (iWindow *, const SDL_Event *); 53iBool processEvent_Window (iWindow *, const SDL_Event *);