diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-07-27 10:39:58 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-07-27 10:39:58 +0300 |
commit | 8070b171badbfaf15b56bcce664098f06f81b4e2 (patch) | |
tree | 9992d96ff8d7d93a996567a0abae4263d03d9bad /src/ui | |
parent | 91917d78832e044efaf6480d63ae4f72a8385d2e (diff) |
Showing and hiding the search bar
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/documentwidget.c | 2 | ||||
-rw-r--r-- | src/ui/inputwidget.c | 4 | ||||
-rw-r--r-- | src/ui/window.c | 29 |
3 files changed, 28 insertions, 7 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index f0170924..d0fa60ab 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -430,7 +430,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
430 | d->foundMark = finder( | 430 | d->foundMark = finder( |
431 | d->doc, text_InputWidget(find), dir > 0 ? d->foundMark.end : d->foundMark.start); | 431 | d->doc, text_InputWidget(find), dir > 0 ? d->foundMark.end : d->foundMark.start); |
432 | if (!d->foundMark.start && wrap) { | 432 | if (!d->foundMark.start && wrap) { |
433 | /* Wrap around */ | 433 | /* Wrap around. */ |
434 | d->foundMark = finder(d->doc, text_InputWidget(find), NULL); | 434 | d->foundMark = finder(d->doc, text_InputWidget(find), NULL); |
435 | } | 435 | } |
436 | if (d->foundMark.start) { | 436 | if (d->foundMark.start) { |
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c index 19623d74..c9be1a58 100644 --- a/src/ui/inputwidget.c +++ b/src/ui/inputwidget.c | |||
@@ -160,11 +160,11 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { | |||
160 | iWidget *w = as_Widget(d); | 160 | iWidget *w = as_Widget(d); |
161 | if (isCommand_Widget(w, ev, "focus.gained")) { | 161 | if (isCommand_Widget(w, ev, "focus.gained")) { |
162 | begin_InputWidget(d); | 162 | begin_InputWidget(d); |
163 | return iTrue; | 163 | return iFalse; |
164 | } | 164 | } |
165 | else if (isCommand_Widget(w, ev, "focus.lost")) { | 165 | else if (isCommand_Widget(w, ev, "focus.lost")) { |
166 | end_InputWidget(d, iTrue); | 166 | end_InputWidget(d, iTrue); |
167 | return iTrue; | 167 | return iFalse; |
168 | } | 168 | } |
169 | switch (processEvent_Click(&d->click, ev)) { | 169 | switch (processEvent_Click(&d->click, ev)) { |
170 | case none_ClickResult: | 170 | case none_ClickResult: |
diff --git a/src/ui/window.c b/src/ui/window.c index 4c140de2..8c252e81 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -132,6 +132,26 @@ static iBool handleSearchBarCommands_(iWidget *searchBar, const char *cmd) { | |||
132 | } | 132 | } |
133 | return iTrue; | 133 | return iTrue; |
134 | } | 134 | } |
135 | else if (equal_Command(cmd, "focus.gained")) { | ||
136 | if (pointer_Command(cmd) == findChild_Widget(searchBar, "find.input")) { | ||
137 | if (!isVisible_Widget(searchBar)) { | ||
138 | setFlags_Widget(searchBar, hidden_WidgetFlag, iFalse); | ||
139 | arrange_Widget(get_Window()->root); | ||
140 | refresh_App(); | ||
141 | } | ||
142 | } | ||
143 | } | ||
144 | else if (equal_Command(cmd, "find.close")) { | ||
145 | if (isVisible_Widget(searchBar)) { | ||
146 | if (isFocused_Widget(findChild_Widget(searchBar, "find.input"))) { | ||
147 | setFocus_Widget(NULL); | ||
148 | } | ||
149 | setFlags_Widget(searchBar, hidden_WidgetFlag, iTrue); | ||
150 | arrange_Widget(searchBar->parent); | ||
151 | refresh_Widget(searchBar->parent); | ||
152 | } | ||
153 | return iTrue; | ||
154 | } | ||
135 | return iFalse; | 155 | return iFalse; |
136 | } | 156 | } |
137 | 157 | ||
@@ -170,18 +190,19 @@ static void setupUserInterface_Window(iWindow *d) { | |||
170 | addChildFlags_Widget(div, iClob(new_DocumentWidget()), expand_WidgetFlag); | 190 | addChildFlags_Widget(div, iClob(new_DocumentWidget()), expand_WidgetFlag); |
171 | 191 | ||
172 | /* Search bar. */ { | 192 | /* Search bar. */ { |
173 | iWidget *searchBar = new_Widget(); | 193 | iWidget *searchBar = new_Widget(); |
174 | setId_Widget(searchBar, "search"); | 194 | setId_Widget(searchBar, "search"); |
175 | setFlags_Widget(searchBar, | 195 | setFlags_Widget(searchBar, |
176 | arrangeHeight_WidgetFlag | resizeChildren_WidgetFlag | | 196 | hidden_WidgetFlag | collapse_WidgetFlag | arrangeHeight_WidgetFlag | |
177 | arrangeHorizontal_WidgetFlag, | 197 | resizeChildren_WidgetFlag | arrangeHorizontal_WidgetFlag, |
178 | iTrue); | 198 | iTrue); |
179 | addChild_Widget(div, iClob(searchBar)); | 199 | addChild_Widget(div, iClob(searchBar)); |
180 | setBackgroundColor_Widget(searchBar, gray25_ColorId); | 200 | setBackgroundColor_Widget(searchBar, gray25_ColorId); |
181 | setCommandHandler_Widget(searchBar, handleSearchBarCommands_); | 201 | setCommandHandler_Widget(searchBar, handleSearchBarCommands_); |
182 | 202 | ||
183 | addChild_Widget(searchBar, iClob(new_LabelWidget("\U0001f50d Text", 0, 0, NULL))); | 203 | addChild_Widget(searchBar, iClob(new_LabelWidget("\U0001f50d Text", 0, 0, NULL))); |
184 | setId_Widget(addChildFlags_Widget(searchBar, iClob(new_InputWidget(0)), expand_WidgetFlag), | 204 | iInputWidget *input = new_InputWidget(0); |
205 | setId_Widget(addChildFlags_Widget(searchBar, iClob(input), expand_WidgetFlag), | ||
185 | "find.input"); | 206 | "find.input"); |
186 | addChild_Widget(searchBar, iClob(new_LabelWidget("Next", 'g', KMOD_PRIMARY, "find.next"))); | 207 | addChild_Widget(searchBar, iClob(new_LabelWidget("Next", 'g', KMOD_PRIMARY, "find.next"))); |
187 | addChild_Widget(searchBar, iClob(new_LabelWidget("Previous", 'g', KMOD_PRIMARY | KMOD_SHIFT, "find.prev"))); | 208 | addChild_Widget(searchBar, iClob(new_LabelWidget("Previous", 'g', KMOD_PRIMARY | KMOD_SHIFT, "find.prev"))); |