diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-08-01 20:37:00 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-08-01 20:37:00 +0300 |
commit | cdc63088603169874b1e98aaf4196cc252a1eee9 (patch) | |
tree | 18bb186068653865f4fd91bcb385b33a384c8a1f /src | |
parent | 395cb3a996482c9e9fc27e00b4259219f85ec663 (diff) |
UploadWidget: Allow expanding to full window height
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/inputwidget.c | 17 | ||||
-rw-r--r-- | src/ui/inputwidget.h | 2 | ||||
-rw-r--r-- | src/ui/uploadwidget.c | 19 |
3 files changed, 34 insertions, 4 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c index 2ca9bd55..6246078e 100644 --- a/src/ui/inputwidget.c +++ b/src/ui/inputwidget.c | |||
@@ -709,10 +709,19 @@ void setMaxLen_InputWidget(iInputWidget *d, size_t maxLen) { | |||
709 | } | 709 | } |
710 | 710 | ||
711 | void setLineLimits_InputWidget(iInputWidget *d, int minLines, int maxLines) { | 711 | void setLineLimits_InputWidget(iInputWidget *d, int minLines, int maxLines) { |
712 | d->minWrapLines = minLines; | 712 | if (d->minWrapLines != minLines || d->maxWrapLines != maxLines) { |
713 | d->maxWrapLines = maxLines; | 713 | d->minWrapLines = minLines; |
714 | updateVisible_InputWidget_(d); | 714 | d->maxWrapLines = maxLines; |
715 | updateMetrics_InputWidget_(d); | 715 | updateVisible_InputWidget_(d); |
716 | updateMetrics_InputWidget_(d); | ||
717 | } | ||
718 | } | ||
719 | |||
720 | int minLines_InputWidget(const iInputWidget *d) { | ||
721 | return d->minWrapLines; | ||
722 | } | ||
723 | int maxLines_InputWidget(const iInputWidget *d) { | ||
724 | return d->maxWrapLines; | ||
716 | } | 725 | } |
717 | 726 | ||
718 | void setValidator_InputWidget(iInputWidget *d, iInputWidgetValidatorFunc validator, void *context) { | 727 | void setValidator_InputWidget(iInputWidget *d, iInputWidgetValidatorFunc validator, void *context) { |
diff --git a/src/ui/inputwidget.h b/src/ui/inputwidget.h index 959eb334..a94291ed 100644 --- a/src/ui/inputwidget.h +++ b/src/ui/inputwidget.h | |||
@@ -63,6 +63,8 @@ void setUrlContent_InputWidget (iInputWidget *, iBool isUrl); | |||
63 | void setNotifyEdits_InputWidget (iInputWidget *, iBool notifyEdits); | 63 | void setNotifyEdits_InputWidget (iInputWidget *, iBool notifyEdits); |
64 | void setEatEscape_InputWidget (iInputWidget *, iBool eatEscape); | 64 | void setEatEscape_InputWidget (iInputWidget *, iBool eatEscape); |
65 | 65 | ||
66 | int minLines_InputWidget (const iInputWidget *); | ||
67 | int maxLines_InputWidget (const iInputWidget *); | ||
66 | iInputWidgetContentPadding contentPadding_InputWidget (const iInputWidget *); | 68 | iInputWidgetContentPadding contentPadding_InputWidget (const iInputWidget *); |
67 | const iString * text_InputWidget (const iInputWidget *); | 69 | const iString * text_InputWidget (const iInputWidget *); |
68 | 70 | ||
diff --git a/src/ui/uploadwidget.c b/src/ui/uploadwidget.c index 7dd26e93..7f2a68bf 100644 --- a/src/ui/uploadwidget.c +++ b/src/ui/uploadwidget.c | |||
@@ -24,6 +24,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
24 | #include "labelwidget.h" | 24 | #include "labelwidget.h" |
25 | #include "inputwidget.h" | 25 | #include "inputwidget.h" |
26 | #include "documentwidget.h" | 26 | #include "documentwidget.h" |
27 | #include "root.h" | ||
27 | #include "color.h" | 28 | #include "color.h" |
28 | #include "command.h" | 29 | #include "command.h" |
29 | #include "gmrequest.h" | 30 | #include "gmrequest.h" |
@@ -62,6 +63,20 @@ static void updateProgress_UploadWidget_(iGmRequest *request, size_t current, si | |||
62 | total); | 63 | total); |
63 | } | 64 | } |
64 | 65 | ||
66 | static void updateInputMaxHeight_UploadWidget_(iUploadWidget *d) { | ||
67 | iWidget *w = as_Widget(d); | ||
68 | /* Calculate how many lines fits vertically in the view. */ | ||
69 | const iInt2 inputPos = topLeft_Rect(bounds_Widget(as_Widget(d->input))); | ||
70 | const int footerHeight = height_Widget(d->token) + | ||
71 | height_Widget(findChild_Widget(w, "dialogbuttons")) + | ||
72 | 6 * gap_UI; | ||
73 | const int avail = bottom_Rect(safeRect_Root(w->root)) - footerHeight; | ||
74 | setLineLimits_InputWidget(d->input, | ||
75 | minLines_InputWidget(d->input), | ||
76 | iMaxi(minLines_InputWidget(d->input), | ||
77 | (avail - inputPos.y) / lineHeight_Text(monospace_FontId))); | ||
78 | } | ||
79 | |||
65 | void init_UploadWidget(iUploadWidget *d) { | 80 | void init_UploadWidget(iUploadWidget *d) { |
66 | iWidget *w = as_Widget(d); | 81 | iWidget *w = as_Widget(d); |
67 | init_Widget(w); | 82 | init_Widget(w); |
@@ -152,6 +167,7 @@ void init_UploadWidget(iUploadWidget *d) { | |||
152 | setFlags_Widget(as_Widget(d->token), expand_WidgetFlag, iTrue); | 167 | setFlags_Widget(as_Widget(d->token), expand_WidgetFlag, iTrue); |
153 | setFocus_Widget(as_Widget(d->input)); | 168 | setFocus_Widget(as_Widget(d->input)); |
154 | setBackupFileName_InputWidget(d->input, "uploadbackup.txt"); | 169 | setBackupFileName_InputWidget(d->input, "uploadbackup.txt"); |
170 | updateInputMaxHeight_UploadWidget_(d); | ||
155 | } | 171 | } |
156 | 172 | ||
157 | void deinit_UploadWidget(iUploadWidget *d) { | 173 | void deinit_UploadWidget(iUploadWidget *d) { |
@@ -214,6 +230,9 @@ static void requestFinished_UploadWidget_(iUploadWidget *d, iGmRequest *req) { | |||
214 | static iBool processEvent_UploadWidget_(iUploadWidget *d, const SDL_Event *ev) { | 230 | static iBool processEvent_UploadWidget_(iUploadWidget *d, const SDL_Event *ev) { |
215 | iWidget *w = as_Widget(d); | 231 | iWidget *w = as_Widget(d); |
216 | const char *cmd = command_UserEvent(ev); | 232 | const char *cmd = command_UserEvent(ev); |
233 | if (isResize_UserEvent(ev)) { | ||
234 | updateInputMaxHeight_UploadWidget_(d); | ||
235 | } | ||
217 | if (isCommand_Widget(w, ev, "upload.cancel")) { | 236 | if (isCommand_Widget(w, ev, "upload.cancel")) { |
218 | setupSheetTransition_Mobile(w, iFalse); | 237 | setupSheetTransition_Mobile(w, iFalse); |
219 | destroy_Widget(w); | 238 | destroy_Widget(w); |