summaryrefslogtreecommitdiff
path: root/src/ui/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/util.c')
-rw-r--r--src/ui/util.c40
1 files changed, 35 insertions, 5 deletions
diff --git a/src/ui/util.c b/src/ui/util.c
index 92cf85b7..04cdf27f 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -378,10 +378,20 @@ void init_Click(iClick *d, iAnyObject *widget, int button) {
378 d->isActive = iFalse; 378 d->isActive = iFalse;
379 d->button = button; 379 d->button = button;
380 d->bounds = as_Widget(widget); 380 d->bounds = as_Widget(widget);
381 d->minHeight = 0;
381 d->startPos = zero_I2(); 382 d->startPos = zero_I2();
382 d->pos = zero_I2(); 383 d->pos = zero_I2();
383} 384}
384 385
386iBool contains_Click(const iClick *d, iInt2 coord) {
387 if (d->minHeight) {
388 iRect rect = bounds_Widget(d->bounds);
389 rect.size.y = iMax(d->minHeight, rect.size.y);
390 return contains_Rect(rect, coord);
391 }
392 return contains_Widget(d->bounds, coord);
393}
394
385enum iClickResult processEvent_Click(iClick *d, const SDL_Event *event) { 395enum iClickResult processEvent_Click(iClick *d, const SDL_Event *event) {
386 if (event->type == SDL_MOUSEMOTION) { 396 if (event->type == SDL_MOUSEMOTION) {
387 const iInt2 pos = init_I2(event->motion.x, event->motion.y); 397 const iInt2 pos = init_I2(event->motion.x, event->motion.y);
@@ -403,7 +413,7 @@ enum iClickResult processEvent_Click(iClick *d, const SDL_Event *event) {
403 } 413 }
404 if (!d->isActive) { 414 if (!d->isActive) {
405 if (mb->state == SDL_PRESSED) { 415 if (mb->state == SDL_PRESSED) {
406 if (contains_Widget(d->bounds, pos)) { 416 if (contains_Click(d, pos)) {
407 d->isActive = iTrue; 417 d->isActive = iTrue;
408 d->startPos = d->pos = pos; 418 d->startPos = d->pos = pos;
409 setMouseGrab_Widget(d->bounds); 419 setMouseGrab_Widget(d->bounds);
@@ -413,7 +423,7 @@ enum iClickResult processEvent_Click(iClick *d, const SDL_Event *event) {
413 } 423 }
414 else { /* Active. */ 424 else { /* Active. */
415 if (mb->state == SDL_RELEASED) { 425 if (mb->state == SDL_RELEASED) {
416 enum iClickResult result = contains_Widget(d->bounds, pos) 426 enum iClickResult result = contains_Click(d, pos)
417 ? finished_ClickResult 427 ? finished_ClickResult
418 : aborted_ClickResult; 428 : aborted_ClickResult;
419 d->isActive = iFalse; 429 d->isActive = iFalse;
@@ -891,6 +901,14 @@ static iBool isTabPage_Widget_(const iWidget *tabs, const iWidget *page) {
891 return page && page->parent == findChild_Widget(tabs, "tabs.pages"); 901 return page && page->parent == findChild_Widget(tabs, "tabs.pages");
892} 902}
893 903
904static void unfocusFocusInsideTabPage_(const iWidget *page) {
905 iWidget *focus = focus_Widget();
906 if (page && focus && hasParent_Widget(focus, page)) {
907 printf("unfocus inside page: %p\n", focus);
908 setFocus_Widget(NULL);
909 }
910}
911
894static iBool tabSwitcher_(iWidget *tabs, const char *cmd) { 912static iBool tabSwitcher_(iWidget *tabs, const char *cmd) {
895 if (equal_Command(cmd, "tabs.switch")) { 913 if (equal_Command(cmd, "tabs.switch")) {
896 iWidget *target = pointerLabel_Command(cmd, "page"); 914 iWidget *target = pointerLabel_Command(cmd, "page");
@@ -898,6 +916,7 @@ static iBool tabSwitcher_(iWidget *tabs, const char *cmd) {
898 target = findChild_Widget(tabs, cstr_Rangecc(range_Command(cmd, "id"))); 916 target = findChild_Widget(tabs, cstr_Rangecc(range_Command(cmd, "id")));
899 } 917 }
900 if (!target) return iFalse; 918 if (!target) return iFalse;
919 unfocusFocusInsideTabPage_(currentTabPage_Widget(tabs));
901 if (flags_Widget(target) & focusable_WidgetFlag) { 920 if (flags_Widget(target) & focusable_WidgetFlag) {
902 setFocus_Widget(target); 921 setFocus_Widget(target);
903 } 922 }
@@ -915,6 +934,7 @@ static iBool tabSwitcher_(iWidget *tabs, const char *cmd) {
915 } 934 }
916 } 935 }
917 else if (equal_Command(cmd, "tabs.next") || equal_Command(cmd, "tabs.prev")) { 936 else if (equal_Command(cmd, "tabs.next") || equal_Command(cmd, "tabs.prev")) {
937 unfocusFocusInsideTabPage_(currentTabPage_Widget(tabs));
918 iWidget *pages = findChild_Widget(tabs, "tabs.pages"); 938 iWidget *pages = findChild_Widget(tabs, "tabs.pages");
919 int tabIndex = 0; 939 int tabIndex = 0;
920 iConstForEach(ObjectList, i, pages->children) { 940 iConstForEach(ObjectList, i, pages->children) {
@@ -1881,6 +1901,9 @@ iWidget *makeDialogButtons_Widget(const iMenuItem *actions, size_t numActions) {
1881 } 1901 }
1882 iLabelWidget *button = 1902 iLabelWidget *button =
1883 addChild_Widget(div, iClob(newKeyMods_LabelWidget(label, key, kmods, cmd))); 1903 addChild_Widget(div, iClob(newKeyMods_LabelWidget(label, key, kmods, cmd)));
1904 if (isDefault) {
1905 setId_Widget(as_Widget(button), "default");
1906 }
1884 setFlags_Widget(as_Widget(button), alignLeft_WidgetFlag | drawKey_WidgetFlag, isDefault); 1907 setFlags_Widget(as_Widget(button), alignLeft_WidgetFlag | drawKey_WidgetFlag, isDefault);
1885 setFont_LabelWidget(button, isDefault ? fonts[1] : fonts[0]); 1908 setFont_LabelWidget(button, isDefault ? fonts[1] : fonts[0]);
1886 } 1909 }
@@ -2175,6 +2198,10 @@ static void addDialogInputWithHeading_(iWidget *headings, iWidget *values, const
2175 setPadding_Widget(as_Widget(head), 0, gap_UI, 0, 0); 2198 setPadding_Widget(as_Widget(head), 0, gap_UI, 0, 0);
2176#endif 2199#endif
2177 setId_Widget(addChild_Widget(values, input), inputId); 2200 setId_Widget(addChild_Widget(values, input), inputId);
2201 if (deviceType_App() != phone_AppDeviceType) {
2202 /* Ensure that the label has the same height as the input widget. */
2203 as_Widget(head)->sizeRef = as_Widget(input);
2204 }
2178} 2205}
2179 2206
2180iInputWidget *addTwoColumnDialogInputField_Widget(iWidget *headings, iWidget *values, 2207iInputWidget *addTwoColumnDialogInputField_Widget(iWidget *headings, iWidget *values,
@@ -2202,10 +2229,13 @@ iWidget *makePreferences_Widget(void) {
2202 /* General preferences. */ { 2229 /* General preferences. */ {
2203 appendTwoColumnPage_(tabs, "${heading.prefs.general}", '1', &headings, &values); 2230 appendTwoColumnPage_(tabs, "${heading.prefs.general}", '1', &headings, &values);
2204#if defined (LAGRANGE_ENABLE_DOWNLOAD_EDIT) 2231#if defined (LAGRANGE_ENABLE_DOWNLOAD_EDIT)
2205 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.downloads}"))); 2232 //addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.downloads}")));
2206 setId_Widget(addChild_Widget(values, iClob(new_InputWidget(0))), "prefs.downloads"); 2233 //setId_Widget(addChild_Widget(values, iClob(new_InputWidget(0))), "prefs.downloads");
2234 addPrefsInputWithHeading_(headings, values, "prefs.downloads", iClob(new_InputWidget(0)));
2207#endif 2235#endif
2208 addPrefsInputWithHeading_(headings, values, "prefs.searchurl", iClob(new_InputWidget(0))); 2236 iInputWidget *searchUrl;
2237 addPrefsInputWithHeading_(headings, values, "prefs.searchurl", iClob(searchUrl = new_InputWidget(0)));
2238 setUrlContent_InputWidget(searchUrl, iTrue);
2209 addChild_Widget(headings, iClob(makePadding_Widget(bigGap))); 2239 addChild_Widget(headings, iClob(makePadding_Widget(bigGap)));
2210 addChild_Widget(values, iClob(makePadding_Widget(bigGap))); 2240 addChild_Widget(values, iClob(makePadding_Widget(bigGap)));
2211 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.collapsepreonload}"))); 2241 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.collapsepreonload}")));