Examples TOCexamples TOC

Horizontal String

$Date: 2004/04/18 13:25:43 $

 Table of contents

Introduction

This example will run a horizontal ProgressBar with custom string.

There are 10 cells with default values:

Percent text info is left aligned on a white background area of 350 pixels width.

[Top]

 PHP script

Build the progress bar

require_once 'HTML/Progress.php';

$bar = new HTML_Progress();
$bar->setAnimSpeed(100);
$bar->setIncrement(5);
$bar->setStringPainted(true);          // get space for the string
$bar->setString('');                   // but don't paint it

$ui =& $bar->getUI();
$ui->setStringAttributes('width=350 align=left');

Loop to run the progress

$pkg = array('PEAR', 'Archive_Tar', 'Config', 
    'HTML_QuickForm', 'HTML_CSS', 'HTML_Page', 'HTML_Template_Sigma', 
    'Log', 'MDB', 'PHPUnit');

do {
    $val = $bar->getValue();
    $i = floor($val / 10);
    $msg = ($val == 100) ? '' : "  installing package ($val %) ... : ".$pkg[$i];
    $bar->setString($msg);

    $bar->display();
    if ($bar->getPercentComplete() == 1) {
        break;   // the progress bar has reached 100%
    }
    $bar->incValue();
} while(1);

[Top]

 Render options

Here are options to build this progress bar string (percent text info):
width = 350
align = left
HTML_Progress_UI::setStringAttributes()

[Top]

 Output

Screenshot

[Top]

 Play full example

Run the script below :


<?php 
require_once 'HTML/Progress.php';

$bar = new HTML_Progress();
$bar->setAnimSpeed(100);
$bar->setIncrement(5);
$bar->setStringPainted(true);          // get space for the string
$bar->setString('');                   // but don't paint it

$ui =& $bar->getUI();
$ui->setStringAttributes('width=350 align=left');
?>
<html>
<head>
<title>Horizontal String ProgressBar example</title>
<style type="text/css">
<!--
<?php echo $bar->getStyle(); ?>
// -->
</style>
<script type="text/javascript">
<!--
<?php echo $bar->getScript(); ?>
//-->
</script>
</head>
<body>

<?php 
echo $bar->toHtml(); 

$pkg = array('PEAR', 'Archive_Tar', 'Config', 
    'HTML_QuickForm', 'HTML_CSS', 'HTML_Page', 'HTML_Template_Sigma', 
    'Log', 'MDB', 'PHPUnit');

do {
    $val = $bar->getValue();
    $i = floor($val / 10);
    $msg = ($val == 100) ? '' : "&nbsp; installing package ($val %) ... : ".$pkg[$i];
    $bar->setString($msg);

    $bar->display();
    if ($bar->getPercentComplete() == 1) {
        break;   // the progress bar has reached 100%
    }
    $bar->incValue();
} while(1);
?>

</body>
</html>
href:  ./horizontal_string.php

[Top]