VectorFieldsΒΆ
FloatField, IntField, and CheckBox have their Vector form as well. They are named VectorFloatField
,
VectorIntField
, VectorBooleanField
respectively.
These classes simply create 3 instances of their regular fields.
Following is the code to create all three of VectorFields:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | from boss.ui_creator import UICreator,Boss_OT_base_ui,RectData
def onTextChanged(caller):
print(type(caller).__name__, f'value - {caller.value}, text - {caller.text}')
def onValueChanged(caller):
print(type(caller).__name__, f'value - {caller.value}, text - {caller.text}')
def onEnterPressed(caller):
print(type(caller).__name__, f'value - {caller.value}, text - {caller.text}')
def ui_elements(op: Boss_OT_base_ui):
# UICreator.deleteAllUi(op) # to delete all existing ui
btn_width, btn_height = 150, 40
space = 10
rd = RectData(
op.uip.mouse_x,
op.uip.mouse_y - btn_height,
btn_width,
btn_height
)
vbf = UICreator.vectorBooleanField(
op,
rectData=rd,
value=(True, False, True),
onValueChange=onValueChanged,
param='This can be any python object'
)
# can also be used
# vbf.add_onValueChange(onValueChanged)
rd = rd.getBottom(space)
vff = UICreator.vectorFloatField(
op,
rectData=rd,
value=(0.0, 0.0, 0.0),
onValueChange=onValueChanged,
onTextChange=onTextChanged,
onEnterPress=onEnterPressed,
param='This can be any python object'
)
# can also be used
# vff.add_onTextChange(onTextChanged)
# vff.add_onValueChange(onValueChanged)
# vff.add_onEnterPress(onEnterPressed)
rd = rd.getBottom(space)
vif = UICreator.vectorIntField(
op,
rectData=rd,
value=(0, 0, 0),
# can also be used
# onValueChange=onValueChanged,
# onTextChange=onTextChanged,
# onEnterPress=onEnterPressed,
param='This can be any python object'
)
vif.add_onTextChange(onTextChanged)
vif.add_onValueChange(onValueChanged)
vif.add_onEnterPress(onEnterPressed)
|
These are presented together, since they all inherit from same class
_VectorField
internally.You can see they have similar events to their one value counterpart, i.e.
onValueChanged
,onTextChange
andonEnterPress
.Since Checkbox is just a Button, it only has
onValueChange
. Because of that,onTextChange
andonEnterPress
will raise exception, but these methods are still available(since it inherit from same class_VectorField
).