mirror of
https://github.com/raysan5/raylib.git
synced 2025-10-21 01:01:50 +00:00
[examples] Added donut pie charts to shapes_pie_chart
(#5277)
* Added donut chart option to pie chart example * Increased example description buffer size * Testing mouse trail building * Removed unused variable --------- Co-authored-by: Gideon Serfontein <gse@newspacesystems.com>
This commit is contained in:
@@ -1,6 +1,3 @@
|
|||||||
#include "raylib.h"
|
|
||||||
#include "raymath.h"
|
|
||||||
|
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shapes] example - Draw a mouse trail (position history)
|
* raylib [shapes] example - Draw a mouse trail (position history)
|
||||||
@@ -18,6 +15,9 @@
|
|||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
#include "raymath.h"
|
||||||
|
|
||||||
// Define the maximum number of positions to store in the trail
|
// Define the maximum number of positions to store in the trail
|
||||||
#define MAX_TRAIL_LENGTH 30
|
#define MAX_TRAIL_LENGTH 30
|
||||||
|
|
||||||
|
@@ -36,6 +36,7 @@ int main(void)
|
|||||||
|
|
||||||
#define MAX_SLICES 10
|
#define MAX_SLICES 10
|
||||||
int sliceCount = 7;
|
int sliceCount = 7;
|
||||||
|
float donutInnerRadius = 25.0f;
|
||||||
float values[MAX_SLICES] = {300.0f, 100.0f, 450.0f, 350.0f, 600.0f, 380.0f, 750.0f}; //initial slice values
|
float values[MAX_SLICES] = {300.0f, 100.0f, 450.0f, 350.0f, 600.0f, 380.0f, 750.0f}; //initial slice values
|
||||||
char labels[MAX_SLICES][32];
|
char labels[MAX_SLICES][32];
|
||||||
bool editingLabel[MAX_SLICES] = {false};
|
bool editingLabel[MAX_SLICES] = {false};
|
||||||
@@ -45,6 +46,7 @@ int main(void)
|
|||||||
|
|
||||||
bool showValues = true;
|
bool showValues = true;
|
||||||
bool showPercentages = false;
|
bool showPercentages = false;
|
||||||
|
bool showDonut = false;
|
||||||
int hoveredSlice = -1;
|
int hoveredSlice = -1;
|
||||||
Rectangle scrollPanelBounds = {0};
|
Rectangle scrollPanelBounds = {0};
|
||||||
Vector2 scrollContentOffset = {0};
|
Vector2 scrollContentOffset = {0};
|
||||||
@@ -159,6 +161,12 @@ int main(void)
|
|||||||
DrawText(labelText, (int)labelPos.x, (int)labelPos.y, 18, WHITE);
|
DrawText(labelText, (int)labelPos.x, (int)labelPos.y, 18, WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(showDonut)
|
||||||
|
{
|
||||||
|
// Draw inner circle to create donut effect
|
||||||
|
DrawCircle(center.x, center.y, donutInnerRadius, RAYWHITE);
|
||||||
|
}
|
||||||
|
|
||||||
startAngle += sweepAngle;
|
startAngle += sweepAngle;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -177,17 +185,29 @@ int main(void)
|
|||||||
currentY += 30;
|
currentY += 30;
|
||||||
|
|
||||||
GuiCheckBox((Rectangle){ panelPos.x + 20, (float)currentY, 20, 20 }, "Show Percentages", &showPercentages);
|
GuiCheckBox((Rectangle){ panelPos.x + 20, (float)currentY, 20, 20 }, "Show Percentages", &showPercentages);
|
||||||
currentY += 40;
|
currentY += 30;
|
||||||
|
|
||||||
|
GuiCheckBox((Rectangle){ panelPos.x + 20, (float)currentY, 20, 20 }, "Make Donut", &showDonut);
|
||||||
|
currentY += 30;
|
||||||
|
|
||||||
|
if(showDonut)
|
||||||
|
{
|
||||||
|
GuiSliderBar((Rectangle){ panelPos.x + 80, (float)currentY, panelRect.width - 100, 30 },
|
||||||
|
"Inner Radius", NULL, &donutInnerRadius, 5.0f, radius - 10.0f);
|
||||||
|
currentY += 40;
|
||||||
|
}
|
||||||
|
|
||||||
GuiLine((Rectangle){ panelPos.x + 10, (float)currentY, panelRect.width - 20, 1 }, NULL);
|
GuiLine((Rectangle){ panelPos.x + 10, (float)currentY, panelRect.width - 20, 1 }, NULL);
|
||||||
currentY += 20;
|
currentY += 20;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Scrollable area for slice editors
|
// Scrollable area for slice editors
|
||||||
scrollPanelBounds = (Rectangle){ panelPos.x+panelMargin, (float)currentY, panelRect.width-panelMargin*2, panelRect.y + panelRect.height - currentY - panelMargin };
|
scrollPanelBounds = (Rectangle){ panelPos.x+panelMargin, (float)currentY, panelRect.width-panelMargin*2, panelRect.y + panelRect.height - currentY - panelMargin };
|
||||||
int contentHeight = sliceCount * 35;
|
int contentHeight = sliceCount * 35;
|
||||||
|
|
||||||
GuiScrollPanel(scrollPanelBounds, NULL,
|
GuiScrollPanel(scrollPanelBounds, NULL,
|
||||||
(Rectangle){ 0, 0, panelRect.width - 20, (float)contentHeight },
|
(Rectangle){ 0, 0, panelRect.width - 25, (float)contentHeight },
|
||||||
&scrollContentOffset, &view);
|
&scrollContentOffset, &view);
|
||||||
|
|
||||||
const float contentX = view.x + scrollContentOffset.x; // left of content
|
const float contentX = view.x + scrollContentOffset.x; // left of content
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 15 KiB |
Reference in New Issue
Block a user