summaryrefslogtreecommitdiff
path: root/src/ui/window.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-07-23 19:30:17 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-07-23 19:30:17 +0300
commitdd73346aad190239ed133d0c4835dbaa05d1b0cd (patch)
tree5946174857fce2b5fcf14d0a662e4ce26745e6ca /src/ui/window.c
parent4b81b3bc704ec8a7041559b4f9a141e96189a7c7 (diff)
Entering URLs and updating the navbar
Diffstat (limited to 'src/ui/window.c')
-rw-r--r--src/ui/window.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/src/ui/window.c b/src/ui/window.c
index 241cd3b0..43233010 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -49,6 +49,10 @@ static iBool handleRootCommands_(iWidget *root, const char *cmd) {
49 } 49 }
50 return iTrue; 50 return iTrue;
51 } 51 }
52 else if (equal_Command(cmd, "setfocus")) {
53 setFocus_Widget(findWidget_App(cstr_String(string_Command(cmd, "id"))));
54 return iTrue;
55 }
52 else if (handleCommand_App(cmd)) { 56 else if (handleCommand_App(cmd)) {
53 return iTrue; 57 return iTrue;
54 } 58 }
@@ -70,6 +74,23 @@ static const iMenuItem editMenuItems[] = {
70static const iMenuItem viewMenuItems[] = { 74static const iMenuItem viewMenuItems[] = {
71}; 75};
72 76
77static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) {
78 if (equal_Command(cmd, "input.ended")) {
79 iInputWidget *url = findChild_Widget(navBar, "url");
80 if (arg_Command(cmd) && pointer_Command(cmd) == url) {
81 postCommandf_App("open url:%s", cstr_String(text_InputWidget(url)));
82 return iTrue;
83 }
84 }
85 else if (equal_Command(cmd, "document.changed")) {
86 iInputWidget *url = findWidget_App("url");
87 setTextCStr_InputWidget(url, valuePtr_Command(cmd, "url"));
88 setTitle_Window(get_Window(), text_InputWidget(url));
89 return iTrue;
90 }
91 return iFalse;
92}
93
73static void setupUserInterface_Window(iWindow *d) { 94static void setupUserInterface_Window(iWindow *d) {
74 /* Children of root cover the entire window. */ 95 /* Children of root cover the entire window. */
75 setFlags_Widget(d->root, resizeChildren_WidgetFlag, iTrue); 96 setFlags_Widget(d->root, resizeChildren_WidgetFlag, iTrue);
@@ -87,12 +108,14 @@ static void setupUserInterface_Window(iWindow *d) {
87 arrangeHorizontal_WidgetFlag, 108 arrangeHorizontal_WidgetFlag,
88 iTrue); 109 iTrue);
89 addChild_Widget(div, iClob(navBar)); 110 addChild_Widget(div, iClob(navBar));
90 setBackgroundColor_Widget(div, gray25_ColorId); 111 setCommandHandler_Widget(navBar, handleNavBarCommands_);
112 setBackgroundColor_Widget(navBar, gray25_ColorId);
91 113
92 addChild_Widget(navBar, iClob(new_LabelWidget("Back", 0, 0, "navigate.back"))); 114 addChild_Widget(navBar, iClob(new_LabelWidget("Back", 0, 0, "navigate.back")));
93 addChild_Widget(navBar, iClob(new_LabelWidget("Fwd", 0, 0, "navigate.forward"))); 115 addChild_Widget(navBar, iClob(new_LabelWidget("Fwd", 0, 0, "navigate.forward")));
94 addChild_Widget(navBar, iClob(new_LabelWidget("Home", 0, 0, "navigate.home"))); 116 addChild_Widget(navBar, iClob(new_LabelWidget("Home", 0, 0, "navigate.home")));
95 iInputWidget *url = new_InputWidget(0); 117 iInputWidget *url = new_InputWidget(0);
118 setId_Widget(as_Widget(url), "url");
96 setTextCStr_InputWidget(url, "gemini://"); 119 setTextCStr_InputWidget(url, "gemini://");
97 addChildFlags_Widget(navBar, iClob(url), expand_WidgetFlag); 120 addChildFlags_Widget(navBar, iClob(url), expand_WidgetFlag);
98 } 121 }
@@ -250,6 +273,7 @@ static void setupUserInterface_Window(iWindow *d) {
250#endif 273#endif
251 /* Glboal keyboard shortcuts. */ { 274 /* Glboal keyboard shortcuts. */ {
252 // addAction_Widget(d->root, SDLK_LEFTBRACKET, KMOD_SHIFT | KMOD_PRIMARY, "tabs.prev"); 275 // addAction_Widget(d->root, SDLK_LEFTBRACKET, KMOD_SHIFT | KMOD_PRIMARY, "tabs.prev");
276 addAction_Widget(d->root, 'l', KMOD_PRIMARY, "setfocus id:url");
253 } 277 }
254} 278}
255 279
@@ -381,8 +405,13 @@ iBool processEvent_Window(iWindow *d, const SDL_Event *ev) {
381 widget = mouseGrab_Widget(); 405 widget = mouseGrab_Widget();
382 } 406 }
383 } 407 }
384 /* TODO: Auto-refresh when hover widget changes. */ 408 iWidget *oldHover = hover_Widget();
385 return dispatchEvent_Widget(widget, &event); 409 /* Dispatch the event to the tree of widgets. */
410 iBool wasUsed = dispatchEvent_Widget(widget, &event);
411 if (oldHover != hover_Widget()) {
412 postRefresh_App();
413 }
414 return wasUsed;
386 } 415 }
387 } 416 }
388 return iFalse; 417 return iFalse;
@@ -432,6 +461,10 @@ void resize_Window(iWindow *d, int w, int h) {
432 updateRootSize_Window_(d); 461 updateRootSize_Window_(d);
433} 462}
434 463
464void setTitle_Window(iWindow *d, const iString *title) {
465 SDL_SetWindowTitle(d->win, cstr_String(title));
466}
467
435void setUiScale_Window(iWindow *d, float uiScale) { 468void setUiScale_Window(iWindow *d, float uiScale) {
436 uiScale = iClamp(uiScale, 0.5f, 4.0f); 469 uiScale = iClamp(uiScale, 0.5f, 4.0f);
437 if (d) { 470 if (d) {