Jump to content

Label Justification not working


kengineer

Recommended Posts

Hey guys,

I'm trying to place a label with center justified text. I do this during the widget init by passing the address of the function to the custom draw parameter in the widget init struct:

wi.customDraw = gwinLabelDrawJustifiedCenter;

However, this isn't working. I can literally make two labels, one with that function passed and another without and they look exactly the same (not center justified, text starts at the x,y location).

Link to comment
Share on other sites

I quickly fired up the µGFX-Studio to give this a try and it appears like everything is working correctly:

	// Create label widget: ghLabel1
	wi.g.show = TRUE;
	wi.g.x = 210;
	wi.g.y = 310;
	wi.g.width = 120;
	wi.g.height = 20;
	wi.g.parent = ghContainerPage0;
	wi.text = "Label1";
	wi.customDraw = gwinLabelDrawJustifiedLeft;
	wi.customParam = 0;
	wi.customStyle = 0;
	ghLabel1 = gwinLabelCreate(0, &wi);
	gwinLabelSetBorder(ghLabel1, TRUE);

	// Create label widget: ghLabel2
	wi.g.show = TRUE;
	wi.g.x = 210;
	wi.g.y = 340;
	wi.g.width = 120;
	wi.g.height = 20;
	wi.g.parent = ghContainerPage0;
	wi.text = "Label2";
	wi.customDraw = gwinLabelDrawJustifiedCenter;
	wi.customParam = 0;
	wi.customStyle = 0;
	ghLabel2 = gwinLabelCreate(0, &wi);
	gwinLabelSetBorder(ghLabel2, TRUE);

	// Create label widget: ghLabel3
	wi.g.show = TRUE;
	wi.g.x = 210;
	wi.g.y = 370;
	wi.g.width = 120;
	wi.g.height = 20;
	wi.g.parent = ghContainerPage0;
	wi.text = "Label3";
	wi.customDraw = gwinLabelDrawJustifiedRight;
	wi.customParam = 0;
	wi.customStyle = 0;
	ghLabel3 = gwinLabelCreate(0, &wi);
	gwinLabelSetBorder(ghLabel3, TRUE);

This code produces the expected result:

label_justification.png

Can you please double check your code and show it to us if the issue remains? A test case that allows us to reproduce the problem would be preferred.

Link to comment
Share on other sites

Forgive me, this was due to my own ignorance. I wasn't thinking about justification within the context of the label width itself but rather the label on the screen. I had created the label without defining the width. Therefore the size was just the amount needed for the text, and therefore justification doesn't do anything different in this case. Now I've defined the width as the width of my screen and this works. Appreciate it!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...