diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/documentwidget.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index acfa9eac..55ac6b80 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -6,6 +6,7 @@ | |||
6 | #include "../gmdocument.h" | 6 | #include "../gmdocument.h" |
7 | 7 | ||
8 | #include <the_Foundation/file.h> | 8 | #include <the_Foundation/file.h> |
9 | #include <the_Foundation/path.h> | ||
9 | #include <the_Foundation/regexp.h> | 10 | #include <the_Foundation/regexp.h> |
10 | #include <the_Foundation/tlsrequest.h> | 11 | #include <the_Foundation/tlsrequest.h> |
11 | 12 | ||
@@ -73,7 +74,8 @@ void init_DocumentWidget(iDocumentWidget *d) { | |||
73 | d->doc = new_GmDocument(); | 74 | d->doc = new_GmDocument(); |
74 | d->pageMargin = 5; | 75 | d->pageMargin = 5; |
75 | d->scrollY = 0; | 76 | d->scrollY = 0; |
76 | setUrl_DocumentWidget(d, collectNewCStr_String("file:///home/jaakko/test.gmi")); | 77 | setUrl_DocumentWidget( |
78 | d, collectNewFormat_String("file://%s/test.gmi", cstr_String(collect_String(home_Path())))); | ||
77 | } | 79 | } |
78 | 80 | ||
79 | void deinit_DocumentWidget(iDocumentWidget *d) { | 81 | void deinit_DocumentWidget(iDocumentWidget *d) { |
@@ -85,7 +87,7 @@ void deinit_DocumentWidget(iDocumentWidget *d) { | |||
85 | static int documentWidth_DocumentWidget_(const iDocumentWidget *d) { | 87 | static int documentWidth_DocumentWidget_(const iDocumentWidget *d) { |
86 | const iWidget *w = constAs_Widget(d); | 88 | const iWidget *w = constAs_Widget(d); |
87 | const iRect bounds = bounds_Widget(w); | 89 | const iRect bounds = bounds_Widget(w); |
88 | return bounds.size.x - gap_UI * d->pageMargin * 2; | 90 | return iMini(bounds.size.x - gap_UI * d->pageMargin * 2, fontSize_UI * 40); |
89 | } | 91 | } |
90 | 92 | ||
91 | void setSource_DocumentWidget(iDocumentWidget *d, const iString *source) { | 93 | void setSource_DocumentWidget(iDocumentWidget *d, const iString *source) { |
@@ -177,12 +179,17 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
177 | } | 179 | } |
178 | else if (ev->type == SDL_MOUSEWHEEL) { | 180 | else if (ev->type == SDL_MOUSEWHEEL) { |
179 | d->scrollY -= 3 * ev->wheel.y * lineHeight_Text(default_FontId); | 181 | d->scrollY -= 3 * ev->wheel.y * lineHeight_Text(default_FontId); |
180 | if (d->scrollY < 0) d->scrollY = 0; | 182 | if (d->scrollY < 0) { |
183 | d->scrollY = 0; | ||
184 | } | ||
181 | const int scrollMax = | 185 | const int scrollMax = |
182 | size_GmDocument(d->doc).y - height_Rect(bounds_Widget(w)) + d->pageMargin * gap_UI; | 186 | size_GmDocument(d->doc).y - height_Rect(bounds_Widget(w)) + d->pageMargin * gap_UI; |
183 | if (scrollMax > 0) { | 187 | if (scrollMax > 0) { |
184 | d->scrollY = iMin(d->scrollY, scrollMax); | 188 | d->scrollY = iMin(d->scrollY, scrollMax); |
185 | } | 189 | } |
190 | else { | ||
191 | d->scrollY = 0; | ||
192 | } | ||
186 | postRefresh_App(); | 193 | postRefresh_App(); |
187 | return iTrue; | 194 | return iTrue; |
188 | } | 195 | } |
@@ -204,7 +211,7 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
204 | initRange_String(&text, run->text); | 211 | initRange_String(&text, run->text); |
205 | iInt2 origin = addY_I2(d->bounds.pos, -d->widget->scrollY); | 212 | iInt2 origin = addY_I2(d->bounds.pos, -d->widget->scrollY); |
206 | drawString_Text(run->font, add_I2(run->bounds.pos, origin), run->color, &text); | 213 | drawString_Text(run->font, add_I2(run->bounds.pos, origin), run->color, &text); |
207 | drawRect_Paint(&d->paint, moved_Rect(run->bounds, origin), red_ColorId); | 214 | // drawRect_Paint(&d->paint, moved_Rect(run->bounds, origin), red_ColorId); |
208 | deinit_String(&text); | 215 | deinit_String(&text); |
209 | } | 216 | } |
210 | 217 | ||
@@ -223,6 +230,8 @@ static void draw_DocumentWidget_(const iDocumentWidget *d) { | |||
223 | iDrawContext ctx = {.widget = d, .bounds = bounds_Widget(w) }; | 230 | iDrawContext ctx = {.widget = d, .bounds = bounds_Widget(w) }; |
224 | const int margin = gap_UI * d->pageMargin; | 231 | const int margin = gap_UI * d->pageMargin; |
225 | shrink_Rect(&ctx.bounds, init1_I2(margin)); | 232 | shrink_Rect(&ctx.bounds, init1_I2(margin)); |
233 | ctx.bounds.size.x = documentWidth_DocumentWidget_(d); | ||
234 | ctx.bounds.pos.x = bounds_Widget(w).size.x / 2 - ctx.bounds.size.x / 2; | ||
226 | init_Paint(&ctx.paint); | 235 | init_Paint(&ctx.paint); |
227 | drawRect_Paint(&ctx.paint, ctx.bounds, teal_ColorId); | 236 | drawRect_Paint(&ctx.paint, ctx.bounds, teal_ColorId); |
228 | render_GmDocument( | 237 | render_GmDocument( |