From addeb72d30b50969a5134ef8ec3abcc367a1a4ba Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 19 Aug 2019 18:22:16 +1000 Subject: [PATCH] Replace TextGroupWidget_SetUsePlaceHolder with simpler method --- src/Gui.h | 4 ++-- src/Screens.c | 2 +- src/Widgets.c | 17 ++++++----------- src/Widgets.h | 4 +--- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/Gui.h b/src/Gui.h index 6e69715b4..f58a7b078 100644 --- a/src/Gui.h +++ b/src/Gui.h @@ -157,8 +157,8 @@ struct TextAtlas { struct Texture tex; int offset, curX; float uScale; - int16_t widths[TEXTATLAS_MAX_WIDTHS]; - int16_t offsets[TEXTATLAS_MAX_WIDTHS]; + short widths[TEXTATLAS_MAX_WIDTHS]; + short offsets[TEXTATLAS_MAX_WIDTHS]; }; void TextAtlas_Make(struct TextAtlas* atlas, const String* chars, const FontDesc* font, const String* prefix); void TextAtlas_Free(struct TextAtlas* atlas); diff --git a/src/Screens.c b/src/Screens.c index c4437e96e..65657d9e6 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -710,8 +710,8 @@ static void HUDScreen_ConstructWidgets(struct HUDScreen* s) { TextGroupWidget_Create(&s->status, CHAT_MAX_STATUS, &s->chatFont, s->statusTextures, HUDScreen_GetStatus); Widget_SetLocation(&s->status, ANCHOR_MAX, ANCHOR_MIN, 0, 0); + s->status.placeholderHeight[0] = false; /* Texture pack download status */ Elem_Init(&s->status); - TextGroupWidget_SetUsePlaceHolder(&s->status, 0, false); TextGroupWidget_Create(&s->bottomRight, CHAT_MAX_BOTTOMRIGHT, &s->chatFont, s->bottomRightTextures, HUDScreen_GetBottomRight); diff --git a/src/Widgets.c b/src/Widgets.c index 681f342f5..67e1fce81 100644 --- a/src/Widgets.c +++ b/src/Widgets.c @@ -2174,14 +2174,6 @@ static void TextGroupWidget_UpdateY(struct TextGroupWidget* w) { } } -void TextGroupWidget_SetUsePlaceHolder(struct TextGroupWidget* w, int index, bool placeHolder) { - w->placeholderHeight[index] = placeHolder; - if (w->textures[index].ID) return; - - w->textures[index].Height = placeHolder ? w->defaultHeight : 0; - TextGroupWidget_UpdateY(w); -} - int TextGroupWidget_UsedHeight(struct TextGroupWidget* w) { struct Texture* textures = w->textures; int i, height = 0; @@ -2221,7 +2213,7 @@ static void TextGroupWidget_UpdateDimensions(struct TextGroupWidget* w) { Widget_Reposition(w); } -struct Portion { int16_t Beg, Len, LineBeg, LineLen; }; +struct Portion { short Beg, Len, LineBeg, LineLen; }; #define TEXTGROUPWIDGET_HTTP_LEN 7 /* length of http:// */ #define TEXTGROUPWIDGET_URL 0x8000 #define TEXTGROUPWIDGET_PACKED_LEN 0x7FFF @@ -2515,8 +2507,7 @@ static void TextGroupWidget_Init(void* widget) { w->defaultHeight = height; for (i = 0; i < w->lines; i++) { - w->textures[i].Height = height; - w->placeholderHeight[i] = true; + w->textures[i].Height = w->placeholderHeight[i] ? height : 0; } TextGroupWidget_UpdateDimensions(w); } @@ -2548,8 +2539,12 @@ static struct WidgetVTABLE TextGroupWidget_VTABLE = { TextGroupWidget_Reposition }; void TextGroupWidget_Create(struct TextGroupWidget* w, int lines, FontDesc* font, struct Texture* textures, TextGroupWidget_Get getLine) { + int i; Widget_Reset(w); w->VTABLE = &TextGroupWidget_VTABLE; + for (i = 0; i < lines; i++) { + w->placeholderHeight[i] = true; + } w->lines = lines; w->font = font; diff --git a/src/Widgets.h b/src/Widgets.h index 4dfc39651..1b3e544a3 100644 --- a/src/Widgets.h +++ b/src/Widgets.h @@ -203,6 +203,7 @@ struct TextGroupWidget { Widget_Layout int lines, defaultHeight; FontDesc* font; + /* Whether a line has non-zero height when that line has no text in it. */ bool placeholderHeight[TEXTGROUPWIDGET_MAX_LINES]; bool underlineUrls; struct Texture* textures; @@ -211,9 +212,6 @@ struct TextGroupWidget { }; CC_NOINLINE void TextGroupWidget_Create(struct TextGroupWidget* w, int lines, FontDesc* font, struct Texture* textures, TextGroupWidget_Get getLine); -/* Sets whether the given line has non-zero height when that line has no text in it. */ -/* By default, all lines are placeholder lines. */ -CC_NOINLINE void TextGroupWidget_SetUsePlaceHolder(struct TextGroupWidget* w, int index, bool placeHolder); /* Deletes first line, then moves all other lines upwards, then redraws last line. */ /* NOTE: GetLine must also adjust the lines it returns for this to behave properly. */ CC_NOINLINE void TextGroupWidget_ShiftUp(struct TextGroupWidget* w);