Many improvements.
This commit is contained in:
26
third-party/mexui/Core/Control/CheckBox.js
vendored
26
third-party/mexui/Core/Control/CheckBox.js
vendored
@@ -19,11 +19,22 @@ mexui.util.linkBaseControlStyles('CheckBox', {
|
||||
// input
|
||||
mexui.Control.CheckBox.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.isCursorOverControl())
|
||||
if(e.button == 0 && this.isCursorOverControl())
|
||||
{
|
||||
e.used = true;
|
||||
this.checked = !this.checked;
|
||||
this.checkToCallCallback();
|
||||
this.toggleChecked();
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Control.CheckBox.prototype.onKeyDown = function(e, key, mods)
|
||||
{
|
||||
if(this.isFocused())
|
||||
{
|
||||
if(key == SDLK_RETURN || key == SDLK_RETURN2 || key == SDLK_KP_ENTER || key == SDLK_SPACE)
|
||||
{
|
||||
e.used = true;
|
||||
this.toggleChecked();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -38,6 +49,9 @@ mexui.Control.CheckBox.prototype.render = function()
|
||||
mexui.native.drawRectangle(mexui.util.addVec2(pos, new Vec2(1, 1)), new Vec2(this.size.x - 2, this.size.y - 2), this.getStyles('innerBox'));
|
||||
|
||||
mexui.native.drawText(mexui.util.addVec2(pos, new Vec2(this.size.x + this.textMarginLeft, 2)), this.size, this.text, this.getStyles('main'));
|
||||
|
||||
if(this.isFocused())
|
||||
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
|
||||
};
|
||||
|
||||
// model
|
||||
@@ -45,4 +59,10 @@ mexui.Control.CheckBox.prototype.getSizeForInput = function()
|
||||
{
|
||||
var textWidth = mexui.native.getTextWidth(this.text, this.getStyles('main'));
|
||||
return new Vec2(this.size.x + this.textMarginLeft + textWidth, this.size.y);
|
||||
};
|
||||
|
||||
mexui.Control.CheckBox.prototype.toggleChecked = function()
|
||||
{
|
||||
this.checked = !this.checked;
|
||||
this.checkToCallCallback();
|
||||
};
|
||||
Reference in New Issue
Block a user