Added function GuiLabelButton()
Also reviewed GuiLabel() to show simple label
This commit is contained in:
parent
4987d385c9
commit
2a371ade58
67
src/raygui.h
67
src/raygui.h
@ -289,8 +289,9 @@ RAYGUIDEF Color GuiBackgroundColor(void); // Get b
|
|||||||
RAYGUIDEF Color GuiLinesColor(void); // Get lines color
|
RAYGUIDEF Color GuiLinesColor(void); // Get lines color
|
||||||
RAYGUIDEF Color GuiTextColor(void); // Get text color for normal state
|
RAYGUIDEF Color GuiTextColor(void); // Get text color for normal state
|
||||||
|
|
||||||
RAYGUIDEF void GuiLabel(Rectangle bounds, const char *text); // Label control, show text
|
RAYGUIDEF void GuiLabel(Rectangle bounds, const char *text); // Label control, shows text
|
||||||
RAYGUIDEF bool GuiButton(Rectangle bounds, const char *text); // Button control, returns true when clicked
|
RAYGUIDEF bool GuiButton(Rectangle bounds, const char *text); // Button control, returns true when clicked
|
||||||
|
RAYGUIDEF bool GuiLabelButton(Rectangle bounds, const char *text); // Label button control, show true when clicked
|
||||||
RAYGUIDEF bool GuiImageButton(Rectangle bounds, Texture2D texture); // Image button control, returns true when clicked
|
RAYGUIDEF bool GuiImageButton(Rectangle bounds, Texture2D texture); // Image button control, returns true when clicked
|
||||||
RAYGUIDEF bool GuiToggleButton(Rectangle bounds, const char *text, bool toggle); // Toggle Button control, returns true when active
|
RAYGUIDEF bool GuiToggleButton(Rectangle bounds, const char *text, bool toggle); // Toggle Button control, returns true when active
|
||||||
RAYGUIDEF int GuiToggleGroup(Rectangle bounds, char **text, int count, int active); // Toggle Group control, returns toggled button index
|
RAYGUIDEF int GuiToggleGroup(Rectangle bounds, char **text, int count, int active); // Toggle Group control, returns toggled button index
|
||||||
@ -586,7 +587,7 @@ RAYGUIDEF Color GuiTextColor(void) { return GetColor(styleGeneric[DEFAULT_TEXT_C
|
|||||||
RAYGUIDEF void GuiLabel(Rectangle bounds, const char *text)
|
RAYGUIDEF void GuiLabel(Rectangle bounds, const char *text)
|
||||||
{
|
{
|
||||||
GuiControlState state = guiState;
|
GuiControlState state = guiState;
|
||||||
|
|
||||||
int textWidth = MeasureText(text, styleGeneric[DEFAULT_TEXT_SIZE]);
|
int textWidth = MeasureText(text, styleGeneric[DEFAULT_TEXT_SIZE]);
|
||||||
int textHeight = styleGeneric[DEFAULT_TEXT_SIZE];
|
int textHeight = styleGeneric[DEFAULT_TEXT_SIZE];
|
||||||
|
|
||||||
@ -595,27 +596,17 @@ RAYGUIDEF void GuiLabel(Rectangle bounds, const char *text)
|
|||||||
|
|
||||||
// Update control
|
// Update control
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
if (state != DISABLED)
|
// ...
|
||||||
{
|
|
||||||
Vector2 mousePoint = GetMousePosition();
|
|
||||||
|
|
||||||
// Check label state
|
|
||||||
if (CheckCollisionPointRec(mousePoint, bounds))
|
|
||||||
{
|
|
||||||
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = PRESSED;
|
|
||||||
else state = FOCUSED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw control
|
// Draw control
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case NORMAL: DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(style[LABEL_TEXT_COLOR_NORMAL])); break;
|
case NORMAL:
|
||||||
case FOCUSED: DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(style[LABEL_TEXT_COLOR_FOCUSED])); break;
|
case FOCUSED:
|
||||||
case PRESSED: DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(style[LABEL_TEXT_COLOR_PRESSED])); break;
|
case PRESSED: DrawText(text, bounds.x, bounds.y, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(style[LABEL_TEXT_COLOR_NORMAL])); break;
|
||||||
case DISABLED: DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(styleGeneric[DEFAULT_TEXT_COLOR_DISABLED])); break;
|
case DISABLED: DrawText(text, bounds.x, bounds.y, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(styleGeneric[DEFAULT_TEXT_COLOR_DISABLED])); break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
@ -684,6 +675,48 @@ RAYGUIDEF bool GuiButton(Rectangle bounds, const char *text)
|
|||||||
return clicked;
|
return clicked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Label button control
|
||||||
|
RAYGUIDEF bool GuiLabelButton(Rectangle bounds, const char *text)
|
||||||
|
{
|
||||||
|
GuiControlState state = guiState;
|
||||||
|
bool clicked = false;
|
||||||
|
|
||||||
|
int textWidth = MeasureText(text, styleGeneric[DEFAULT_TEXT_SIZE]);
|
||||||
|
int textHeight = styleGeneric[DEFAULT_TEXT_SIZE];
|
||||||
|
|
||||||
|
if (bounds.width < textWidth) bounds.width = textWidth;
|
||||||
|
if (bounds.height < textHeight) bounds.height = textHeight;
|
||||||
|
|
||||||
|
// Update control
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
if (state != DISABLED)
|
||||||
|
{
|
||||||
|
Vector2 mousePoint = GetMousePosition();
|
||||||
|
|
||||||
|
// Check label state
|
||||||
|
if (CheckCollisionPointRec(mousePoint, bounds))
|
||||||
|
{
|
||||||
|
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = PRESSED;
|
||||||
|
else state = FOCUSED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw control
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
switch (state)
|
||||||
|
{
|
||||||
|
case NORMAL: DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(style[LABEL_TEXT_COLOR_NORMAL])); break;
|
||||||
|
case FOCUSED: DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(style[LABEL_TEXT_COLOR_FOCUSED])); break;
|
||||||
|
case PRESSED: DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(style[LABEL_TEXT_COLOR_PRESSED])); break;
|
||||||
|
case DISABLED: DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, styleGeneric[DEFAULT_TEXT_SIZE], GetColor(styleGeneric[DEFAULT_TEXT_COLOR_DISABLED])); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
|
return clicked;
|
||||||
|
}
|
||||||
|
|
||||||
// Image button control, returns true when clicked
|
// Image button control, returns true when clicked
|
||||||
// TODO: Just provide textureId instead of full Texture2D
|
// TODO: Just provide textureId instead of full Texture2D
|
||||||
RAYGUIDEF bool GuiImageButton(Rectangle bounds, Texture2D texture)
|
RAYGUIDEF bool GuiImageButton(Rectangle bounds, Texture2D texture)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user