2

all: I found that there are two method to align the widgets, DLGAnchor and DLGAlign. It seems the function of these two are the same. Could anyone give an example about the usage difference?

Regards

Chen ZX

BmyGuest
  • 6,331
  • 1
  • 21
  • 35
ChenZX
  • 293
  • 4
  • `DLGAnchor` is in the [Listing of most DM Script Commands](http://www.dmscripting.com/files/DM_Script_and_Dialog_Functions.pdf), by `DLGAlign` is not. Cahn you share more info on your question ? – Luuk Aug 20 '23 at 09:13
  • For radio list, I always used DLGAnchor. But for label, I always used DLGSide. But I tried to exchange these two methods, it seems ok. – ChenZX Aug 20 '23 at 11:10
  • @Luuk Actually, both are in the F1 documentation of GMS 3.5, but with little detail in explanation. Both set property values in the TagGroup which are used by different elements. See my answer. – BmyGuest Aug 21 '23 at 07:45

1 Answers1

3

Different dialog arrangement command utilizes different property values. (All dialog building is just a compilation of a descriptor TagGroup that then gets translated into a dialog.)

The anchor property is used for the Table Layout, as in the following example:

class UITest : UIFrame
{
 object ShowTest(object self, number variant)
 {
    TagGroup DLG,DLGItems
    DLG = DLGCreateDialog("VariantTest",DLGitems)
    for(number i=0;i<25;i++)
    {
        number col = (i%5)
        number row = trunc(i/5)
        TagGroup item = DLGCreatePushButton("#"+i,"")
        number width =  (0==row%2) ? 5+col*12 : 65-col*12 
        number height =  (1==row%3) ? 35-col*6 : 5+col*6*row
        item.DLGInternalPadding(width,height)
        //item.DLGExternalPadding(5,5)
        DLGItems.DLGAddElement( item )
    }
        
    if (0==Variant)
    {
        DLG.DLGTableLayout(5,5,0)
    }
    else if (1==Variant)
    {
        DLG.DLGTableLayout(5,5,1)   // All item tiles are same size in grid
    }
    else if (2==Variant)
    {
        DLG.DLGTableLayout(5,5,0)
        taggroup item
        // 2nd row gets "South" attribute to align bottom       
        for (number i=5;i<10;i++){
            if (DLGItems.TagGroupGetIndexedTagAsTagGroup(i,item))
                item.DLGAnchor("South")
        }
        // 3nd row gets "North" attribute to align top
        for (number i=10;i<15;i++){
            if (DLGItems.TagGroupGetIndexedTagAsTagGroup(i,item))
                item.DLGAnchor("North")
        }   
    }
    else if (3==Variant)
    {
        DLG.DLGTableLayout(5,5,0)
        taggroup item
        // 3rd colum gets "East" attribute to align left
        for (number i=2;i<25;i+=5){
            if (DLGItems.TagGroupGetIndexedTagAsTagGroup(i,item))
                item.DLGAnchor("East")
        }
        // 4th colum gets "West" attribute to align right
        for (number i=3;i<25;i+=5){
            if (DLGItems.TagGroupGetIndexedTagAsTagGroup(i,item))
                item.DLGAnchor("West")
        }
    }
    self.Init(DLG).Display("Test "+variant)
    return self
 }
}

Alloc(UITest).ShowTest(0)
Alloc(UITest).ShowTest(1)
Alloc(UITest).ShowTest(2)
Alloc(UITest).ShowTest(3)

The side property is used for arranging radio elements:

class UITest : UIFrame
{
    object ShowTest(object self)
    {
        TagGroup DLG,DLGItems
        DLG = DLGCreateDialog("VariantTest",DLGitems)
        
        
        TagGroup Radio1,RadioItems1
        Radio1 = DLGCreateRadioList(RadioItems1,1)
        Radio1.DLGExternalPadding(0,20)
        DLGItems.DLGAddElement(Radio1)
        
        // Left-to-Right arrangement
        For (Number i=1;i<=5;i++)   
            Radio1.DLGAddRadioItem("radio 1/"+i,10*i).DLGSide("Left")
        
        TagGroup Radio2,RadioItems2
        Radio2 = DLGCreateRadioList(RadioItems2,1)
        Radio2.DLGExternalPadding(0,20)
        DLGItems.DLGAddElement(Radio2)
        
        // Right-To-Left arrangement
        For (Number i=1;i<=5;i++)   
            Radio2.DLGAddRadioItem("radio 2/"+i,10*i).DLGSide("Right")
            
        TagGroup Radio3,RadioItems3
        Radio3 = DLGCreateRadioList(RadioItems3,1)
        Radio3.DLGExternalPadding(0,20)
        DLGItems.DLGAddElement(Radio3)
        
        // Top-to-Bottom arrangement
        For (Number i=1;i<=5;i++)   
            Radio3.DLGAddRadioItem("radio 3/"+i,10*i).DLGSide("Top")
        
        TagGroup Radio4,RadioItems4
        Radio4 = DLGCreateRadioList(RadioItems4,1)
        Radio4.DLGExternalPadding(0,20)
        DLGItems.DLGAddElement(Radio4)
        
        // Bottom-to-Top arrangement
        For (Number i=1;i<=5;i++)   
            Radio4.DLGAddRadioItem("radio 4/"+i,10*i).DLGSide("Bottom")
        
        
        self.Init(DLG).Display("Test")
        return self
    }
}
Alloc(UITest).ShowTest()
BmyGuest
  • 6,331
  • 1
  • 21
  • 35