mirror of
https://github.com/raysan5/raygui.git
synced 2026-02-06 14:19:19 -05:00
Consider tabs out of screen bounds
Avoid drawing tabs out of screen
This commit is contained in:
10
src/raygui.h
10
src/raygui.h
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user