From 4e84a9ff371e69ba828f8678c5cec89eea45d2ab Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Wed, 12 May 2021 09:06:11 +0300 Subject: InputWidget: Expanding while editing The navbar layout cannot accommodate more than one line of text, but allow the editor to expand while writing text. --- src/ui/util.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src/ui/util.c') 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) { d->isActive = iFalse; d->button = button; d->bounds = as_Widget(widget); + d->minHeight = 0; d->startPos = zero_I2(); d->pos = zero_I2(); } +iBool contains_Click(const iClick *d, iInt2 coord) { + if (d->minHeight) { + iRect rect = bounds_Widget(d->bounds); + rect.size.y = iMax(d->minHeight, rect.size.y); + return contains_Rect(rect, coord); + } + return contains_Widget(d->bounds, coord); +} + enum iClickResult processEvent_Click(iClick *d, const SDL_Event *event) { if (event->type == SDL_MOUSEMOTION) { 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) { } if (!d->isActive) { if (mb->state == SDL_PRESSED) { - if (contains_Widget(d->bounds, pos)) { + if (contains_Click(d, pos)) { d->isActive = iTrue; d->startPos = d->pos = pos; setMouseGrab_Widget(d->bounds); @@ -413,7 +423,7 @@ enum iClickResult processEvent_Click(iClick *d, const SDL_Event *event) { } else { /* Active. */ if (mb->state == SDL_RELEASED) { - enum iClickResult result = contains_Widget(d->bounds, pos) + enum iClickResult result = contains_Click(d, pos) ? finished_ClickResult : aborted_ClickResult; d->isActive = iFalse; @@ -891,6 +901,14 @@ static iBool isTabPage_Widget_(const iWidget *tabs, const iWidget *page) { return page && page->parent == findChild_Widget(tabs, "tabs.pages"); } +static void unfocusFocusInsideTabPage_(const iWidget *page) { + iWidget *focus = focus_Widget(); + if (page && focus && hasParent_Widget(focus, page)) { + printf("unfocus inside page: %p\n", focus); + setFocus_Widget(NULL); + } +} + static iBool tabSwitcher_(iWidget *tabs, const char *cmd) { if (equal_Command(cmd, "tabs.switch")) { iWidget *target = pointerLabel_Command(cmd, "page"); @@ -898,6 +916,7 @@ static iBool tabSwitcher_(iWidget *tabs, const char *cmd) { target = findChild_Widget(tabs, cstr_Rangecc(range_Command(cmd, "id"))); } if (!target) return iFalse; + unfocusFocusInsideTabPage_(currentTabPage_Widget(tabs)); if (flags_Widget(target) & focusable_WidgetFlag) { setFocus_Widget(target); } @@ -915,6 +934,7 @@ static iBool tabSwitcher_(iWidget *tabs, const char *cmd) { } } else if (equal_Command(cmd, "tabs.next") || equal_Command(cmd, "tabs.prev")) { + unfocusFocusInsideTabPage_(currentTabPage_Widget(tabs)); iWidget *pages = findChild_Widget(tabs, "tabs.pages"); int tabIndex = 0; iConstForEach(ObjectList, i, pages->children) { @@ -2205,7 +2225,9 @@ iWidget *makePreferences_Widget(void) { addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.downloads}"))); setId_Widget(addChild_Widget(values, iClob(new_InputWidget(0))), "prefs.downloads"); #endif - addPrefsInputWithHeading_(headings, values, "prefs.searchurl", iClob(new_InputWidget(0))); + iInputWidget *searchUrl; + addPrefsInputWithHeading_(headings, values, "prefs.searchurl", iClob(searchUrl = new_InputWidget(0))); + setUrlContent_InputWidget(searchUrl, iTrue); addChild_Widget(headings, iClob(makePadding_Widget(bigGap))); addChild_Widget(values, iClob(makePadding_Widget(bigGap))); addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.collapsepreonload}"))); -- cgit v1.2.3