mirror of
https://github.com/raysan5/raygui.git
synced 2026-01-31 11:19:18 -05:00
Some code tweaks
This commit is contained in:
@ -142,7 +142,7 @@ int main()
|
|||||||
if (GuiTextBoxMulti((Rectangle){ 320, 25, 225, 140 }, multiTextBoxText, 141, multiTextBoxEditMode)) multiTextBoxEditMode = !multiTextBoxEditMode;
|
if (GuiTextBoxMulti((Rectangle){ 320, 25, 225, 140 }, multiTextBoxText, 141, multiTextBoxEditMode)) multiTextBoxEditMode = !multiTextBoxEditMode;
|
||||||
colorPickerValue = GuiColorPicker((Rectangle){ 320, 185, 196, 192 }, colorPickerValue);
|
colorPickerValue = GuiColorPicker((Rectangle){ 320, 185, 196, 192 }, colorPickerValue);
|
||||||
|
|
||||||
sliderValue = GuiSliderEx((Rectangle){ 320, 400, 200, 20 }, sliderValue, 0, 100, "SLIDER", true);
|
sliderValue = GuiSliderEx((Rectangle){ 320, 400, 200, 20 }, sliderValue, -50, 100, "SLIDER", true);
|
||||||
sliderBarValue = GuiSliderBarEx((Rectangle){ 320, 430, 200, 20 }, sliderBarValue, 0, 100, "SLIDERBAR", true);
|
sliderBarValue = GuiSliderBarEx((Rectangle){ 320, 430, 200, 20 }, sliderBarValue, 0, 100, "SLIDERBAR", true);
|
||||||
progressValue = GuiProgressBarEx((Rectangle){ 320, 460, 200, 20 }, progressValue, 0, 1, true);
|
progressValue = GuiProgressBarEx((Rectangle){ 320, 460, 200, 20 }, progressValue, 0, 1, true);
|
||||||
|
|
||||||
|
|||||||
35
src/raygui.h
35
src/raygui.h
@ -1845,22 +1845,20 @@ RAYGUIDEF float GuiSliderPro(Rectangle bounds, float value, float minValue, floa
|
|||||||
GuiControlState state = guiState;
|
GuiControlState state = guiState;
|
||||||
|
|
||||||
int textWidth = (text == NULL) ? 0: GuiTextWidth(text);
|
int textWidth = (text == NULL) ? 0: GuiTextWidth(text);
|
||||||
|
int sliderValue = (int)(((value - minValue)/(maxValue - minValue))*(bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH)));
|
||||||
|
|
||||||
Rectangle slider = { 0 };
|
Rectangle slider = { bounds.x, bounds.y + GuiGetStyle(SLIDER, BORDER_WIDTH) + GuiGetStyle(SLIDER, INNER_PADDING),
|
||||||
|
0, bounds.height - 2*GuiGetStyle(SLIDER, BORDER_WIDTH) - 2*GuiGetStyle(SLIDER, INNER_PADDING) };
|
||||||
|
|
||||||
if (sliderWidth > 0) // Slider
|
if (sliderWidth > 0) // Slider
|
||||||
{
|
{
|
||||||
slider = (Rectangle){ bounds.x + (int)((value/(maxValue - minValue))*(bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH))) - GuiGetStyle(SLIDER, SLIDER_WIDTH)/2,
|
slider.x += (sliderValue - sliderWidth/2);
|
||||||
bounds.y + GuiGetStyle(SLIDER, BORDER_WIDTH),
|
slider.width = sliderWidth;
|
||||||
sliderWidth,
|
|
||||||
bounds.height - 2*GuiGetStyle(SLIDER, BORDER_WIDTH) };
|
|
||||||
}
|
}
|
||||||
else if (sliderWidth == 0) // SliderBar
|
else if (sliderWidth == 0) // SliderBar
|
||||||
{
|
{
|
||||||
slider = (Rectangle){ bounds.x + GuiGetStyle(SLIDER, BORDER_WIDTH),
|
slider.x += GuiGetStyle(SLIDER, BORDER_WIDTH);
|
||||||
bounds.y + GuiGetStyle(SLIDER, BORDER_WIDTH) + GuiGetStyle(SLIDER, INNER_PADDING),
|
slider.width = sliderValue;
|
||||||
(int)(((value - minValue)/(maxValue - minValue))*(bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH))),
|
|
||||||
bounds.height - 2*GuiGetStyle(SLIDER, BORDER_WIDTH) - 2*GuiGetStyle(SLIDER, INNER_PADDING) };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update control
|
// Update control
|
||||||
@ -1876,16 +1874,10 @@ RAYGUIDEF float GuiSliderPro(Rectangle bounds, float value, float minValue, floa
|
|||||||
state = GUI_STATE_PRESSED;
|
state = GUI_STATE_PRESSED;
|
||||||
|
|
||||||
// Get equivalent value and slider position from mousePoint.x
|
// Get equivalent value and slider position from mousePoint.x
|
||||||
if (sliderWidth > 0) // Slider
|
value = ((maxValue - minValue)*(mousePoint.x - (float)(bounds.x + sliderWidth/2)))/(float)(bounds.width - sliderWidth) + minValue;
|
||||||
{
|
|
||||||
value = ((maxValue - minValue)*(mousePoint.x - (float)(bounds.x + slider.width/2)))/(float)(bounds.width - slider.width) + minValue;
|
if (sliderWidth > 0) slider.x = mousePoint.x - slider.width/2; // Slider
|
||||||
slider.x = mousePoint.x - slider.width/2;
|
else if (sliderWidth == 0) slider.width = sliderValue; // SliderBar
|
||||||
}
|
|
||||||
else if (sliderWidth == 0) // SliderBar
|
|
||||||
{
|
|
||||||
value = (maxValue - minValue)*((mousePoint.x - (float)bounds.x)/(float)bounds.width) + minValue;
|
|
||||||
slider.width = (int)(((value - minValue)/(maxValue - minValue))*(bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else state = GUI_STATE_FOCUSED;
|
else state = GUI_STATE_FOCUSED;
|
||||||
}
|
}
|
||||||
@ -1893,10 +1885,11 @@ RAYGUIDEF float GuiSliderPro(Rectangle bounds, float value, float minValue, floa
|
|||||||
if (value > maxValue) value = maxValue;
|
if (value > maxValue) value = maxValue;
|
||||||
else if (value < minValue) value = minValue;
|
else if (value < minValue) value = minValue;
|
||||||
|
|
||||||
|
// Bar limits check
|
||||||
if (sliderWidth > 0) // Slider
|
if (sliderWidth > 0) // Slider
|
||||||
{
|
{
|
||||||
if (slider.x <= bounds.x + GuiGetStyle(SLIDER, BORDER_WIDTH)) slider.x = bounds.x + GuiGetStyle(SLIDER, BORDER_WIDTH);
|
if (slider.x <= (bounds.x + GuiGetStyle(SLIDER, BORDER_WIDTH))) slider.x = bounds.x + GuiGetStyle(SLIDER, BORDER_WIDTH);
|
||||||
else if (slider.x + slider.width >= bounds.x + bounds.width) slider.x = bounds.x + bounds.width - slider.width - GuiGetStyle(SLIDER, BORDER_WIDTH);
|
else if ((slider.x + slider.width) >= (bounds.x + bounds.width)) slider.x = bounds.x + bounds.width - slider.width - GuiGetStyle(SLIDER, BORDER_WIDTH);
|
||||||
}
|
}
|
||||||
else if (sliderWidth == 0) // SliderBar
|
else if (sliderWidth == 0) // SliderBar
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user