summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-08-10 13:34:41 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-08-10 13:34:41 +0300
commit935337e3395579e46e3a301fccec647d520d2820 (patch)
treeea655581389ac452a27b29cc212c069f0e79d407 /src/ui
parenteae9636f254c2709167eefe0c2daaca578bfdde4 (diff)
DocumentWidget: Fixed drawing of empty document
An empty document would could the widget to be drawn as a black non-themed rectangle, with a single-pixel horizontal line in the middle. This fixes that by just clearing the widget to the UI background color. The most notable situation where this occurred was immediately after activating split view mode.
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/documentwidget.c111
-rw-r--r--src/ui/visbuf.c8
2 files changed, 59 insertions, 60 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 6a5ed172..703d1d13 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -4796,64 +4796,67 @@ static void draw_DocumentWidget_(const iDocumentWidget *d) {
4796 }; 4796 };
4797 init_Paint(&ctx.paint); 4797 init_Paint(&ctx.paint);
4798 render_DocumentWidget_(d, &ctx, iFalse /* just the mandatory parts */); 4798 render_DocumentWidget_(d, &ctx, iFalse /* just the mandatory parts */);
4799 setClip_Paint(&ctx.paint, clipBounds); 4799 int yTop = docBounds.pos.y - pos_SmoothScroll(&d->scrollY);
4800 int yTop = docBounds.pos.y - pos_SmoothScroll(&d->scrollY); 4800 const iBool isDocEmpty = size_GmDocument(d->doc).y == 0;
4801 draw_VisBuf(d->visBuf, init_I2(bounds.pos.x, yTop), ySpan_Rect(bounds));
4802 /* Text markers. */
4803 const iBool isTouchSelecting = (flags_Widget(w) & touchDrag_WidgetFlag) != 0; 4801 const iBool isTouchSelecting = (flags_Widget(w) & touchDrag_WidgetFlag) != 0;
4804 if (!isEmpty_Range(&d->foundMark) || !isEmpty_Range(&d->selectMark)) { 4802 if (!isDocEmpty) {
4805 SDL_Renderer *render = renderer_Window(get_Window()); 4803 setClip_Paint(&ctx.paint, clipBounds);
4806 ctx.firstMarkRect = zero_Rect(); 4804 draw_VisBuf(d->visBuf, init_I2(bounds.pos.x, yTop), ySpan_Rect(bounds));
4807 ctx.lastMarkRect = zero_Rect(); 4805 /* Text markers. */
4808 SDL_SetRenderDrawBlendMode(render, 4806 if (!isEmpty_Range(&d->foundMark) || !isEmpty_Range(&d->selectMark)) {
4809 isDark_ColorTheme(colorTheme_App()) ? SDL_BLENDMODE_ADD 4807 SDL_Renderer *render = renderer_Window(get_Window());
4810 : SDL_BLENDMODE_BLEND); 4808 ctx.firstMarkRect = zero_Rect();
4811 ctx.viewPos = topLeft_Rect(docBounds); 4809 ctx.lastMarkRect = zero_Rect();
4812 /* Marker starting outside the visible range? */ 4810 SDL_SetRenderDrawBlendMode(render,
4813 if (d->visibleRuns.start) { 4811 isDark_ColorTheme(colorTheme_App()) ? SDL_BLENDMODE_ADD
4814 if (!isEmpty_Range(&d->selectMark) && 4812 : SDL_BLENDMODE_BLEND);
4815 d->selectMark.start < d->visibleRuns.start->text.start && 4813 ctx.viewPos = topLeft_Rect(docBounds);
4816 d->selectMark.end > d->visibleRuns.start->text.start) { 4814 /* Marker starting outside the visible range? */
4817 ctx.inSelectMark = iTrue; 4815 if (d->visibleRuns.start) {
4816 if (!isEmpty_Range(&d->selectMark) &&
4817 d->selectMark.start < d->visibleRuns.start->text.start &&
4818 d->selectMark.end > d->visibleRuns.start->text.start) {
4819 ctx.inSelectMark = iTrue;
4820 }
4821 if (isEmpty_Range(&d->foundMark) &&
4822 d->foundMark.start < d->visibleRuns.start->text.start &&
4823 d->foundMark.end > d->visibleRuns.start->text.start) {
4824 ctx.inFoundMark = iTrue;
4825 }
4818 } 4826 }
4819 if (isEmpty_Range(&d->foundMark) && 4827 render_GmDocument(d->doc, vis, drawMark_DrawContext_, &ctx);
4820 d->foundMark.start < d->visibleRuns.start->text.start && 4828 SDL_SetRenderDrawBlendMode(render, SDL_BLENDMODE_NONE);
4821 d->foundMark.end > d->visibleRuns.start->text.start) { 4829 /* Selection range pins. */
4822 ctx.inFoundMark = iTrue; 4830 if (isTouchSelecting) {
4831 drawPin_(&ctx.paint, ctx.firstMarkRect, 0);
4832 drawPin_(&ctx.paint, ctx.lastMarkRect, 1);
4823 } 4833 }
4824 } 4834 }
4825 render_GmDocument(d->doc, vis, drawMark_DrawContext_, &ctx); 4835 drawMedia_DocumentWidget_(d, &ctx.paint);
4826 SDL_SetRenderDrawBlendMode(render, SDL_BLENDMODE_NONE); 4836 /* Fill the top and bottom, in case the document is short. */
4827 /* Selection range pins. */ 4837 if (yTop > top_Rect(bounds)) {
4828 if (isTouchSelecting) { 4838 fillRect_Paint(&ctx.paint,
4829 drawPin_(&ctx.paint, ctx.firstMarkRect, 0); 4839 (iRect){ bounds.pos, init_I2(bounds.size.x, yTop - top_Rect(bounds)) },
4830 drawPin_(&ctx.paint, ctx.lastMarkRect, 1); 4840 hasSiteBanner_GmDocument(d->doc) ? tmBannerBackground_ColorId
4831 } 4841 : tmBackground_ColorId);
4832 } 4842 }
4833 drawMedia_DocumentWidget_(d, &ctx.paint); 4843 const int yBottom = yTop + size_GmDocument(d->doc).y + 1;
4834 /* Fill the top and bottom, in case the document is short. */ 4844 if (yBottom < bottom_Rect(bounds)) {
4835 if (yTop > top_Rect(bounds)) { 4845 fillRect_Paint(&ctx.paint,
4836 fillRect_Paint(&ctx.paint, 4846 init_Rect(bounds.pos.x, yBottom, bounds.size.x, bottom_Rect(bounds) - yBottom),
4837 (iRect){ bounds.pos, init_I2(bounds.size.x, yTop - top_Rect(bounds)) }, 4847 tmBackground_ColorId);
4838 hasSiteBanner_GmDocument(d->doc) ? tmBannerBackground_ColorId 4848 }
4839 : tmBackground_ColorId); 4849 unsetClip_Paint(&ctx.paint);
4840 } 4850 drawSideElements_DocumentWidget_(d);
4841 const int yBottom = yTop + size_GmDocument(d->doc).y + 1; 4851 if (prefs_App()->hoverLink && d->hoverLink) {
4842 if (yBottom < bottom_Rect(bounds)) { 4852 const int font = uiLabel_FontId;
4843 fillRect_Paint(&ctx.paint, 4853 const iRangecc linkUrl = range_String(linkUrl_GmDocument(d->doc, d->hoverLink->linkId));
4844 init_Rect(bounds.pos.x, yBottom, bounds.size.x, bottom_Rect(bounds) - yBottom), 4854 const iInt2 size = measureRange_Text(font, linkUrl).bounds.size;
4845 tmBackground_ColorId); 4855 const iRect linkRect = { addY_I2(bottomLeft_Rect(bounds), -size.y),
4846 } 4856 addX_I2(size, 2 * gap_UI) };
4847 unsetClip_Paint(&ctx.paint); 4857 fillRect_Paint(&ctx.paint, linkRect, tmBackground_ColorId);
4848 drawSideElements_DocumentWidget_(d); 4858 drawRange_Text(font, addX_I2(topLeft_Rect(linkRect), gap_UI), tmParagraph_ColorId, linkUrl);
4849 if (prefs_App()->hoverLink && d->hoverLink) { 4859 }
4850 const int font = uiLabel_FontId;
4851 const iRangecc linkUrl = range_String(linkUrl_GmDocument(d->doc, d->hoverLink->linkId));
4852 const iInt2 size = measureRange_Text(font, linkUrl).bounds.size;
4853 const iRect linkRect = { addY_I2(bottomLeft_Rect(bounds), -size.y),
4854 addX_I2(size, 2 * gap_UI) };
4855 fillRect_Paint(&ctx.paint, linkRect, tmBackground_ColorId);
4856 drawRange_Text(font, addX_I2(topLeft_Rect(linkRect), gap_UI), tmParagraph_ColorId, linkUrl);
4857 } 4860 }
4858 if (colorTheme_App() == pureWhite_ColorTheme) { 4861 if (colorTheme_App() == pureWhite_ColorTheme) {
4859 drawHLine_Paint(&ctx.paint, topLeft_Rect(bounds), width_Rect(bounds), uiSeparator_ColorId); 4862 drawHLine_Paint(&ctx.paint, topLeft_Rect(bounds), width_Rect(bounds), uiSeparator_ColorId);
diff --git a/src/ui/visbuf.c b/src/ui/visbuf.c
index 88a5fd60..503d0a2f 100644
--- a/src/ui/visbuf.c
+++ b/src/ui/visbuf.c
@@ -58,18 +58,14 @@ void alloc_VisBuf(iVisBuf *d, const iInt2 size, int granularity) {
58 if (tex->texture) { 58 if (tex->texture) {
59 SDL_DestroyTexture(tex->texture); 59 SDL_DestroyTexture(tex->texture);
60 } 60 }
61 SDL_Renderer *rend = renderer_Window(get_Window());
61 tex->texture = 62 tex->texture =
62 SDL_CreateTexture(renderer_Window(get_Window()), 63 SDL_CreateTexture(rend,
63 SDL_PIXELFORMAT_RGBA8888, 64 SDL_PIXELFORMAT_RGBA8888,
64 SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET, 65 SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET,
65 texSize.x, 66 texSize.x,
66 texSize.y); 67 texSize.y);
67 SDL_SetTextureBlendMode(tex->texture, SDL_BLENDMODE_NONE); 68 SDL_SetTextureBlendMode(tex->texture, SDL_BLENDMODE_NONE);
68// tex->origin = i * texSize.y;
69// iZap(tex->validRange);
70// if (d->invalidUserData) {
71// d->invalidUserData(i, d->buffers[i].user);
72// }
73 } 69 }
74 invalidate_VisBuf(d); 70 invalidate_VisBuf(d);
75 } 71 }