GMS3.2/3.xx版本DLGCreateDialog复选框标签截断问题求助
问题:GMS 3.2.xx/3.5.xx中复选框标签被截断(仅显示前几个字符)
我在GMS 3.2.xx和3.5.xx版本中运行如下DLGCreateDialog示例代码:
TagGroup DLG, DLGItems DLG = DLGCreateDialog( "Please enter strings", DLGItems ) TagGroup opt1tg = DLGCreateCheckBox( "Option 1", 0) TagGroup opt2tg = DLGCreateCheckBox( "Option 2", 1) TagGroup opt3tg = DLGCreateCheckBox( "Option 3", 1) DLGitems.DLGAddElement( opt1tg ) DLGitems.DLGAddElement( opt2tg ) DLGitems.DLGAddElement( opt3tg ) if ( !Alloc( UIframe ).Init( DLG ).Pose() ) Throw( "User abort." ) Result( "Option 1: " + opt1tg.DLGGetValue() + "\n" ) Result( "Option 2: " + opt2tg.DLGGetValue() + "\n" ) Result( "Option 3: " + ( opt3tg.DLGGetValue() ? "enabled" : "disabled" ) + "\n" )
该代码在旧版GMS 2.3.xxx中可正常显示完整标签,但在3.2/3.5版本中,复选框标签仅显示前几个字符(如“Optio...”),问题截图如下:
[复选框标签被截断的问题截图]
原因分析
GMS 3.x系列对DLG控件的默认布局逻辑做了调整,默认情况下复选框控件的宽度被限制为固定的较小值,无法自动适配标签文本长度,导致较长的标签被截断。
解决方法
方法1:显式设置复选框控件的宽度
使用DLGSetAttribute为每个复选框设置足够容纳文本的宽度值(单位为像素):
TagGroup DLG, DLGItems DLG = DLGCreateDialog( "Please enter strings", DLGItems ) TagGroup opt1tg = DLGCreateCheckBox( "Option 1", 0) opt1tg.DLGSetAttribute( "width", 120 ) // 设置宽度适配文本 TagGroup opt2tg = DLGCreateCheckBox( "Option 2", 1) opt2tg.DLGSetAttribute( "width", 120 ) TagGroup opt3tg = DLGCreateCheckBox( "Option 3", 1) opt3tg.DLGSetAttribute( "width", 120 ) DLGitems.DLGAddElement( opt1tg ) DLGitems.DLGAddElement( opt2tg ) DLGitems.DLGAddElement( opt3tg ) if ( !Alloc( UIframe ).Init( DLG ).Pose() ) Throw( "User abort." ) Result( "Option 1: " + opt1tg.DLGGetValue() + "\n" ) Result( "Option 2: " + opt2tg.DLGGetValue() + "\n" ) Result( "Option 3: " + ( opt3tg.DLGGetValue() ? "enabled" : "disabled" ) + "\n" )
方法2:使用布局容器自动适配宽度
将复选框放入DLGCreateGroup布局容器中,让容器自动根据内容调整控件宽度:
TagGroup DLG, DLGItems DLG = DLGCreateDialog( "Please enter strings", DLGItems ) // 创建布局组承载复选框 TagGroup checkGroup = DLGCreateGroup() TagGroup opt1tg = DLGCreateCheckBox( "Option 1", 0) TagGroup opt2tg = DLGCreateCheckBox( "Option 2", 1) TagGroup opt3tg = DLGCreateCheckBox( "Option 3", 1) checkGroup.DLGAddElement( opt1tg ) checkGroup.DLGAddElement( opt2tg ) checkGroup.DLGAddElement( opt3tg ) DLGitems.DLGAddElement( checkGroup ) if ( !Alloc( UIframe ).Init( DLG ).Pose() ) Throw( "User abort." ) Result( "Option 1: " + opt1tg.DLGGetValue() + "\n" ) Result( "Option 2: " + opt2tg.DLGGetValue() + "\n" ) Result( "Option 3: " + ( opt3tg.DLGGetValue() ? "enabled" : "disabled" ) + "\n" )
补充说明
如果需要更灵活的布局控制,还可以结合DLGSetFixedWidth(false)让控件自动适应文本长度,或者使用DLGAddElement的布局参数(如DLG_ALIGN_LEFT)优化显示效果。
内容的提问来源于stack exchange,提问作者Yuan Yao
相关产品推荐
相关产品推荐

