Change position of text

This commit is contained in:
Nikola Petrov 2025-01-20 02:43:53 +01:00
parent a0756a152f
commit 5342f1b928
3 changed files with 23 additions and 9 deletions

View File

@ -2,4 +2,4 @@
Color ColorAdd(Color c1, Color c2);
Color ColorAddValue(Color c, int add);
Rectangle TextInSpace(Rectangle box, float textH, float textW, float margin);
Rectangle TextInSpace(Rectangle box, float textH, float textW, float margin, bool topOrBottom);

View File

@ -13,14 +13,20 @@
// Dimentions for font size 20
// DISLIKE 83
// LIKE 46
// GEN 9999: 999/999 -> 196
// GEN 9999: 999/999 -> 200
constexpr float textMargin = 0.02f;
void App::init(int screenWidth, int screenHeight)
{
SetTextLineSpacing(0);
this->screenWidth = screenWidth;
this->screenHeight = screenHeight;
this->canvas.init(screenWidth);
// int s = MeasureText("GEN 9999: 999/999", 20);
// TraceLog(LOG_INFO, "%d", s);
for (size_t i = 0; i < canvasTexure.size(); i++)
{
canvasTexure[i] = LoadRenderTexture(screenWidth, screenWidth);
@ -44,15 +50,15 @@ void App::init(int screenWidth, int screenHeight)
likedTextBox = TextInSpace({0,
0,
(float)screenWidth,
(float)screenWidth / 2.0f,
posY},
20.0f, 83.0f, 0.02f);
20.0f, 83.0f, textMargin, false);
genTextBox = TextInSpace({0,
posY + screenWidth,
(float)screenWidth,
posY},
20.0f, 196.0f, 0.02f);
20.0f, 200.0f, textMargin, true);
destB = {0, posY, (float)screenWidth, (float)screenWidth};
destA = destB;

View File

@ -25,7 +25,7 @@ Color ColorAdd(Color c1, Color c2)
return {(unsigned char)r, (unsigned char)g, (unsigned char)b, (unsigned char)a};
}
Rectangle TextInSpace(Rectangle box, float textH, float textW, float margin)
Rectangle TextInSpace(Rectangle box, float textH, float textW, float margin, bool topOrBottom)
{
float br = box.width / box.height;
float tr = textW / textH;
@ -35,9 +35,6 @@ Rectangle TextInSpace(Rectangle box, float textH, float textW, float margin)
float hm = box.height * margin;
float wm = box.width * margin;
ret.y = box.y + hm;
ret.x = box.x + wm;
ret.height = box.height - hm;
ret.width = box.width - wm;
@ -52,5 +49,16 @@ Rectangle TextInSpace(Rectangle box, float textH, float textW, float margin)
ret.width = ret.height * tr;
}
if (topOrBottom)
{
ret.y = box.y + hm;
}
else
{
ret.y = box.y + box.height - hm - ret.height;
}
ret.x = box.x + wm;
return ret;
}