Solved

how do i justify text with math

Posted on 2008-10-21
2
623 Views
Last Modified: 2012-05-05
I need to write an algorithm that will full jusity a number of text links along a line in action script.  i can read any programming language so information in any language is appreciated.

The idea is this:

if therer are 5 links of various sizes that are situated on a menu that can be 600 pixels wide, i need  to center then and adjust the spaces between each item such that the fill the available horizontal area.  Dont worry about what happens if they over fill the available space.
0
Comment
Question by:Edanisko
2 Comments
 
LVL 9

Accepted Solution

by:
jhshukla earned 500 total points
ID: 22772524
>> text links along a line in action script
AFAIK, action script has something to do with flash. So why in C??

that aside, here are the things you will need:
(1) some sort of graphics object or class that can give you dimensions of a given text string.
(2) the fonts (+ size, bold/italics decoration)
(3) the actual text you want to display

use the above three to get the sizes of links and add them to get total size : call it total_size
(600 - total_size)/(num_items - 1) = spacing you need between two links

We will need more info on what environment you are developing in to write pseudo code.
0
 
LVL 2

Author Comment

by:Edanisko
ID: 22772620
Yes.

there here it is in AS3
for(var i:int=0; i<=_NavItems.length-1;i++){

	if (i==0){

		_NavItems[i].x = 0;

	} else {

		_NavItems[i].x =amountOfSpaceBetweenLinks + _NavItems[i-1].x + _NavItems[i-1].width;

	}

	_NavItems[i].visible=true;

	

}

Open in new window

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now