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 


Cheat Engine Forum Index
PostGo back to topic
jgoemat
Master Cheater
Reputation: 22
Joined: 25 Sep 2011
Posts: 252

PostPosted: Mon Jul 23, 2018 12:57 am    Post subject: ListView Tutorial

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...
Back to top
View user's profile Send private message
Post reviews:   Approve 1
Author Review
Dark Byte
Review: Approve
Post reference:
ReviewPosted: Mon Jul 23, 2018 2:43 am


Back to top
View user's profile Send private message MSN Messenger
Display:  
Cheat Engine Forum Index


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites