Jump to content


TextAfter property in ProgressItems


  • Please log in to reply
No replies to this topic

#1 Guest_Markus_*

Guest_Markus_*
  • Guests

Posted 11 February 2006 - 02:58 AM

Sometimes it can be useful to have data other than percentages (eg. rpm, kB, dB, ...) associated with a ProgressBar. Therefore TNxProgressItem should have a TextAfter property as well as TNxTrackBarItem. As a side effect the Max property would be more useful as you currently can only see texts like 255% next to the progress bar when Max > 100 :roll: .

CODE
Index: NxPropertyItemClasses.pas

===================================================================

--- NxPropertyItemClasses.pas    (revision 3.3.5)

+++ NxPropertyItemClasses.pas    (working copy)

@@ -416,6 +416,7 @@

    FProgressStyle: TProgressBarStyle;

    FPosition: Integer;

    FHeight: Integer;

+    FTextAfter: WideString;

    procedure SetBorderColor(const Value: TColor);

    procedure SetHideWhenEmpty(const Value: Boolean);

    procedure SetMargin(const Value: Integer);

@@ -428,6 +429,7 @@

    procedure SetTransparent(const Value: Boolean);

    procedure SetPosition(const Value: Integer);

    procedure SetHeight(const Value: Integer);

+    procedure SetTextAfter(const Value: WideString);

  protected

    function GetAsFloat: Double; override;

    function GetAsInteger: Integer; override;

@@ -450,6 +452,7 @@

    property ProgressStyle: TProgressBarStyle read FProgressStyle write SetProgressStyle default pbSolid;

    property RoundCorners: Boolean read FRoundCorners write SetRoundCorners default False;

    property ShowText: Boolean read FShowText write SetShowText default False;

+    property TextAfter: WideString read FTextAfter write SetTextAfter;

    property Transparent: Boolean read FTransparent write SetTransparent default False;

  end;



@@ -1541,6 +1544,7 @@

  FProgressColor := clHighlight;

  FProgressStyle := pbSolid;

  FRoundCorners := False;

+  FTextAfter := '%';

  FTransparent := False;  

end;



@@ -1654,6 +1658,12 @@

  Change(ckValueRepaint);

end;



+procedure TNxProgressItem.SetTextAfter(const Value: WideString);

+begin

+  FTextAfter := Value;

+  Change(ckValueRepaint);

+end;

+

procedure TNxProgressItem.SetTransparent(const Value: Boolean);

begin

  FTransparent := Value;

Index: NxPropertyItemDisplay.pas

===================================================================

--- NxPropertyItemDisplay.pas    (revision 3.3.5)

+++ NxPropertyItemDisplay.pas    (working copy)

@@ -96,6 +96,8 @@

  end;



  TNxProgressItemDisplay = class(TNxItemDisplay)

+  private

+    function GetTextWidth: Integer;

  protected

    procedure DrawBoxes(R: TRect; Color: TColor);

    procedure DrawProgressBar;

@@ -932,8 +934,6 @@

end;



procedure TNxProgressItemDisplay.DrawProgressBar;

-const

-  spaTextToBar = 30;

var

  Ratio: Double;

  TxtRect, BorderRect, BoxRect, ProgressRect: TRect;

@@ -957,8 +957,8 @@

      Canvas.Font.Assign(ValueFont);

      TxtRect := ClientRect;

      TxtRect.Left := TxtRect.Left + 2;

-      TGraphicsProvider.DrawTextRect(Canvas, TxtRect, taLeftJustify, IntToStr(Position) + '%');

-      BorderRect.Left := BorderRect.Left + spaTextToBar;

+      TGraphicsProvider.DrawTextRect(Canvas, TxtRect, taLeftJustify, IntToStr(Position) + TextAfter);

+      BorderRect.Left := BorderRect.Left + GetTextWidth;

    end;

   

    Brush.Color := BorderColor;

@@ -996,6 +996,18 @@

  end;

end;



+function TNxProgressItemDisplay.GetTextWidth: Integer;

+begin

+  with Item as TNxProgressItem do

+  begin

+    if ShowText then

+    begin

+      Canvas.Font.Assign(ValueFont);

+      Result := Canvas.TextWidth(IntToStr(Max) + TextAfter) + 2;

+    end else Result := 0;

+  end;

+end;

+

procedure TNxProgressItemDisplay.PaintValue;

begin

  inherited;





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users