Consider tabs out of screen bounds

Avoid drawing tabs out of screen
This commit is contained in:
Ray
2022-11-22 17:09:11 +01:00
parent bd4d2d860c
commit 85d6736be9

View File

@ -1495,12 +1495,19 @@ int GuiTabBar(Rectangle bounds, const char **text, int count, int *active)
if (*active < 0) *active = 0;
else if (*active > count - 1) *active = count - 1;
int offsetX = 0; // Required in case tabs go out of screen
offsetX = (*active + 2)*RAYGUI_TABBAR_ITEM_WIDTH - GetScreenWidth();
if (offsetX < 0) offsetX = 0;
// Draw control
//--------------------------------------------------------------------
for (int i = 0; i < count; i++)
{
tabBounds.x = bounds.x + (RAYGUI_TABBAR_ITEM_WIDTH + 4)*i;
tabBounds.x = bounds.x + (RAYGUI_TABBAR_ITEM_WIDTH + 4)*i - offsetX;
if (tabBounds.x < GetScreenWidth())
{
// Draw tabs as toggle controls
int textAlignment = GuiGetStyle(TOGGLE, TEXT_ALIGNMENT);
int textPadding = GuiGetStyle(TOGGLE, TEXT_PADDING);
GuiSetStyle(TOGGLE, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
@ -1524,6 +1531,7 @@ int GuiTabBar(Rectangle bounds, const char **text, int count, int *active)
GuiSetStyle(BUTTON, BORDER_WIDTH, tempBorderWidth);
GuiSetStyle(BUTTON, TEXT_ALIGNMENT, tempTextAlignment);
}
}
GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x, bounds.y + bounds.height - 1, bounds.width, 1 }, 0, BLANK, GetColor(GuiGetStyle(TOGGLE, BORDER_COLOR_NORMAL)));
//GuiLine(RAYGUI_CLITERAL(Rectangle){ bounds.x, bounds.y + bounds.height - 1, bounds.width, 1 }, NULL);