From 69b0df4e3fbdb9bca7448e0d05e37845fa6dd0b5 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 6 May 2022 18:47:49 +1000 Subject: [PATCH] iOS: Avoid loading all system fonts when going to servers menu --- src/LBackend.c | 12 ++++++++---- src/LScreens.c | 11 +---------- src/LWidgets.c | 3 +-- src/LWidgets.h | 7 +++---- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/LBackend.c b/src/LBackend.c index 35b61a880..e0f5d9bea 100644 --- a/src/LBackend.c +++ b/src/LBackend.c @@ -25,7 +25,7 @@ #include "Utils.h" #include "Event.h" -struct FontDesc titleFont, textFont, hintFont, logoFont; +struct FontDesc titleFont, textFont, hintFont, logoFont, rowFont; /* Contains the pixels that are drawn to the window */ static struct Bitmap framebuffer; /* The area/region of the window that needs to be redrawn and presented to the screen. */ @@ -85,6 +85,7 @@ void LBackend_Free(void) { Font_Free(&textFont); Font_Free(&hintFont); Font_Free(&logoFont); + Font_Free(&rowFont); } void LBackend_UpdateLogoFont(void) { @@ -706,13 +707,16 @@ void LBackend_SliderDraw(struct LSlider* w) { /*########################################################################################################################* *-------------------------------------------------------TableWidget-------------------------------------------------------* *#########################################################################################################################*/ -void LBackend_TableInit(struct LTable* w) { } +void LBackend_TableInit(struct LTable* w) { + if (rowFont.handle) return; + Drawer2D_MakeFont(&rowFont, 11, FONT_FLAGS_NONE); +} void LBackend_TableUpdate(struct LTable* w) { } void LBackend_TableReposition(struct LTable* w) { int rowsHeight; w->hdrHeight = Drawer2D_FontHeight(&textFont, true) + hdrYPadding; - w->rowHeight = Drawer2D_FontHeight(w->rowFont, true) + rowYPadding; + w->rowHeight = Drawer2D_FontHeight(&rowFont, true) + rowYPadding; w->rowsBegY = w->y + w->hdrHeight + gridlineHeight; w->rowsEndY = w->y + w->height; @@ -843,7 +847,7 @@ static void LTable_DrawRows(struct LTable* w) { int i, x, y, row, end; String_InitArray(str, strBuffer); - DrawTextArgs_Make(&args, &str, w->rowFont, true); + DrawTextArgs_Make(&args, &str, &rowFont, true); cell.table = w; y = w->rowsBegY; end = w->topRow + w->visibleRows; diff --git a/src/LScreens.c b/src/LScreens.c index b990bcf2a..001ad57c5 100644 --- a/src/LScreens.c +++ b/src/LScreens.c @@ -1316,7 +1316,7 @@ static void ServersScreen_Init(struct LScreen* s_) { s->iptHash.TextChanged = ServersScreen_HashChanged; s->iptHash.ClipboardFilter = ServersScreen_HashFilter; - LTable_Init(&s->table, &s->rowFont); + LTable_Init(&s->table); s->table.filter = &s->iptSearch.text; s->table.selectedHash = &s->iptHash.text; s->table.OnSelectedChanged = ServersScreen_OnSelectedChanged; @@ -1324,9 +1324,6 @@ static void ServersScreen_Init(struct LScreen* s_) { static void ServersScreen_Show(struct LScreen* s_) { struct ServersScreen* s = (struct ServersScreen*)s_; - Drawer2D_MakeFont(&s->rowFont, 11, FONT_FLAGS_NONE); - - s->table.rowFont = &s->rowFont; LTable_Reset(&s->table); LInput_ClearText(&s->iptHash); LInput_ClearText(&s->iptSearch); @@ -1360,11 +1357,6 @@ static void ServersScreen_Tick(struct LScreen* s_) { FetchServersTask.Base.success ? "Refresh" : "&cFailed"); } -static void ServersScreen_Free(struct LScreen* s_) { - struct ServersScreen* s = (struct ServersScreen*)s_; - Font_Free(&s->rowFont); -} - static void ServersScreen_Layout(struct LScreen* s_) { struct ServersScreen* s = (struct ServersScreen*)s_; LWidget_SetLocation(&s->iptSearch, ANCHOR_MIN, ANCHOR_MIN, 10, 10); @@ -1410,7 +1402,6 @@ void ServersScreen_SetActive(void) { s->Init = ServersScreen_Init; s->Show = ServersScreen_Show; s->Tick = ServersScreen_Tick; - s->Free = ServersScreen_Free; s->Layout = ServersScreen_Layout; s->MouseWheel = ServersScreen_MouseWheel; s->KeyDown = ServersScreen_KeyDown; diff --git a/src/LWidgets.c b/src/LWidgets.c index 7a2f2bddd..be37edebc 100644 --- a/src/LWidgets.c +++ b/src/LWidgets.c @@ -629,13 +629,12 @@ static const struct LWidgetVTABLE ltable_VTABLE = { LTable_MouseDown, LTable_MouseUp, /* Select */ LTable_MouseWheel, /* Wheel */ }; -void LTable_Init(struct LTable* w, struct FontDesc* rowFont) { +void LTable_Init(struct LTable* w) { int i; w->VTABLE = <able_VTABLE; w->type = LWIDGET_TABLE; w->columns = tableColumns; w->numColumns = Array_Elems(tableColumns); - w->rowFont = rowFont; w->sortingCol = -1; w->opaque = true; diff --git a/src/LWidgets.h b/src/LWidgets.h index 8614e254c..8873b5376 100644 --- a/src/LWidgets.h +++ b/src/LWidgets.h @@ -123,6 +123,7 @@ CC_NOINLINE void LLabel_SetConst(struct LLabel* w, const char* text); /* Represents a coloured translucent line separator. */ struct LLine { LWidget_Layout + int _width; }; CC_NOINLINE void LLine_Init(struct LLine* w, int width); CC_NOINLINE BitmapCol LLine_GetColor(void); @@ -130,7 +131,7 @@ CC_NOINLINE BitmapCol LLine_GetColor(void); /* Represents a slider bar that may or may not be modifiable by the user. */ struct LSlider { LWidget_Layout - int value; + int value, _width, _height; BitmapCol color; }; CC_NOINLINE void LSlider_Init(struct LSlider* w, int width, int height, BitmapCol color); @@ -167,8 +168,6 @@ struct LTable { struct LTableColumn* columns; /* Number of columns in the table. */ int numColumns; - /* Fonts for text in rows. */ - struct FontDesc* rowFont; /* Y start and end of rows and height of each row. */ int rowsBegY, rowsEndY, rowHeight; /* Y height of headers. */ @@ -205,7 +204,7 @@ struct LTableCell { struct LTable* table; int x, y, width; }; /* Initialises a table. */ /* NOTE: Must also call LTable_Reset to make a table actually useful. */ -void LTable_Init(struct LTable* table, struct FontDesc* rowFont); +void LTable_Init(struct LTable* table); /* Resets state of a table (reset sorter, filter, etc) */ void LTable_Reset(struct LTable* table); /* Adjusts Y position of rows and number of visible rows. */