summaryrefslogtreecommitdiff
path: root/src/ui/text.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-03-06 14:44:17 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-03-06 14:44:17 +0200
commiteddc86b7b0795fe7c7a82d86f6ee151ccdca229f (patch)
tree7eea8ac70aa37d068adfc2d06dc066367a10572c /src/ui/text.c
parent7fa64b95d0c63b243f50b23c5551a7e04fe90c30 (diff)
Mobile: Dealing with keyboard height
The software keyboard obstructs part of the UI, so need to offset the view if the focused input widget would not be visible.
Diffstat (limited to 'src/ui/text.c')
-rw-r--r--src/ui/text.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/ui/text.c b/src/ui/text.c
index d3b8df37..b08bdc60 100644
--- a/src/ui/text.c
+++ b/src/ui/text.c
@@ -53,6 +53,7 @@ int enableHalfPixelGlyphs_Text = iTrue; /* debug setting */
53int enableKerning_Text = iTrue; /* looking up kern pairs is slow */ 53int enableKerning_Text = iTrue; /* looking up kern pairs is slow */
54 54
55static iBool enableRaster_Text_ = iTrue; 55static iBool enableRaster_Text_ = iTrue;
56static int numPendingRasterization_Text_ = 0;
56 57
57enum iGlyphFlag { 58enum iGlyphFlag {
58 rasterized0_GlyphFlag = iBit(1), /* zero offset */ 59 rasterized0_GlyphFlag = iBit(1), /* zero offset */
@@ -423,6 +424,7 @@ static void initCache_Text_(iText *d) {
423 d->cacheSize.x, 424 d->cacheSize.x,
424 d->cacheSize.y); 425 d->cacheSize.y);
425 SDL_SetTextureBlendMode(d->cache, SDL_BLENDMODE_BLEND); 426 SDL_SetTextureBlendMode(d->cache, SDL_BLENDMODE_BLEND);
427 numPendingRasterization_Text_ = 0;
426} 428}
427 429
428static void deinitCache_Text_(iText *d) { 430static void deinitCache_Text_(iText *d) {
@@ -501,6 +503,10 @@ void resetFonts_Text(void) {
501 initFonts_Text_(d); 503 initFonts_Text_(d);
502} 504}
503 505
506int numPendingGlyphs_Text(void) {
507 return numPendingRasterization_Text_;
508}
509
504iLocalDef iFont *font_Text_(enum iFontId id) { 510iLocalDef iFont *font_Text_(enum iFontId id) {
505 return &text_.fonts[id & mask_FontId]; 511 return &text_.fonts[id & mask_FontId];
506} 512}
@@ -569,7 +575,7 @@ static void allocate_Font_(iFont *d, iGlyph *glyph, int hoff) {
569 } 575 }
570} 576}
571 577
572static void cache_Font_(iFont *d, iGlyph *glyph, int hoff) { 578static iBool cache_Font_(iFont *d, iGlyph *glyph, int hoff) {
573 iText * txt = &text_; 579 iText * txt = &text_;
574 SDL_Renderer *render = txt->render; 580 SDL_Renderer *render = txt->render;
575 SDL_Texture * tex = NULL; 581 SDL_Texture * tex = NULL;
@@ -590,6 +596,7 @@ static void cache_Font_(iFont *d, iGlyph *glyph, int hoff) {
590 if (surface) { 596 if (surface) {
591 SDL_FreeSurface(surface); 597 SDL_FreeSurface(surface);
592 } 598 }
599 return isRasterized_Glyph_(glyph, hoff);
593} 600}
594 601
595iLocalDef iFont *characterFont_Font_(iFont *d, iChar ch, uint32_t *glyphIndex) { 602iLocalDef iFont *characterFont_Font_(iFont *d, iChar ch, uint32_t *glyphIndex) {
@@ -659,15 +666,22 @@ static const iGlyph *glyph_Font_(iFont *d, iChar ch) {
659 allocate_Font_(font, glyph, 0); 666 allocate_Font_(font, glyph, 0);
660 allocate_Font_(font, glyph, 1); 667 allocate_Font_(font, glyph, 1);
661 insert_Hash(&font->glyphs, &glyph->node); 668 insert_Hash(&font->glyphs, &glyph->node);
669 numPendingRasterization_Text_ += 2;
662 } 670 }
663 if (enableRaster_Text_ && !isFullyRasterized_Glyph_(glyph)) { 671 if (enableRaster_Text_ && !isFullyRasterized_Glyph_(glyph)) {
664 SDL_Texture *oldTarget = SDL_GetRenderTarget(text_.render); 672 SDL_Texture *oldTarget = SDL_GetRenderTarget(text_.render);
665 SDL_SetRenderTarget(text_.render, text_.cache); 673 SDL_SetRenderTarget(text_.render, text_.cache);
666 if (!isRasterized_Glyph_(glyph, 0)) { 674 if (!isRasterized_Glyph_(glyph, 0)) {
667 cache_Font_(font, glyph, 0); 675 if (cache_Font_(font, glyph, 0)) {
676 numPendingRasterization_Text_--;
677 iAssert(numPendingRasterization_Text_ >= 0);
678 }
668 } 679 }
669 if (!isRasterized_Glyph_(glyph, 1)) { 680 if (!isRasterized_Glyph_(glyph, 1)) {
670 cache_Font_(font, glyph, 1); /* half-pixel offset */ 681 if (cache_Font_(font, glyph, 1)) { /* half-pixel offset */
682 numPendingRasterization_Text_--;
683 iAssert(numPendingRasterization_Text_ >= 0);
684 }
671 } 685 }
672 SDL_SetRenderTarget(text_.render, oldTarget); 686 SDL_SetRenderTarget(text_.render, oldTarget);
673 } 687 }