mirror of
https://github.com/raysan5/raygui.git
synced 2025-12-25 10:22:33 -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;
|
||||
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);
|
||||
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;
|
||||
|
||||
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
|
||||
{
|
||||
slider = (Rectangle){ bounds.x + (int)((value/(maxValue - minValue))*(bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH))) - GuiGetStyle(SLIDER, SLIDER_WIDTH)/2,
|
||||
bounds.y + GuiGetStyle(SLIDER, BORDER_WIDTH),
|
||||
sliderWidth,
|
||||
bounds.height - 2*GuiGetStyle(SLIDER, BORDER_WIDTH) };
|
||||
slider.x += (sliderValue - sliderWidth/2);
|
||||
slider.width = sliderWidth;
|
||||
}
|
||||
else if (sliderWidth == 0) // SliderBar
|
||||
{
|
||||
slider = (Rectangle){ bounds.x + GuiGetStyle(SLIDER, BORDER_WIDTH),
|
||||
bounds.y + GuiGetStyle(SLIDER, BORDER_WIDTH) + GuiGetStyle(SLIDER, INNER_PADDING),
|
||||
(int)(((value - minValue)/(maxValue - minValue))*(bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH))),
|
||||
bounds.height - 2*GuiGetStyle(SLIDER, BORDER_WIDTH) - 2*GuiGetStyle(SLIDER, INNER_PADDING) };
|
||||
slider.x += GuiGetStyle(SLIDER, BORDER_WIDTH);
|
||||
slider.width = sliderValue;
|
||||
}
|
||||
|
||||
// Update control
|
||||
@ -1876,16 +1874,10 @@ RAYGUIDEF float GuiSliderPro(Rectangle bounds, float value, float minValue, floa
|
||||
state = GUI_STATE_PRESSED;
|
||||
|
||||
// Get equivalent value and slider position from mousePoint.x
|
||||
if (sliderWidth > 0) // Slider
|
||||
{
|
||||
value = ((maxValue - minValue)*(mousePoint.x - (float)(bounds.x + slider.width/2)))/(float)(bounds.width - slider.width) + minValue;
|
||||
slider.x = mousePoint.x - slider.width/2;
|
||||
}
|
||||
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)));
|
||||
}
|
||||
value = ((maxValue - minValue)*(mousePoint.x - (float)(bounds.x + sliderWidth/2)))/(float)(bounds.width - sliderWidth) + minValue;
|
||||
|
||||
if (sliderWidth > 0) slider.x = mousePoint.x - slider.width/2; // Slider
|
||||
else if (sliderWidth == 0) slider.width = sliderValue; // SliderBar
|
||||
}
|
||||
else state = GUI_STATE_FOCUSED;
|
||||
}
|
||||
@ -1893,10 +1885,11 @@ RAYGUIDEF float GuiSliderPro(Rectangle bounds, float value, float minValue, floa
|
||||
if (value > maxValue) value = maxValue;
|
||||
else if (value < minValue) value = minValue;
|
||||
|
||||
// Bar limits check
|
||||
if (sliderWidth > 0) // Slider
|
||||
{
|
||||
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);
|
||||
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 (sliderWidth == 0) // SliderBar
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user