Jump to content

GUI Scrollpane bug?


Castillo

Recommended Posts

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.

Link to comment
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.

Link to comment

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 

Link to comment

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 

Link to comment
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

Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...