diff options
-rw-r--r-- | prototypes/fpgui2/tests/edittest.dpr | 7 | ||||
-rw-r--r-- | src/corelib/gfxbase.pas | 1 | ||||
-rw-r--r-- | src/gui/gui_label.pas | 27 |
3 files changed, 32 insertions, 3 deletions
diff --git a/prototypes/fpgui2/tests/edittest.dpr b/prototypes/fpgui2/tests/edittest.dpr index 9440f7b8..c9b33b22 100644 --- a/prototypes/fpgui2/tests/edittest.dpr +++ b/prototypes/fpgui2/tests/edittest.dpr @@ -290,18 +290,20 @@ end; bmp: TfpgImage; begin SetPosition(200, 200, 500, 350); -// WindowTitle := 'fpGUI Widget Test'; WindowTitle := 'Test Russian text -> Òåñò'; label1 := CreateLabel(self, 5, 5, 'Hello world!'); label2 := CreateLabel(self, 5, 20, 'Hello world in Bold!'); label2.FontDesc := 'Sans-12:bold:underline'; - label2.Width := 200; edit1 := CreateEdit(self, 10, 40, 120, 22); edit1.Text := 'Hello world. Hello world. Hello world.'; edit2 := CreateEdit(self, 10, 70, 200, 22); edit2.Text := 'Test Russian text -> Òåñò'; + // left to right and right to left text in one + // fpGUI doesn't handle this correctly yet. + // See http://www.catch22.net/tuts/editor18.asp for how it needs to display and work +// edit2.Text := 'HelloيُساوِيWorld'; btn2 := CreateButton(self, 10, 100, 75, 'Normal', nil); btn2.OnClick := @btnDisplayBMP; @@ -311,7 +313,6 @@ end; btn3.Embedded := True; btn3.OnClick := @btn3Click; - btn := CreateButton(self, 10, 130, 75, 'Close', @btnCloseClick); btn.ImageName := 'stdimg.close'; btn.ShowImage := True; diff --git a/src/corelib/gfxbase.pas b/src/corelib/gfxbase.pas index 9dfb9830..efc06cac 100644 --- a/src/corelib/gfxbase.pas +++ b/src/corelib/gfxbase.pas @@ -788,6 +788,7 @@ begin { What was not handled: underline } if Pos('UNDERLINE', UpperCase(Font.FontDesc)) > 0 then begin + writeln('underline detected in font'); underline := (Font.Descent div 2) + 1; if underline = 0 then underline := 1; diff --git a/src/gui/gui_label.pas b/src/gui/gui_label.pas index b3d7f9b7..9e51b780 100644 --- a/src/gui/gui_label.pas +++ b/src/gui/gui_label.pas @@ -15,13 +15,16 @@ type TfpgLabel = class(TfpgWidget) private + FAutoSize: boolean; FBackgroundColor: TfpgColor; FColor: TfpgColor; function GetFontDesc: string; + procedure SetAutoSize(const AValue: boolean); procedure SetBackgroundColor(const AValue: TfpgColor); procedure SetFontDesc(const AValue: string); procedure SetColor(const AValue: TfpgColor); procedure SetText(const AValue: string); + procedure ResizeLabel; protected FText: string; FFont: TfpgFont; @@ -31,6 +34,7 @@ type destructor Destroy; override; property Font: TfpgFont read FFont; published + property AutoSize: boolean read FAutoSize write SetAutoSize default True; property Text: string read FText write SetText; property FontDesc: string read GetFontDesc write SetFontDesc; property Color: TfpgColor read FColor write SetColor; @@ -68,6 +72,18 @@ begin Result := FFont.FontDesc; end; +procedure TfpgLabel.SetAutoSize(const AValue: boolean); +begin + if FAutoSize = AValue then + Exit; //==> + FAutoSize := AValue; + if FAutoSize then + begin + ResizeLabel; + RePaint; + end; +end; + procedure TfpgLabel.SetBackgroundColor(const AValue: TfpgColor); begin if FBackgroundColor = AValue then @@ -80,6 +96,8 @@ procedure TfpgLabel.SetFontDesc(const AValue: string); begin FFont.Free; FFont := fpgGetFont(AValue); + if FAutoSize then + ResizeLabel; RePaint; end; @@ -88,9 +106,17 @@ begin if FText = AValue then Exit; FText := AValue; + if FAutoSize then + ResizeLabel; RePaint; end; +procedure TfpgLabel.ResizeLabel; +begin + Width := FFont.TextWidth(FText); + Height := FFont.Height; +end; + constructor TfpgLabel.Create(AOwner: TComponent); begin inherited Create(AOwner); @@ -100,6 +126,7 @@ begin FWidth := 80; FColor := clText1; FBackgroundColor := clWindowBackground; + FAutoSize := True; end; destructor TfpgLabel.Destroy; |