I would like to create a spin box on a modal/modeless dialog in dm-script, which enables users to increase or decrease the number value in the text field by clicking up or down arrow buttons (i.e., spin buttons).
Is there an appropriate way to create such a spin box? It will be appreciated if you share some wisdom. Thank you very much in advance.
There exists no "spin control" for scripted dialogs.
However, you can build a proxy-spin control by creating and arranging according push-buttons. It is a bit crude, but the following code creates this:
Class CMySpin : UIFrame
{
TagGroup CreateDLGTgs( object self )
{
TagGroup DLGtgs, DLGItems
DLGtgs = DLGCreateDialog( "Test", DLGItems )
TagGroup upButton = DLGCreatePushButton( "U", "OnPushUp" ).DLGExternalPadding(0,-5).DLGInternalPadding(-2,-3)
TagGroup downButton = DLGCreatePushButton( "D", "OnPushDown" ).DLGInternalPadding(-2,-3)
TagGroup field = DLGCreateIntegerField( 10, 10 ).DLGIdentifier( "field" )
TagGroup SpinGroup = DLGGroupItems( upButton, downButton ).DLGTableLayout(1,2,0)
TagGroup fieldWithSpin = DLGGroupItems( field, SpinGroup ).DLGTableLayout(2,1,0)
DLGItems.DLGAddElement( fieldWithSpin )
return DLGtgs
}
void OnPushUp( object self )
{
taggroup fieldTG = self.LookupElement( "field" )
number value = fieldTG.DLGGetValue()
value++
fieldTG.DLGValue( value )
}
void OnPushDown( object self )
{
taggroup fieldTG = self.LookupElement( "field" )
number value = fieldTG.DLGGetValue()
value--
fieldTG.DLGValue( value )
}
void CreateAndPose( object self )
{
self.Init( self.CreateDLGTgs() )
self.Pose()
}
}
Alloc(CMySpin).CreateAndPose()
You can then play with looks a bit by using bitmap buttons instead of simple push buttons and setting things up until they look more appealing.
f.e. I created this variant:
With this code:
Class CMySpin : UIFrame
{
TagGroup CreateDLGTgs( object self )
{
image arrowImg := [7,5]:
{ { 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 1, 0, 0, 0 },
{ 0, 0, 1, 1, 1, 0, 0 },
{ 0, 1, 1, 1, 1, 1, 0 },
{ 0, 0, 0, 0, 0, 0, 0 } }
number factor = 2
image upArrow := RealImage("",4,factor*7,factor*5)
upArrow=arrowImg.warp( icol / factor, irow / factor )
image downArrow = upArrow
downArrow.FlipVertical()
rgbImage upArrowUp = RGB( upArrow * 100, upArrow * 100, upArrow * 100 )
rgbImage upArrowDown = RGB( upArrow * 200, upArrow * 200, upArrow * 200 )
rgbImage downArrowUp = RGB( downArrow * 100, downArrow * 100, downArrow * 100 )
rgbImage downArrowDown = RGB( downArrow * 200, downArrow * 200, downArrow * 200 )
TagGroup DLGtgs, DLGItems
DLGtgs = DLGCreateDialog( "Test", DLGItems )
TagGroup upButton = DLGCreateBevelButton( upArrowUp, upArrowDown, "OnPushUp" ).DLGExternalPadding(0,-3).DLGInternalPadding(-2,-3)
TagGroup downButton = DLGCreateBevelButton( downArrowUp, downArrowDown, "OnPushDown" ).DLGExternalPadding(0,-3).DLGInternalPadding(-2,-3)
TagGroup field = DLGCreateIntegerField( 10, 10 ).DLGIdentifier( "field" )
TagGroup SpinGroup = DLGGroupItems( upButton, downButton ).DLGTableLayout(1,2,0)
TagGroup fieldWithSpin = DLGGroupItems( field, SpinGroup ).DLGTableLayout(2,1,0)
DLGItems.DLGAddElement( fieldWithSpin )
return DLGtgs
}
void OnPushUp( object self )
{
taggroup fieldTG = self.LookupElement( "field" )
number value = fieldTG.DLGGetValue()
value++
fieldTG.DLGValue( value )
}
void OnPushDown( object self )
{
taggroup fieldTG = self.LookupElement( "field" )
number value = fieldTG.DLGGetValue()
value--
fieldTG.DLGValue( value )
}
void CreateAndPose( object self )
{
self.Init( self.CreateDLGTgs() )
self.Pose()
}
}
Alloc(CMySpin).CreateAndPose()