Castillo Posted January 1, 2013 Posted January 1, 2013 Today I encountered a problem while using scrollpanes, in the first image you'll see that everything is fine, but in the second you'll notice of a huge space between group 1 and 2. Image 1: http://imgur.com/KMFdC Image 2: http://imgur.com/Pzlu6 My code: testGroups = { { name = "Test", contacts = { { name = "Test 1", state = "online" }, { name = "Test 2", state = "offline" }, { name = "Test 3", state = "online" }, } }, { name = "Test 2", contacts = { { name = "Test 1", state = "online" }, { name = "Test 2", state = "offline" }, { name = "Test 3", state = "online" }, { name = "Test 4", state = "online" }, { name = "Test 5", state = "online" }, { name = "Test 6", state = "online" }, } } } for index, group in ipairs ( testGroups ) do local groupY = ( #group.contacts * 0.13 ) local groupY = ( index == 1 and 0.02 or groupY ) friendsList [ "main" ] [ "contacts_group_".. group.name ] = guiCreateLabel(0.00, groupY, 0.98, 0.06, group.name ..":", true, friendsList [ "main" ] [ "contacts_scrollPane" ]) for index, contact in ipairs ( group.contacts ) do friendsList [ "main" ] [ "contacts_contact_state_".. contact.name ] = guiCreateStaticImage(0.03, ( groupY + 0.10 * index ), 0.05, 0.06, "images/".. contact.state ..".png", true, friendsList [ "main" ] [ "contacts_scrollPane" ]) friendsList [ "main" ] [ "contacts_contact_label_".. contact.name ] = guiCreateLabel(0.10, ( groupY + 0.10 * index ), 0.90, 0.06, contact.name, true, friendsList [ "main" ] [ "contacts_scrollPane" ]) end end I don't know if there's a way to fix this, that's why I'm making this topic. P.S: IF YOU DON'T KNOW WHAT IS THIS ABOUT, DON'T EVEN REPLY.
Cadu12 Posted January 2, 2013 Posted January 2, 2013 I dont see any wrong, may be problem with math. What do you use font scale? You can try use dxGetFontHeight or guiGetSize.
Castillo Posted January 2, 2013 Author Posted January 2, 2013 Maths aren't wrong, they work in the first image, scroll panes are bugged I think.
Cadu12 Posted January 2, 2013 Posted January 2, 2013 addEventHandler("onClientRender", getRootElement(), function() local groupY = 0 for index, group in ipairs ( testGroups ) do dxDrawText(group.name, 0, groupY, tocolor(255, 255, 255, 255), 1, Font, "left") for index, contact in ipairs ( group.contacts ) do dxDrawText(contact.name, 10, (index * dxGetFontHeight(1, Font)) + groupY, tocolor(0, 255, 0, 255), 1, Font, "left") --friendsList [ "main" ] [ "contacts_contact_state_".. contact.name ] = guiCreateStaticImage(0.03, ( groupY + 0.10 * index ), 0.05, 0.06, "images/".. contact.state ..".png", true, friendsList [ "main" ] [ "contacts_scrollPane" ]) --friendsList [ "main" ] [ "contacts_contact_label_".. contact.name ] = guiCreateLabel(0.10, ( groupY + 0.10 * index ), 0.90, 0.06, contact.name, true, friendsList [ "main" ] [ "contacts_scrollPane" ]) end groupY = ((#group.contacts + 1) * dxGetFontHeight(1, Font)) + groupY end end) You can edit it, it was problem math, I told you.
Cadu12 Posted January 2, 2013 Posted January 2, 2013 I can't test it becuase GUI code isnt full. My math are right. I used your math with dxDrawText, and it bugged.
Castillo Posted January 2, 2013 Author Posted January 2, 2013 Well, I converted your DX to my GUI, and it was even worst.
Cadu12 Posted January 2, 2013 Posted January 2, 2013 As you can see it, becuase of your math. Maybe your font scale are wrong again.
Castillo Posted January 2, 2013 Author Posted January 2, 2013 Well, now the problem is the separation between them. Image: http://imgur.com/fwNxc Code: local groupY = 0 for index, group in ipairs ( testGroups ) do friendsList [ "main" ] [ "contacts_group_".. group.name ] = guiCreateLabel(0.00, groupY, 0.98, 0.06, group.name ..":", true, friendsList [ "main" ] [ "contacts_scrollPane" ]) for index, contact in ipairs ( group.contacts ) do friendsList [ "main" ] [ "contacts_contact_state_".. contact.name ] = guiCreateStaticImage(0.03, ( index * dxGetFontHeight ( 1, "default-normal" ) / sy ) + groupY, 0.05, 0.06, "images/".. contact.state ..".png", true, friendsList [ "main" ] [ "contacts_scrollPane" ]) friendsList [ "main" ] [ "contacts_contact_label_".. contact.name ] = guiCreateLabel(0.10, ( index * dxGetFontHeight ( 1, "default-normal" ) / sy ) + groupY, 0.90, 0.06, contact.name, true, friendsList [ "main" ] [ "contacts_scrollPane" ]) end groupY = ( ( #group.contacts + 1 ) * dxGetFontHeight ( 1, "default-normal" ) / sy ) + groupY end
Cadu12 Posted January 2, 2013 Posted January 2, 2013 -- Wrong: dxGetFontHeight ( 1, "default-normal" ) / sy -- Use: (dxGetFontHeight ( 1, "default-normal" ) / sy)
Castillo Posted January 2, 2013 Author Posted January 2, 2013 That doesn't make any difference, I actually changed the code after I posted it. local groupY = 0 local fontY = ( dxGetFontHeight ( 1, "default-normal" ) / sy ) for index, group in ipairs ( testGroups ) do friendsList [ "main" ] [ "contacts_group_".. group.name ] = guiCreateLabel(0.00, groupY, 0.98, 0.06, group.name ..":", true, friendsList [ "main" ] [ "contacts_scrollPane" ]) for index, contact in ipairs ( group.contacts ) do friendsList [ "main" ] [ "contacts_contact_state_".. contact.name ] = guiCreateStaticImage(0.03, ( index * fontY ) + groupY, 0.05, 0.06, "images/".. contact.state ..".png", true, friendsList [ "main" ] [ "contacts_scrollPane" ]) friendsList [ "main" ] [ "contacts_contact_label_".. contact.name ] = guiCreateLabel(0.10, ( index * fontY ) + groupY, 0.90, 0.06, contact.name, true, friendsList [ "main" ] [ "contacts_scrollPane" ]) end groupY = ( ( #group.contacts + 1 ) * fontY ) + groupY end
Cadu12 Posted January 2, 2013 Posted January 2, 2013 local groupY = 0 for index, group in ipairs ( testGroups ) do friendsList [ "main" ] [ "contacts_group_".. group.name ] = guiCreateLabel(0.00, groupY, 0.98, 0.06, group.name ..":", true, friendsList [ "main" ] [ "contacts_scrollPane" ]) for index, contact in ipairs ( group.contacts ) do friendsList [ "main" ] [ "contacts_contact_state_".. contact.name ] = guiCreateStaticImage(0, 0, 0.05, 0.06, "images/".. contact.state ..".png", true, friendsList [ "main" ] [ "contacts_scrollPane" ]) friendsList [ "main" ] [ "contacts_contact_label_".. contact.name ] = guiCreateLabel(0, 0, 0.90, 0.06, contact.name, true, friendsList [ "main" ] [ "contacts_scrollPane" ]) local height = guiLabelGetFontHeight ( friendsList [ "main" ] [ "contacts_contact_state_".. contact.name ] ) guiSetSize(friendsList [ "main" ] [ "contacts_contact_state_".. contact.name ], 0.03, ( index * height ) + groupY, true) guiSetSize(friendsList [ "main" ] [ "contacts_contact_state_".. contact.name ], 0.10, ( index * height ) + groupY, true) end groupY = ( ( #group.contacts + 1 ) * guiLabelGetFontHeight ( friendsList [ "main" ] [ "contacts_group_".. group.name ] ) ) + groupY end Try this code. Not tested
Castillo Posted January 2, 2013 Author Posted January 2, 2013 I already fixed it by setting + 0.10 here: local fontY = ( dxGetFontHeight ( 1, "default-normal" ) / sy ) + 0.10 Thanks for your help.
Recommended Posts