diff --git a/src/LBackend.c b/src/LBackend.c index 99d07a38a..75d22f0f5 100644 --- a/src/LBackend.c +++ b/src/LBackend.c @@ -135,6 +135,17 @@ void LBackend_DrawButton(struct LButton* w) { /*########################################################################################################################* *-----------------------------------------------------CheckboxWidget------------------------------------------------------* *#########################################################################################################################*/ +#define CB_SIZE 24 +#define CB_OFFSET 8 + +void LBackend_InitCheckbox(struct LCheckbox* w) { + struct DrawTextArgs args; + DrawTextArgs_Make(&args, &w->text, &Launcher_TextFont, true); + + w->width = Display_ScaleX(CB_SIZE + CB_OFFSET) + Drawer2D_TextWidth(&args); + w->height = Display_ScaleY(CB_SIZE); +} + /* Based off checkbox from original ClassiCube Launcher */ static const cc_uint8 checkbox_indices[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, @@ -210,7 +221,7 @@ void LBackend_DrawCheckbox(struct LCheckbox* w) { } DrawBoxBounds(black, w->x, w->y, width, height); - DrawTextArgs_Make(&args, &w->text, w->font, true); + DrawTextArgs_Make(&args, &w->text, &Launcher_TextFont, true); x = w->x + Display_ScaleX(CB_SIZE + CB_OFFSET); y = w->y + (height - Drawer2D_TextHeight(&args)) / 2; Drawer2D_DrawText(&Launcher_Framebuffer, &args, x, y); @@ -306,6 +317,14 @@ void LBackend_DrawInput(struct LInput* w, const cc_string* text) { /*########################################################################################################################* *------------------------------------------------------LabelWidget--------------------------------------------------------* *#########################################################################################################################*/ +void LBackend_UpdateLabel(struct LLabel* w) { + struct DrawTextArgs args; + DrawTextArgs_Make(&args, &w->text, w->font, true); + + w->width = Drawer2D_TextWidth(&args); + w->height = Drawer2D_TextHeight(&args); +} + void LBackend_DrawLabel(struct LLabel* w) { struct DrawTextArgs args; DrawTextArgs_Make(&args, &w->text, w->font, true); @@ -359,12 +378,13 @@ static void LSlider_DrawBox(struct LSlider* w) { w->width - xBorder2, halfHeight); } +#define LSLIDER_MAXVALUE 100 void LBackend_DrawSlider(struct LSlider* w) { int curWidth; LSlider_DrawBoxBounds(w); LSlider_DrawBox(w); - curWidth = (int)((w->width - xBorder2) * w->value / w->maxValue); + curWidth = (int)((w->width - xBorder2) * w->value / LSLIDER_MAXVALUE); Drawer2D_Clear(&Launcher_Framebuffer, w->color, w->x + xBorder, w->y + yBorder, curWidth, w->height - yBorder2); diff --git a/src/LBackend.h b/src/LBackend.h index 1b918a241..b54378ce8 100644 --- a/src/LBackend.h +++ b/src/LBackend.h @@ -12,14 +12,19 @@ struct LLabel; struct LLine; struct LSlider; -#define CB_SIZE 24 -#define CB_OFFSET 8 - void LBackend_CalcOffsets(void); + void LBackend_DrawButton(struct LButton* w); + +void LBackend_InitCheckbox(struct LCheckbox* w); void LBackend_DrawCheckbox(struct LCheckbox* w); + void LBackend_DrawInput(struct LInput* w, const cc_string* text); + +void LBackend_UpdateLabel(struct LLabel* w); void LBackend_DrawLabel(struct LLabel* w); + void LBackend_DrawLine(struct LLine* w); + void LBackend_DrawSlider(struct LSlider* w); #endif diff --git a/src/LWidgets.c b/src/LWidgets.c index 29cfa925a..fba5f6d1e 100644 --- a/src/LWidgets.c +++ b/src/LWidgets.c @@ -129,17 +129,12 @@ static const struct LWidgetVTABLE lcheckbox_VTABLE = { NULL, NULL /* Select */ }; void LCheckbox_Init(struct LCheckbox* w, const char* text) { - struct DrawTextArgs args; w->VTABLE = &lcheckbox_VTABLE; - w->font = &Launcher_TextFont; w->tabSelectable = true; String_InitArray(w->text, w->_textBuffer); String_AppendConst(&w->text, text); - - DrawTextArgs_Make(&args, &w->text, w->font, true); - w->width = Display_ScaleX(CB_SIZE + CB_OFFSET) + Drawer2D_TextWidth(&args); - w->height = Display_ScaleY(CB_SIZE); + LBackend_InitCheckbox(w); } @@ -481,12 +476,8 @@ void LLabel_Init(struct LLabel* w, const char* text) { } void LLabel_SetText(struct LLabel* w, const cc_string* text) { - struct DrawTextArgs args; String_Copy(&w->text, text); - - DrawTextArgs_Make(&args, &w->text, w->font, true); - w->width = Drawer2D_TextWidth(&args); - w->height = Drawer2D_TextHeight(&args); + LBackend_UpdateLabel(w); LWidget_CalcPosition(w); } @@ -532,11 +523,10 @@ static const struct LWidgetVTABLE lslider_VTABLE = { NULL, NULL /* Select */ }; void LSlider_Init(struct LSlider* w, int width, int height, BitmapCol color) { - w->VTABLE = &lslider_VTABLE; - w->width = Display_ScaleX(width); - w->height = Display_ScaleY(height); - w->maxValue = 100; - w->color = color; + w->VTABLE = &lslider_VTABLE; + w->width = Display_ScaleX(width); + w->height = Display_ScaleY(height); + w->color = color; } diff --git a/src/LWidgets.h b/src/LWidgets.h index 8a5ef8a81..04224d0ca 100644 --- a/src/LWidgets.h +++ b/src/LWidgets.h @@ -61,7 +61,6 @@ CC_NOINLINE void LButton_SetConst(struct LButton* w, const char* text); struct LCheckbox { LWidget_Layout - struct FontDesc* font; cc_bool value; cc_string text; char _textBuffer[STRING_SIZE]; @@ -121,7 +120,7 @@ CC_NOINLINE void LLine_Init(struct LLine* w, int width); /* Represents a slider bar that may or may not be modifiable by the user. */ struct LSlider { LWidget_Layout - int value, maxValue; + int value; BitmapCol color; }; CC_NOINLINE void LSlider_Init(struct LSlider* w, int width, int height, BitmapCol color);