diff options
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r-- | src/ui/documentwidget.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 7fe30f1e..acfa9eac 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -177,6 +177,12 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
177 | } | 177 | } |
178 | else if (ev->type == SDL_MOUSEWHEEL) { | 178 | else if (ev->type == SDL_MOUSEWHEEL) { |
179 | d->scrollY -= 3 * ev->wheel.y * lineHeight_Text(default_FontId); | 179 | d->scrollY -= 3 * ev->wheel.y * lineHeight_Text(default_FontId); |
180 | if (d->scrollY < 0) d->scrollY = 0; | ||
181 | const int scrollMax = | ||
182 | size_GmDocument(d->doc).y - height_Rect(bounds_Widget(w)) + d->pageMargin * gap_UI; | ||
183 | if (scrollMax > 0) { | ||
184 | d->scrollY = iMin(d->scrollY, scrollMax); | ||
185 | } | ||
180 | postRefresh_App(); | 186 | postRefresh_App(); |
181 | return iTrue; | 187 | return iTrue; |
182 | } | 188 | } |
@@ -198,7 +204,7 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
198 | initRange_String(&text, run->text); | 204 | initRange_String(&text, run->text); |
199 | iInt2 origin = addY_I2(d->bounds.pos, -d->widget->scrollY); | 205 | iInt2 origin = addY_I2(d->bounds.pos, -d->widget->scrollY); |
200 | drawString_Text(run->font, add_I2(run->bounds.pos, origin), run->color, &text); | 206 | drawString_Text(run->font, add_I2(run->bounds.pos, origin), run->color, &text); |
201 | // drawRect_Paint(&d->paint, moved_Rect(run->bounds, origin), red_ColorId); | 207 | drawRect_Paint(&d->paint, moved_Rect(run->bounds, origin), red_ColorId); |
202 | deinit_String(&text); | 208 | deinit_String(&text); |
203 | } | 209 | } |
204 | 210 | ||
@@ -215,13 +221,15 @@ static void draw_DocumentWidget_(const iDocumentWidget *d) { | |||
215 | } | 221 | } |
216 | if (d->state != ready_DocumentState) return; | 222 | if (d->state != ready_DocumentState) return; |
217 | iDrawContext ctx = {.widget = d, .bounds = bounds_Widget(w) }; | 223 | iDrawContext ctx = {.widget = d, .bounds = bounds_Widget(w) }; |
218 | shrink_Rect(&ctx.bounds, init1_I2(gap_UI * d->pageMargin)); | 224 | const int margin = gap_UI * d->pageMargin; |
225 | shrink_Rect(&ctx.bounds, init1_I2(margin)); | ||
219 | init_Paint(&ctx.paint); | 226 | init_Paint(&ctx.paint); |
220 | drawRect_Paint(&ctx.paint, ctx.bounds, teal_ColorId); | 227 | drawRect_Paint(&ctx.paint, ctx.bounds, teal_ColorId); |
221 | render_GmDocument(d->doc, | 228 | render_GmDocument( |
222 | (iRangei){ d->scrollY, d->scrollY + height_Rect(ctx.bounds) }, | 229 | d->doc, |
223 | drawRun_DrawContext_, | 230 | (iRangei){ d->scrollY - margin, d->scrollY + height_Rect(ctx.bounds) + margin }, |
224 | &ctx); | 231 | drawRun_DrawContext_, |
232 | &ctx); | ||
225 | } | 233 | } |
226 | 234 | ||
227 | iBeginDefineSubclass(DocumentWidget, Widget) | 235 | iBeginDefineSubclass(DocumentWidget, Widget) |