Coloring the lines of a DListView?

So far I got this:

[lua]local Line = PANEL.AppList:GetLine(1)
function Line:Paint(w, h)
surface.SetDrawColor(Color(255, 50, 50))
local x, y = self:GetPos()
surface.DrawRect(x - 1, y, w, h)
end[/lua]
And it sort of works

But when I click on the column names, and the items get rearranged, all background disappears from the line.

Tips?

I would use the base function for DListView_Line paint. You can find it here at line 33. Unfortunately, the line is painted with a derma_hook, or a derma skin, so you will have to look into how the default derma skin paints the line.

The line is complicated, obviously. There is the selected color, the deselected color, the regular color, and the every-other color. I would just copy the current derma skin and modify the colors there.
You could also try Line:SetColor() but I assume you already did that and it probably didn’t work.

I didn’t do SetColor because I knew from the beginning it wouldn’t have worked.
And yes, I plan was already planning on having the selcted colors and stuff. Did it various time for other components.

Will look into it

Eh… I’m just gonna try to code my own DListView.

It might be BUMP but anyway…

if you want to color all lines then its something like this:



for k,v in pairs(player.GetAll()) do
	DListView:AddLine( ) --what ever you want to add
	DListView:GetLine(k).Paint = function()
		-- what you want to paint EXAMPLE:
		-- draw.RoundedBox(0,0,0, DListView:GetWide(), DListView:GetTall(), Color(249,105,14,255)) -- this will make every line Orange.
	end
end


If you still need it or not I decided to put it here so maybe someone in near future could be looking for this :slight_smile:

I realize this is a bump as well, but this might be helpful for anyone working with the DListView.

PANEL:Paint( w, h ) automatically gives you the width and height parameters. You don’t need to use :GetWide() and :GetTall().

If you want to override the paint hooks of an already existing DListView panel, you can also do something along these lines:



for _, line in pairs( YourDListView:GetLines() ) do

    function line:Paint( w, h )

        if ( self:IsHovered() ) then

            -- draw it highlighted

        elseif ( self:IsSelected() ) then

            -- draw it selected

        elseif ( self:GetAltLine() ) then

            -- draw it lighter or darker

        else

            -- draw it normally

        end

    end

    -- if you want to change the text font/color of the columns
    for _, column in pairs( line["Columns"] ) do

        column:SetFont( "YourFont" )
        column:SetTextColor( YourColor )

    end

end


You can also color the column tabs at the top:



for _, v in pairs( YourDListView[ "Tabs" ] ) do

        function v.Header:Paint( w, h )

            -- paint it how you want

        end

        v.Header:SetFont( "YourFont" )
        v.Header:SetTextColor( YourColor )
end


Finally, you can also change the look of the vertical scroll bar so it fits your theme:



function YourDListView.VBar:Paint( w, h ) 
        -- paints the track area behind the grip and the buttons
end

function YourDListView.VBar.btnUp:Paint( w, h ) 
        -- paints the top button that lets you scroll up
end

function YourDListView.VBar.btnDown:Paint( w, h )
        -- paints the bottom button that lets you scroll down
end

function YourDListView.VBar.btnGrip:Paint( w, h )
        -- paints the portion of the scrollbar that you can grab
end


With those functions overwritten, you can produce something like:

http://build.ijwtb.net/images/commands.png