mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-25 09:08:22 -05:00
Added _enabled param for imguiBeginScrollArea().
This commit is contained in:
parent
ef7289c0a6
commit
dde03c6bee
2 changed files with 65 additions and 27 deletions
|
@ -277,6 +277,7 @@ struct Imgui
|
||||||
, m_insideCurrentScroll(false)
|
, m_insideCurrentScroll(false)
|
||||||
, m_areaId(0)
|
, m_areaId(0)
|
||||||
, m_widgetId(0)
|
, m_widgetId(0)
|
||||||
|
, m_enabledAreaIds(0)
|
||||||
, m_scissor(UINT16_MAX)
|
, m_scissor(UINT16_MAX)
|
||||||
, m_scrollTop(0)
|
, m_scrollTop(0)
|
||||||
, m_scrollBottom(0)
|
, m_scrollBottom(0)
|
||||||
|
@ -437,6 +438,16 @@ struct Imgui
|
||||||
&& m_my <= _y + _height;
|
&& m_my <= _y + _height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isEnabled(uint32_t _areaId)
|
||||||
|
{
|
||||||
|
return (m_enabledAreaIds>>_areaId)&0x1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setEnabled(uint32_t _areaId)
|
||||||
|
{
|
||||||
|
m_enabledAreaIds |= (1ULL<<_areaId)&UINT64_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
void clearInput()
|
void clearInput()
|
||||||
{
|
{
|
||||||
m_leftPressed = false;
|
m_leftPressed = false;
|
||||||
|
@ -545,8 +556,9 @@ struct Imgui
|
||||||
m_widgetY = 0;
|
m_widgetY = 0;
|
||||||
m_widgetW = 0;
|
m_widgetW = 0;
|
||||||
|
|
||||||
m_areaId = 1;
|
m_areaId = 0;
|
||||||
m_widgetId = 1;
|
m_widgetId = 0;
|
||||||
|
m_enabledAreaIds = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void endFrame()
|
void endFrame()
|
||||||
|
@ -555,12 +567,17 @@ struct Imgui
|
||||||
nvgEndFrame(m_nvg);
|
nvgEndFrame(m_nvg);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool beginScrollArea(const char* _name, int32_t _x, int32_t _y, int32_t _width, int32_t _height, int32_t* _scroll)
|
bool beginScrollArea(const char* _name, int32_t _x, int32_t _y, int32_t _width, int32_t _height, int32_t* _scroll, bool _enabled)
|
||||||
{
|
{
|
||||||
m_areaId++;
|
m_areaId++;
|
||||||
m_widgetId = 0;
|
m_widgetId = 0;
|
||||||
m_scrollId = (m_areaId << 16) | m_widgetId;
|
m_scrollId = (m_areaId << 16) | m_widgetId;
|
||||||
|
|
||||||
|
if (_enabled)
|
||||||
|
{
|
||||||
|
setEnabled(m_areaId);
|
||||||
|
}
|
||||||
|
|
||||||
m_widgetX = _x + SCROLL_AREA_PADDING;
|
m_widgetX = _x + SCROLL_AREA_PADDING;
|
||||||
m_widgetY = _y + AREA_HEADER + (*_scroll);
|
m_widgetY = _y + AREA_HEADER + (*_scroll);
|
||||||
m_widgetW = _width - SCROLL_AREA_PADDING * 4;
|
m_widgetW = _width - SCROLL_AREA_PADDING * 4;
|
||||||
|
@ -715,7 +732,8 @@ struct Imgui
|
||||||
int32_t height = BUTTON_HEIGHT;
|
int32_t height = BUTTON_HEIGHT;
|
||||||
m_widgetY += BUTTON_HEIGHT + DEFAULT_SPACING;
|
m_widgetY += BUTTON_HEIGHT + DEFAULT_SPACING;
|
||||||
|
|
||||||
bool over = _enabled && inRect(xx, yy, width, height);
|
bool enabled = _enabled && isEnabled(m_areaId);
|
||||||
|
bool over = enabled && inRect(xx, yy, width, height);
|
||||||
bool res = buttonLogic(id, over);
|
bool res = buttonLogic(id, over);
|
||||||
|
|
||||||
drawRoundedRect( (float)xx
|
drawRoundedRect( (float)xx
|
||||||
|
@ -726,7 +744,7 @@ struct Imgui
|
||||||
, imguiRGBA(128, 128, 128, isActive(id) ? 196 : 96)
|
, imguiRGBA(128, 128, 128, isActive(id) ? 196 : 96)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (_enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
drawText(xx + BUTTON_HEIGHT / 2
|
drawText(xx + BUTTON_HEIGHT / 2
|
||||||
, yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2
|
, yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2
|
||||||
|
@ -759,7 +777,8 @@ struct Imgui
|
||||||
int32_t height = BUTTON_HEIGHT;
|
int32_t height = BUTTON_HEIGHT;
|
||||||
m_widgetY += BUTTON_HEIGHT + DEFAULT_SPACING;
|
m_widgetY += BUTTON_HEIGHT + DEFAULT_SPACING;
|
||||||
|
|
||||||
bool over = _enabled && inRect(xx, yy, width, height);
|
bool enabled = _enabled && isEnabled(m_areaId);
|
||||||
|
bool over = enabled && inRect(xx, yy, width, height);
|
||||||
bool res = buttonLogic(id, over);
|
bool res = buttonLogic(id, over);
|
||||||
|
|
||||||
if (isHot(id) )
|
if (isHot(id) )
|
||||||
|
@ -773,7 +792,7 @@ struct Imgui
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
drawText(xx + BUTTON_HEIGHT / 2
|
drawText(xx + BUTTON_HEIGHT / 2
|
||||||
, yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2
|
, yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2
|
||||||
|
@ -806,7 +825,8 @@ struct Imgui
|
||||||
int32_t height = BUTTON_HEIGHT;
|
int32_t height = BUTTON_HEIGHT;
|
||||||
m_widgetY += BUTTON_HEIGHT + DEFAULT_SPACING;
|
m_widgetY += BUTTON_HEIGHT + DEFAULT_SPACING;
|
||||||
|
|
||||||
bool over = _enabled && inRect(xx, yy, width, height);
|
bool enabled = _enabled && isEnabled(m_areaId);
|
||||||
|
bool over = enabled && inRect(xx, yy, width, height);
|
||||||
bool res = buttonLogic(id, over);
|
bool res = buttonLogic(id, over);
|
||||||
|
|
||||||
const int32_t cx = xx + BUTTON_HEIGHT / 2 - CHECK_SIZE / 2;
|
const int32_t cx = xx + BUTTON_HEIGHT / 2 - CHECK_SIZE / 2;
|
||||||
|
@ -821,7 +841,7 @@ struct Imgui
|
||||||
|
|
||||||
if (_checked)
|
if (_checked)
|
||||||
{
|
{
|
||||||
if (_enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
drawRoundedRect( (float)cx
|
drawRoundedRect( (float)cx
|
||||||
, (float)cy
|
, (float)cy
|
||||||
|
@ -843,7 +863,7 @@ struct Imgui
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
drawText(xx + BUTTON_HEIGHT
|
drawText(xx + BUTTON_HEIGHT
|
||||||
, yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2
|
, yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2
|
||||||
|
@ -922,7 +942,8 @@ struct Imgui
|
||||||
const int32_t cx = xx + BUTTON_HEIGHT / 2 - CHECK_SIZE / 2;
|
const int32_t cx = xx + BUTTON_HEIGHT / 2 - CHECK_SIZE / 2;
|
||||||
const int32_t cy = yy + BUTTON_HEIGHT / 2 - CHECK_SIZE / 2;
|
const int32_t cy = yy + BUTTON_HEIGHT / 2 - CHECK_SIZE / 2;
|
||||||
|
|
||||||
bool over = _enabled && inRect(xx, yy, width, height);
|
bool enabled = _enabled && isEnabled(m_areaId);
|
||||||
|
bool over = enabled && inRect(xx, yy, width, height);
|
||||||
bool res = buttonLogic(id, over);
|
bool res = buttonLogic(id, over);
|
||||||
|
|
||||||
if (_checked)
|
if (_checked)
|
||||||
|
@ -946,7 +967,7 @@ struct Imgui
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
drawText(xx + BUTTON_HEIGHT
|
drawText(xx + BUTTON_HEIGHT
|
||||||
, yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2
|
, yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2
|
||||||
|
@ -1034,7 +1055,8 @@ struct Imgui
|
||||||
float uu = bx::fsaturate( (_val - _vmin) / (_vmax - _vmin) );
|
float uu = bx::fsaturate( (_val - _vmin) / (_vmax - _vmin) );
|
||||||
int32_t m = (int)(uu * range);
|
int32_t m = (int)(uu * range);
|
||||||
|
|
||||||
bool over = _enabled && inRect(xx + m, yy, SLIDER_MARKER_WIDTH, SLIDER_HEIGHT);
|
bool enabled = _enabled && isEnabled(m_areaId);
|
||||||
|
bool over = enabled && inRect(xx + m, yy, SLIDER_MARKER_WIDTH, SLIDER_HEIGHT);
|
||||||
bool res = buttonLogic(id, over);
|
bool res = buttonLogic(id, over);
|
||||||
bool valChanged = false;
|
bool valChanged = false;
|
||||||
|
|
||||||
|
@ -1085,7 +1107,7 @@ struct Imgui
|
||||||
char msg[128];
|
char msg[128];
|
||||||
bx::snprintf(msg, 128, fmt, _val);
|
bx::snprintf(msg, 128, fmt, _val);
|
||||||
|
|
||||||
if (_enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
drawText(xx + SLIDER_HEIGHT / 2
|
drawText(xx + SLIDER_HEIGHT / 2
|
||||||
, yy + SLIDER_HEIGHT / 2 + TEXT_HEIGHT / 2
|
, yy + SLIDER_HEIGHT / 2 + TEXT_HEIGHT / 2
|
||||||
|
@ -1141,7 +1163,7 @@ struct Imgui
|
||||||
void separatorLine()
|
void separatorLine()
|
||||||
{
|
{
|
||||||
int32_t xx = m_widgetX;
|
int32_t xx = m_widgetX;
|
||||||
int32_t yy = m_widgetY;
|
int32_t yy = m_widgetY + DEFAULT_SPACING*2;
|
||||||
int32_t width = m_widgetW;
|
int32_t width = m_widgetW;
|
||||||
int32_t height = 1;
|
int32_t height = 1;
|
||||||
m_widgetY += DEFAULT_SPACING * 4;
|
m_widgetY += DEFAULT_SPACING * 4;
|
||||||
|
@ -1667,7 +1689,8 @@ struct Imgui
|
||||||
float hsv[3];
|
float hsv[3];
|
||||||
bx::rgbToHsv(hsv, _rgb);
|
bx::rgbToHsv(hsv, _rgb);
|
||||||
|
|
||||||
if (_enabled)
|
bool enabled = _enabled && isEnabled(m_areaId);
|
||||||
|
if (enabled)
|
||||||
{
|
{
|
||||||
if (m_leftPressed)
|
if (m_leftPressed)
|
||||||
{
|
{
|
||||||
|
@ -1704,7 +1727,7 @@ struct Imgui
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_enabled
|
if (enabled
|
||||||
&& m_left
|
&& m_left
|
||||||
&& isActive(triangleId) )
|
&& isActive(triangleId) )
|
||||||
{
|
{
|
||||||
|
@ -1767,7 +1790,21 @@ struct Imgui
|
||||||
// Draw widget.
|
// Draw widget.
|
||||||
nvgSave(m_nvg);
|
nvgSave(m_nvg);
|
||||||
{
|
{
|
||||||
const float drawSaturation = _enabled ? 1.0f : 0.0f;
|
float saturation;
|
||||||
|
uint8_t alpha0;
|
||||||
|
uint8_t alpha1;
|
||||||
|
if (enabled)
|
||||||
|
{
|
||||||
|
saturation = 1.0f;
|
||||||
|
alpha0 = 255;
|
||||||
|
alpha1 = 192;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
saturation = 0.0f;
|
||||||
|
alpha0 = 10;
|
||||||
|
alpha1 = 10;
|
||||||
|
}
|
||||||
|
|
||||||
// Circle.
|
// Circle.
|
||||||
for (uint8_t ii = 0; ii < 6; ii++)
|
for (uint8_t ii = 0; ii < 6; ii++)
|
||||||
|
@ -1786,8 +1823,8 @@ struct Imgui
|
||||||
NVGpaint paint = nvgLinearGradient(m_nvg
|
NVGpaint paint = nvgLinearGradient(m_nvg
|
||||||
, ax, ay
|
, ax, ay
|
||||||
, bx, by
|
, bx, by
|
||||||
, nvgHSLA(a0/NVG_PI*0.5f,drawSaturation,0.55f,255)
|
, nvgHSLA(a0/NVG_PI*0.5f,saturation,0.55f,alpha0)
|
||||||
, nvgHSLA(a1/NVG_PI*0.5f,drawSaturation,0.55f,255)
|
, nvgHSLA(a1/NVG_PI*0.5f,saturation,0.55f,alpha0)
|
||||||
);
|
);
|
||||||
|
|
||||||
nvgFillPaint(m_nvg, paint);
|
nvgFillPaint(m_nvg, paint);
|
||||||
|
@ -1810,7 +1847,7 @@ struct Imgui
|
||||||
nvgStrokeWidth(m_nvg, 2.0f);
|
nvgStrokeWidth(m_nvg, 2.0f);
|
||||||
nvgBeginPath(m_nvg);
|
nvgBeginPath(m_nvg);
|
||||||
nvgRect(m_nvg, ri-1.0f,-3.0f,rd+2.0f,6.0f);
|
nvgRect(m_nvg, ri-1.0f,-3.0f,rd+2.0f,6.0f);
|
||||||
nvgStrokeColor(m_nvg, nvgRGBA(255,255,255,192) );
|
nvgStrokeColor(m_nvg, nvgRGBA(255,255,255,alpha1) );
|
||||||
nvgStroke(m_nvg);
|
nvgStroke(m_nvg);
|
||||||
|
|
||||||
// Hue selector drop shadow.
|
// Hue selector drop shadow.
|
||||||
|
@ -1832,10 +1869,10 @@ struct Imgui
|
||||||
nvgStroke(m_nvg);
|
nvgStroke(m_nvg);
|
||||||
|
|
||||||
// Center triangle fill.
|
// Center triangle fill.
|
||||||
paint = nvgLinearGradient(m_nvg, aa[0], aa[1], bb[0], bb[1], nvgHSL(hsv[0],drawSaturation,0.5f), nvgRGBA(0,0,0,255) );
|
paint = nvgLinearGradient(m_nvg, aa[0], aa[1], bb[0], bb[1], nvgHSL(hsv[0],saturation,0.5f), nvgRGBA(0,0,0,alpha0) );
|
||||||
nvgFillPaint(m_nvg, paint);
|
nvgFillPaint(m_nvg, paint);
|
||||||
nvgFill(m_nvg);
|
nvgFill(m_nvg);
|
||||||
paint = nvgLinearGradient(m_nvg, (aa[0]+bb[0])*0.5f, (aa[1]+bb[1])*0.5f, cc[0], cc[1], nvgRGBA(0,0,0,0), nvgRGBA(255,255,255,255) );
|
paint = nvgLinearGradient(m_nvg, (aa[0]+bb[0])*0.5f, (aa[1]+bb[1])*0.5f, cc[0], cc[1], nvgRGBA(0,0,0,0), nvgRGBA(255,255,255,alpha0) );
|
||||||
nvgFillPaint(m_nvg, paint);
|
nvgFillPaint(m_nvg, paint);
|
||||||
nvgFill(m_nvg);
|
nvgFill(m_nvg);
|
||||||
|
|
||||||
|
@ -1843,7 +1880,7 @@ struct Imgui
|
||||||
nvgStrokeWidth(m_nvg, 2.0f);
|
nvgStrokeWidth(m_nvg, 2.0f);
|
||||||
nvgBeginPath(m_nvg);
|
nvgBeginPath(m_nvg);
|
||||||
nvgCircle(m_nvg, sel[0], sel[1], 5);
|
nvgCircle(m_nvg, sel[0], sel[1], 5);
|
||||||
nvgStrokeColor(m_nvg, nvgRGBA(255,255,255,192) );
|
nvgStrokeColor(m_nvg, nvgRGBA(255,255,255,alpha1) );
|
||||||
nvgStroke(m_nvg);
|
nvgStroke(m_nvg);
|
||||||
|
|
||||||
// Color selector stroke.
|
// Color selector stroke.
|
||||||
|
@ -1882,6 +1919,7 @@ struct Imgui
|
||||||
|
|
||||||
uint32_t m_areaId;
|
uint32_t m_areaId;
|
||||||
uint32_t m_widgetId;
|
uint32_t m_widgetId;
|
||||||
|
uint64_t m_enabledAreaIds;
|
||||||
uint16_t m_scissor;
|
uint16_t m_scissor;
|
||||||
|
|
||||||
float m_tempCoords[MAX_TEMP_COORDS * 2];
|
float m_tempCoords[MAX_TEMP_COORDS * 2];
|
||||||
|
@ -1945,9 +1983,9 @@ void imguiEndFrame()
|
||||||
s_imgui.endFrame();
|
s_imgui.endFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool imguiBeginScrollArea(const char* _name, int32_t _x, int32_t _y, int32_t _width, int32_t _height, int32_t* _scroll)
|
bool imguiBeginScrollArea(const char* _name, int32_t _x, int32_t _y, int32_t _width, int32_t _height, int32_t* _scroll, bool _enabled)
|
||||||
{
|
{
|
||||||
return s_imgui.beginScrollArea(_name, _x, _y, _width, _height, _scroll);
|
return s_imgui.beginScrollArea(_name, _x, _y, _width, _height, _scroll, _enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
void imguiEndScrollArea()
|
void imguiEndScrollArea()
|
||||||
|
|
|
@ -69,7 +69,7 @@ void imguiDestroy();
|
||||||
void imguiBeginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, uint8_t _view = 31);
|
void imguiBeginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, uint8_t _view = 31);
|
||||||
void imguiEndFrame();
|
void imguiEndFrame();
|
||||||
|
|
||||||
bool imguiBeginScrollArea(const char* _name, int _x, int _y, int _width, int _height, int* _scroll);
|
bool imguiBeginScrollArea(const char* _name, int _x, int _y, int _width, int _height, int* _scroll, bool _enabled = true);
|
||||||
void imguiEndScrollArea();
|
void imguiEndScrollArea();
|
||||||
|
|
||||||
void imguiIndent();
|
void imguiIndent();
|
||||||
|
|
Loading…
Reference in a new issue