diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-05-12 09:06:11 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-05-12 09:06:11 +0300 |
commit | 4e84a9ff371e69ba828f8678c5cec89eea45d2ab (patch) | |
tree | 332a76e480b197c1bc814ff8dd4d9b46ebe4431e /src/ui/util.c | |
parent | 892d8dedc46713ddf916e82405f06fc2c9c46ae4 (diff) |
InputWidget: Expanding while editing
The navbar layout cannot accommodate more than one line of text, but allow the editor to expand while writing text.
Diffstat (limited to 'src/ui/util.c')
-rw-r--r-- | src/ui/util.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/ui/util.c b/src/ui/util.c index 92cf85b7..f20338b5 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 | ||
386 | iBool 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 | |||
385 | enum iClickResult processEvent_Click(iClick *d, const SDL_Event *event) { | 395 | enum 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 | ||
904 | static 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 | |||
894 | static iBool tabSwitcher_(iWidget *tabs, const char *cmd) { | 912 | static 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) { |
@@ -2205,7 +2225,9 @@ iWidget *makePreferences_Widget(void) { | |||
2205 | addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.downloads}"))); | 2225 | addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.downloads}"))); |
2206 | setId_Widget(addChild_Widget(values, iClob(new_InputWidget(0))), "prefs.downloads"); | 2226 | setId_Widget(addChild_Widget(values, iClob(new_InputWidget(0))), "prefs.downloads"); |
2207 | #endif | 2227 | #endif |
2208 | addPrefsInputWithHeading_(headings, values, "prefs.searchurl", iClob(new_InputWidget(0))); | 2228 | iInputWidget *searchUrl; |
2229 | addPrefsInputWithHeading_(headings, values, "prefs.searchurl", iClob(searchUrl = new_InputWidget(0))); | ||
2230 | setUrlContent_InputWidget(searchUrl, iTrue); | ||
2209 | addChild_Widget(headings, iClob(makePadding_Widget(bigGap))); | 2231 | addChild_Widget(headings, iClob(makePadding_Widget(bigGap))); |
2210 | addChild_Widget(values, iClob(makePadding_Widget(bigGap))); | 2232 | addChild_Widget(values, iClob(makePadding_Widget(bigGap))); |
2211 | addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.collapsepreonload}"))); | 2233 | addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.collapsepreonload}"))); |