Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


ListView Tutorial

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials
View previous topic :: View next topic  
Author Message
jgoemat
Expert Cheater
Reputation: 21

Joined: 25 Sep 2011
Posts: 217

PostPosted: Mon Jul 23, 2018 12:57 am    Post subject: ListView Tutorial This post has 1 review(s) Reply with quote

I was using ListView for a project and decided to write a tutorial:

https://wiki.cheatengine.org/index.php?title=Tutorial:LuaFormListView

It covers the basics, using OwnerData for performance, and custom styles. The sample shows a view of a million-row lua table. Here's the complete code-behind:

Code:
-- items
list = list or {}
if #list == 0 then
  for i=1,1000000 do
    local item = {
      message = string.format('Message %d', i),
      data = math.sqrt(i)
    }
    table.insert(list, item)
  end
end

-- need to set the Items.Count property so that it knows how many rows there
-- are in total
UDF1.CEListView1.Items.Count = #list

-- definition created by double-clicking OnData event handler
function CEListView1Data(sender, listitem)
  -- use + 1 because listitem.Index is 0-based
  local d = list[listitem.Index + 1]
  if not d then return end
  listitem.Caption = d.message -- first column
  -- other columns have sqrt of data property and CURRENT clock
  -- when this event was called
  local others = {string.format('%0.3f', math.sqrt(d.data)), os.clock()}
  listitem.SubItems.text = table.concat(others, '\n')
end

function CEListView1CustomDrawSubItem(Sender, Item, SubItem, State)
  if (Item.Index % 2) == 1 then
    Sender.Canvas.Brush.Color = 0xffe0e0 -- odd rows blue bg (0-based)
    if SubItem == 1 then Sender.Canvas.Font.Color = 0x8f8f8f end -- gray middle column
  else
    Sender.Canvas.Brush.Color = 0xffffff -- odd rows white bg (0-based)
    if SubItem == 2 then
      Sender.Canvas.Font.Color = 0xffff40 -- cyan right column
    else
      Sender.Canvas.Font.Color = 0x2020ff -- red other columns
    end
  end
  return true -- return true for DefaultDraw
end

function CEListView1CustomDrawItem(Sender, Item, State)
  return CEListView1CustomDrawSubItem(Sender, Item, 0, State)
end


I'm going to handle selecting and handling user events later...



EndResult.png
 Description:
 Filesize:  12.73 KB
 Viewed:  2358 Time(s)

EndResult.png


Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites