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 


Auto-Center Label Text on Parent Panel

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
AntumDeluge
Cheater
Reputation: 0

Joined: 20 Dec 2018
Posts: 48

PostPosted: Fri Dec 21, 2018 4:29 pm    Post subject: Auto-Center Label Text on Parent Panel Reply with quote

I want to center a text label on its parent panel & update its position to remain centered even if the parent is resized. I'm having trouble figuring out if this is possible.

Here is some example code:
Code:
local function showAbout()
   -- dialog to display information about trainer
   local aboutDialog = createForm(false)
   aboutDialog.setCaption("About")
   aboutDialog.setSize(400, 480)

   -- main panel
   local panel = createPanel(aboutDialog)
   panel.Align = alClient

   -- description text
   local descr = createLabel(panel)
   descr.setCaption("CE Trainer for a Game")

   -- show the dialog
   aboutDialog.showModal()
   -- free memory after dialog is closed
   aboutDialog.destroy()
end


I've tried setting descr.Align, descr.Alignment, & descr.Layout values (as well as those values for panel). But I haven't figured out how to get the text to center on the panel. Is this even possible. Or do I just have to set the text's position manually & disallow resizing the window?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Fri Dec 21, 2018 4:54 pm    Post subject: Reply with quote

in the formdesigner you can use anchor control settings (rightclock the component)

in lua you need to use code like
descr.anchorSideLeft.control=panel
descr.anchorSideLeft.side=asrCenter

or something like that (on my phone so can't check)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
AntumDeluge
Cheater
Reputation: 0

Joined: 20 Dec 2018
Posts: 48

PostPosted: Fri Dec 21, 2018 5:30 pm    Post subject: Reply with quote

Ah, thank you Dark Byte. I was just looking at the tutorial & figured out how to center the text in the form designer using anchors. But wasn't sure how to translate it over to Lua. I will try out your suggestions & see if I can find any more references to anchoring on the wiki.

-- Edit --

That worked:
Code:
local function showAbout()
   -- dialog to display information about trainer
   local aboutDialog = createForm(false)
   aboutDialog.setCaption("About")
   aboutDialog.setSize(400, 480)

   -- main panel
   local panel = createPanel(aboutDialog)
   panel.Align = alClient

   -- description text
   local descr = createLabel(panel)
   descr.setCaption("CE Trainer for a Game")
   -- center text
   descr.anchorSideLeft.control = panel
   descr.anchorSideLeft.side = asrCenter
   descr.anchorSideTop.control = panel
   descr.anchorSideTop.side = asrCenter

   -- show the dialog
   aboutDialog.showModal()
   -- free memory after dialog is closed
   aboutDialog.destroy()
end


Thank you again Dark Byte.

-- Edit --

I'm having another small issue with this. In the form designer I can center justify the text by setting Alignment to taCenter. But adding descr.Alignment = taCenter to my code doesn't work.

-- Edit --

I should note that I am using a newline escape character in the text:
Code:
descr.setCaption("CE Trainer\nfor a Game")


-- Edit --

Doesn't seem to work with an actual line break either:
Code:
descr.setCaption("CE Trainer\
for a Game")


-- Solved --

Using lowercase (descr.alignment = taCenter) doesn't work either. However, I was able to get it to work via the setProperty function:
Code:
setProperty(descr, "alignment", "taCenter")
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Fri Dec 21, 2018 10:12 pm    Post subject: Reply with quote

You need to use it as a string. descr.Alignment = 'taCenter' should work.
_________________
I don't know where I'm going, but I'll figure it out when I get there.
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 Lua Scripting 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