Jump to content
  • Register Now

    Sign up and take advantage of the features of our community! Some forums are only accessible to our members!

  • 0

How can i align text?


iShadoW

Question

Version of Files XXX

Hi i have a problem with the short textes, the appendtextline align long textes and all below them, but if the first bonus or the title is shorter it doesnt align

 

GIF

 

here is the part of code

		def AppendTextLine(self, text, color = FONT_COLOR, centerAlign = True):
			textLine = ui.TextLine()
			textLine.SetParent(self)
			textLine.SetFontName(self.defFontName)
			textLine.SetPackedFontColor(color)
			textLine.SetText(text)
			textLine.SetOutline()
			textLine.SetFeather(False)
			textLine.Show()

			(textWidth, textHeight)=textLine.GetTextSize()

			textWidth += 55
			textHeight += 5

			if self.toolTipWidth < textWidth:
				self.toolTipWidth = textWidth

			self.childrenList.append(textLine)
			
			if centerAlign:
				textLine.SetPosition(self.toolTipWidth/2, self.toolTipHeight)
				textLine.SetHorizontalAlignCenter()
			else:
				textLine.SetPosition(10, self.toolTipHeight)

			
			self.toolTipHeight += textHeight
			self.ResizeToolTip()		

			return textLine

 

	def __AppendAttributeInformation(self, attrSlot, itemAbsChance = 0):
		if 0 != attrSlot:
			for i in xrange(player.ATTRIBUTE_SLOT_MAX_NUM):
				type = attrSlot[i][0]
				value = attrSlot[i][1]
				if 0 == value:
					continue

				affectString = self.__GetAffectString(type, value)

				if app.ENABLE_SASH_SYSTEM:
					if item.GetItemType() == item.ITEM_TYPE_COSTUME and item.GetItemSubType() == item.COSTUME_TYPE_SASH and itemAbsChance:
						value = self.CalcSashValue(value, itemAbsChance)
						affectString = self.__GetAffectString(type, value)
				
				if affectString:
					affectColor = self.__GetAttributeColor(i, value)
					self.AppendTextLine(affectString, affectColor)

 

Thanks, Sincerly,
iShadoW

 

Edited by iShadoW (see edit history)
Link to post

5 answers to this question

Recommended Posts

  • 0
  • VIP

Try replacing your AppendTextLine function with this:

	    def AppendTextLine(self, text, color = FONT_COLOR, centerAlign = TRUE):
	        textLine = ui.TextLine()
	        textLine.SetParent(self)
	        textLine.SetFontName(self.defFontName)
	        textLine.SetPackedFontColor(color)
	        textLine.SetText(text)
	        textLine.SetOutline()
	        textLine.SetFeather(FALSE)
	        textLine.Show()
	 
	        if centerAlign:
	            textLine.SetPosition(self.toolTipWidth/2, self.toolTipHeight)
	            textLine.SetHorizontalAlignCenter()
	 
	        else:
	            textLine.SetPosition(10, self.toolTipHeight)
	 
	        self.childrenList.append(textLine)
	 
	        self.toolTipHeight += self.TEXT_LINE_HEIGHT
	        self.ResizeToolTip()
	 
	        return textLine
	

 

Link to post
  • 0
6 hours ago, Finnael said:

Try replacing your AppendTextLine function with this:

 

	    def AppendTextLine(self, text, color = FONT_COLOR, centerAlign = TRUE):
	        textLine = ui.TextLine()
	        textLine.SetParent(self)
	        textLine.SetFontName(self.defFontName)
	        textLine.SetPackedFontColor(color)
	        textLine.SetText(text)
	        textLine.SetOutline()
	        textLine.SetFeather(FALSE)
	        textLine.Show()
	 
	        if centerAlign:
	            textLine.SetPosition(self.toolTipWidth/2, self.toolTipHeight)
	            textLine.SetHorizontalAlignCenter()
	 
	        else:
	            textLine.SetPosition(10, self.toolTipHeight)
	 
	        self.childrenList.append(textLine)
	 
	        self.toolTipHeight += self.TEXT_LINE_HEIGHT
	        self.ResizeToolTip()
	 
	        return textLine
	

 

This function is ok for alignment, but the width of the tooltip will be generated according to the 'Title' text length and if the title text is too short, some longer bonus texts will get out of the tooltip. I tried to set the tooltip width using the longest text but no result so far. Any ideas?

Link to post
  • 0
7 hours ago, Finnael said:

Try replacing your AppendTextLine function with this:

 

	    def AppendTextLine(self, text, color = FONT_COLOR, centerAlign = TRUE):
	        textLine = ui.TextLine()
	        textLine.SetParent(self)
	        textLine.SetFontName(self.defFontName)
	        textLine.SetPackedFontColor(color)
	        textLine.SetText(text)
	        textLine.SetOutline()
	        textLine.SetFeather(FALSE)
	        textLine.Show()
	 
	        if centerAlign:
	            textLine.SetPosition(self.toolTipWidth/2, self.toolTipHeight)
	            textLine.SetHorizontalAlignCenter()
	 
	        else:
	            textLine.SetPosition(10, self.toolTipHeight)
	 
	        self.childrenList.append(textLine)
	 
	        self.toolTipHeight += self.TEXT_LINE_HEIGHT
	        self.ResizeToolTip()
	 
	        return textLine
	

got it , but this is the classic function, and the guy above is right, the longer bonuses will exit tooltip, i tried something with reversed(xrange) but nothing works, anyway is a good fix for anyway if we can get it , it is all about small things ;)

 

49 minutes ago, valizrt said:

This function is ok for alignment, but the width of the tooltip will be generated according to the 'Title' text length and if the title text is too short, some longer bonus texts will get out of the tooltip. I tried to set the tooltip width using the longest text but no result so far. Any ideas?

i'm still trying to resolve :D

Link to post
  • 0

try calling this function:

self.AlignHorizonalCenter()

in the body of the if statement.

It should look like this:

if self.toolTipWidth < textWidth:
	self.toolTipWidth = textWidth
	self.AlignHorizonalCenter()
                       
	

Let me know if it works

Edited by valizrt (see edit history)
  • Love 1
Link to post
  • 0
9 hours ago, valizrt said:

try calling this function:

self.AlignHorizonalCenter()

in the body of the if statement.

It should look like this:

if self.toolTipWidth < textWidth:
	self.toolTipWidth = textWidth
	self.AlignHorizonalCenter()
                       
	

Let me know if it works

works so god damn good, ty so much for your time ❤️ 

Link to post
Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.