summaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graemeg@users.sourceforge.net>2007-04-10 14:48:34 +0000
committerGraeme Geldenhuys <graemeg@users.sourceforge.net>2007-04-10 14:48:34 +0000
commitb44565fdd5a7d591159c594b1ee375e10845a595 (patch)
tree30d1b8c792be530538ed27d1acde9c2057da3947 /gui
parent47cf5118b97d7964e9a8d2cca5deffeddfa43475 (diff)
downloadfpGUI-b44565fdd5a7d591159c594b1ee375e10845a595.tar.xz
* Fixed TFFixedLayout, TFDockedLayout implementations
* Updated the Layout demo and enabled all available layout managers. * Fixed the text clipping issue under Linux now that it uses Xft as default. * Fixed the Text Size issue under Linux now that it uses Xft. It report the wrong text size so the focus rectangle was draw wrong. * Adjust the scrollbar and combobox arrow button size to remove the tiny gap that appear below it.
Diffstat (limited to 'gui')
-rw-r--r--gui/fpguibuttons.inc6
-rw-r--r--gui/fpguicheckbox.inc2
-rw-r--r--gui/fpguilayouts.inc212
-rw-r--r--gui/fpguiscrollbar.inc12
-rw-r--r--gui/fpguistyle.inc28
5 files changed, 151 insertions, 109 deletions
diff --git a/gui/fpguibuttons.inc b/gui/fpguibuttons.inc
index 2c305fbf..04aaf714 100644
--- a/gui/fpguibuttons.inc
+++ b/gui/fpguibuttons.inc
@@ -76,6 +76,8 @@ constructor TFGenericButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
WidgetStyle := WidgetStyle + [wsCaptureMouse, wsClickable, wsOpaque];
+ // default size
+ FDefSize := Size(18, 18);
end;
@@ -134,7 +136,7 @@ begin
FMinSize.cx := Borders.Left + Borders.Right + TextWidth(Text);
if FMinSize.cx < 75 then
FMinSize.cx := 75; // apply default button width
- FMinSize.cy := Borders.Left + Borders.Right + FontCellHeight;
+ FMinSize.cy := Borders.Top + Borders.Bottom + FontCellHeight;
end;
FDefSize := FMinSize + gfxbase.Size(20, 2);
end;
@@ -142,6 +144,8 @@ end;
constructor TFCustomButton.Create(const pText: string; pOwner: TComponent);
begin
Create(pOwner);
+ // default size
+ FDefSize := Size(75, 25);
Text := pText;
end;
diff --git a/gui/fpguicheckbox.inc b/gui/fpguicheckbox.inc
index ff5e4cc6..d2615a1c 100644
--- a/gui/fpguicheckbox.inc
+++ b/gui/fpguicheckbox.inc
@@ -108,7 +108,7 @@ end;
procedure TFCustomCheckbox.CalcSizes;
begin
with FindForm.Wnd.Canvas do
- Style.GeTFCheckboxLayout(gfxbase.Size(TextWidth(Text), FontCellHeight),
+ Style.GetCheckboxLayout(gfxbase.Size(TextWidth(Text), FontCellHeight),
FMinSize, FLabelPos);
end;
diff --git a/gui/fpguilayouts.inc b/gui/fpguilayouts.inc
index b5dd511f..e6fbf929 100644
--- a/gui/fpguilayouts.inc
+++ b/gui/fpguilayouts.inc
@@ -77,6 +77,7 @@ type
TFFixedLayout = class(TFLayout)
protected
procedure CalcSizes; override;
+ procedure Resized; override;
public
constructor Create(AOwner: TComponent); override;
procedure AddWidget(AWidget: TFWidget; ALeft, ATop: Integer);
@@ -101,8 +102,11 @@ type
TFDockingLayout = class(TFLayout)
+ private
+ procedure InternalLayoutChildren;
protected
procedure CalcSizes; override;
+ procedure Resized; override;
public
constructor Create(AOwner: TComponent); override;
procedure AddWidget(AWidget: TFWidget; ADockingMode: TDockingMode);
@@ -361,14 +365,32 @@ var
item: TFFixedItem;
begin
if FWidgets.Count = 0 then
+ begin
FDefSize := gfxbase.Size(50, 50)
+ end
else
+ begin
for i := 0 to FWidgets.Count - 1 do
begin
item := TFFixedItem(FWidgets.Items[i]);
FDefSize.cx := Max(DefSize.cx, item.Left + item.Widget.DefSize.cx);
FDefSize.cy := Max(DefSize.cy, item.Top + item.Widget.DefSize.cy);
end;
+ end; { if..else }
+end;
+
+procedure TFFixedLayout.Resized;
+var
+ i: Integer;
+ item: TFFixedItem;
+begin
+ writeln('==> ' + Classname + '.Resized');
+
+ for i := 0 to FWidgets.Count - 1 do
+ begin
+ item := TFFixedItem(FWidgets.Items[i]);
+ item.Widget.SetBounds(item.Widget.Left, item.Widget.Top, item.Widget.Width, item.Widget.Height);
+ end;
end;
constructor TFFixedLayout.Create(AOwner: TComponent);
@@ -381,12 +403,15 @@ procedure TFFixedLayout.AddWidget(AWidget: TFWidget; ALeft, ATop: Integer);
var
item: TFFixedItem;
begin
- AWidget.Parent := self;
- item := TFFixedItem(FWidgets.Add);
- item.Left := ALeft;
- item.Top := ATop;
- item.Widget := AWidget;
- AWidget.SetBounds(Point(item.Left, item.Top), item.Widget.DefSize);
+ if not ContainsChild(AWidget) then
+ begin
+ item := TFFixedItem(FWidgets.Add);
+ item.Left := ALeft;
+ item.Top := ATop;
+ item.Widget := AWidget;
+ AWidget.Parent := self;
+ AWidget.SetBounds(Point(item.Left, item.Top), item.Widget.DefSize);
+ end;
end;
procedure TFFixedLayout.MoveWidget(AWidget: TFWidget; ALeft, ATop: Integer);
@@ -432,6 +457,71 @@ begin
FWidgets := TCollection.Create(TFDockingItem);
end;
+procedure TFDockingLayout.InternalLayoutChildren;
+var
+ clx, cly, clw, clh: Integer; // Client rectangle
+ ClientWidget: TFWidget;
+ i, WidgetW, WidgetH: Integer;
+ item: TFDockingItem;
+begin
+ clx := 0;
+ cly := 0;
+ clw := BoundsSize.cx;
+ clh := BoundsSize.cy;
+//WriteLn('=> DockingLayout.EvLayoutChildren ', BoundsSize.cx, ' x ', BoundsSize.cy);
+ if (clw = 0) or (clh = 0) then
+ exit;
+
+ // Process all attached widgets
+ ClientWidget := nil;
+ for i := 0 to FWidgets.Count - 1 do
+ begin
+ item := TFDockingItem(FWidgets.Items[i]);
+ case item.DockingMode of
+ dmLeft:
+ begin
+ WidgetW := item.Widget.DefSize.cx;
+ WidgetH := clh;
+ item.Left := clx;
+ item.Top := cly;
+ Inc(clx, WidgetW);
+ Dec(clw, WidgetW);
+ end;
+ dmTop:
+ begin
+ WidgetW := clw;
+ WidgetH := item.Widget.DefSize.cy;
+ item.Left := clx;
+ item.Top := cly;
+ Inc(cly, WidgetH);
+ Dec(clh, WidgetH);
+ end;
+ dmRight:
+ begin
+ WidgetW := item.Widget.DefSize.cx;
+ WidgetH := clh;
+ item.Left := clx + clw - WidgetW;
+ item.Top := cly;
+ Dec(clw, WidgetW);
+ end;
+ dmBottom:
+ begin
+ WidgetH := item.Widget.DefSize.cy;
+ WidgetW := clw;
+ item.Left := clx;
+ item.Top := cly + clh - WidgetH;
+ Dec(clh, WidgetH);
+ end;
+ dmClient:
+ ClientWidget := item.Widget;
+ end; { case }
+ if item.DockingMode <> dmClient then
+ item.Widget.SetBounds(item.Left, item.Top, WidgetW, WidgetH);
+ end; { for }
+ if Assigned(ClientWidget) then
+ ClientWidget.SetBounds(clx, cly, clw, clh);
+end;
+
procedure TFDockingLayout.CalcSizes;
var
i: Integer;
@@ -501,93 +591,38 @@ begin
end; { for }
end;
-{
-procedure TDockingLayout.EvLayoutChildren(Canvas: TGfxCanvas);
-var
- clx, cly, clw, clh: Integer; // Client rectangle
- ClientWidget: TFWidget;
- i, WidgetW, WidgetH: Integer;
- item: TDockingItem;
+procedure TFDockingLayout.Resized;
begin
- clx := 0;
- cly := 0;
- clw := BoundsSize.cx;
- clh := BoundsSize.cy;
- // WriteLn('=> DockingLayout.EvLayoutChildren ', BoundsSize.cx, ' x ', BoundsSize.cy);
- if (clw = 0) or (clh = 0) then
- exit;
-
- // Process all attached widgets
- ClientWidget := nil;
- for i := 0 to FWidgets.Count - 1 do
- begin
- item := TDockingItem(FWidgets.Items[i]);
- case item.DockingMode of
- dmLeft:
- begin
- WidgetW := item.Widget.DefSize.cx;
- WidgetH := clh;
- item.Left := clx;
- item.Top := cly;
- Inc(clx, WidgetW);
- Dec(clw, WidgetW);
- end;
- dmTop:
- begin
- WidgetW := clw;
- WidgetH := item.Widget.DefSize.cy;
- item.Left := clx;
- item.Top := cly;
- Inc(cly, WidgetH);
- Dec(clh, WidgetH);
- end;
- dmRight:
- begin
- WidgetW := item.Widget.DefSize.cx;
- WidgetH := clh;
- item.Left := clx + clw - WidgetW;
- item.Top := cly;
- Dec(clw, WidgetW);
- end;
- dmBottom:
- begin
- WidgetH := item.Widget.DefSize.cy;
- WidgetW := clw;
- item.Left := clx;
- item.Top := cly + clh - WidgetH;
- Dec(clh, WidgetH);
- end;
- dmClient:
- ClientWidget := item.Widget;
- end;
- if item.DockingMode <> dmClient then
- item.Widget.SetBounds(item.Left, item.Top, WidgetW, WidgetH);
- end;
- if Assigned(ClientWidget) then
- ClienTFWidget.SetBounds(clx, cly, clw, clh);
+ inherited Resized;
+ InternalLayoutChildren;
end;
-}
procedure TFDockingLayout.AddWidget(AWidget: TFWidget; ADockingMode: TDockingMode);
var
item: TFDockingItem;
begin
- AWidget.Parent := Self;
- item := TFDockingItem(FWidgets.Add);
- item.Widget := AWidget;
- item.DockingMode := ADockingMode;
+ if not ContainsChild(AWidget) then
+ begin
+ item := TFDockingItem(FWidgets.Add);
+ item.Widget := AWidget;
+ item.DockingMode := ADockingMode;
+ AWidget.Parent := Self;
+ end;
end;
procedure TFDockingLayout.AddWidget(AWidget: TFWidget; ALeft, ATop: Integer);
var
item: TFDockingItem;
begin
- AWidget.Parent := Self;
- item := TFDockingItem(FWidgets.Add);
- item.Widget := AWidget;
- item.DockingMode := dmUndocked;
- item.Left := ALeft;
- item.Top := ATop;
+ if not ContainsChild(AWidget) then
+ begin
+ item := TFDockingItem(FWidgets.Add);
+ item.Widget := AWidget;
+ item.DockingMode := dmUndocked;
+ item.Left := ALeft;
+ item.Top := ATop;
+ AWidget.Parent := Self;
+ end;
end;
@@ -1002,13 +1037,16 @@ procedure TFCustomGridLayout.AddWidget(AWidget: TFWidget; x, y, w, h: Integer);
var
item: TFGridItem;
begin
- AWidget.Parent := Self;
- item := TFGridItem(FWidgets.Add);
- item.Widget := AWidget;
- item.x := x;
- item.y := y;
- item.Width := w;
- item.Height := h;
+ if not ContainsChild(AWidget) then
+ begin
+ item := TFGridItem(FWidgets.Add);
+ item.Widget := AWidget;
+ item.x := x;
+ item.y := y;
+ item.Width := w;
+ item.Height := h;
+ AWidget.Parent := Self;
+ end;
end;
procedure TFCustomGridLayout.MoveWidget(AWidget: TFWidget; x, y, w, h: Integer);
diff --git a/gui/fpguiscrollbar.inc b/gui/fpguiscrollbar.inc
index 43030960..3a5f1e66 100644
--- a/gui/fpguiscrollbar.inc
+++ b/gui/fpguiscrollbar.inc
@@ -128,7 +128,7 @@ end;
procedure TFScrollBarButton.CalcSizes;
begin
ASSERT(Owner is TFCustomScrollBar);
- FMinSize := Style.GeTFScrollBarBtnSize(TFCustomScrollBar(Owner).Orientation);
+ FMinSize := Style.GetScrollBarBtnSize(TFCustomScrollBar(Owner).Orientation);
end;
@@ -389,9 +389,9 @@ end;
procedure TFScrollBarSlider.CalcSizes;
begin
if TFCustomScrollBar(Owner).Orientation = Horizontal then
- FDefSize.cx := Style.GeTFScrollBarBtnSize(Horizontal).cy * 5
+ FDefSize.cx := Style.GetScrollBarBtnSize(Horizontal).cy * 5
else
- FDefSize.cy := Style.GeTFScrollBarBtnSize(Vertical).cx * 5;
+ FDefSize.cy := Style.GetScrollBarBtnSize(Vertical).cx * 5;
end;
function TFScrollBarSlider.CalcPosition: Integer;
@@ -533,7 +533,7 @@ begin
end;
if not Embedded then
- with Style.GeTFScrollBarBorders(Orientation) do
+ with Style.GetScrollBarBorders(Orientation) do
begin
Inc(FMinSize.cx, Left + Right);
Inc(FMinSize.cy, Top + Bottom);
@@ -550,7 +550,7 @@ var
r: TRect;
begin
if not Embedded then
- with Style.GeTFScrollBarBorders(Orientation) do
+ with Style.GetScrollBarBorders(Orientation) do
begin
r.Left := Left;
r.Top := Top;
@@ -684,7 +684,7 @@ begin
Size := Slider.Width
else
Size := Slider.Height;
- Result := Math.Max(Style.GeTFScrollBarBtnMinSize,
+ Result := Math.Max(Style.GetScrollBarBtnMinSize,
PageSize * Size div Math.Max(1, Max - Min + 1));
if Result > Size then
Result := Size;
diff --git a/gui/fpguistyle.inc b/gui/fpguistyle.inc
index a06aa0c9..86743598 100644
--- a/gui/fpguistyle.inc
+++ b/gui/fpguistyle.inc
@@ -63,7 +63,7 @@
function GetEditBoxBorders: TRect; virtual; abstract;
// Check boxes
procedure DrawCheckBox(Canvas: TFCanvas; const ARect, LabelRect: TRect; Flags: TFCheckboxFlags); virtual; abstract;
- procedure GeTFCheckboxLayout(const LabelSize: TSize; var TotalSize: TSize; var LabelPos: TPoint); virtual; abstract;
+ procedure GetCheckboxLayout(const LabelSize: TSize; var TotalSize: TSize; var LabelPos: TPoint); virtual; abstract;
// Radio buttons
procedure DrawRadioButton(Canvas: TFCanvas; const ARect, LabelRect: TRect; Flags: TFCheckboxFlags); virtual; abstract;
procedure GetRadioButtonLayout(const LabelSize: TSize; var TotalSize: TSize; var LabelPos: TPoint); virtual; abstract;
@@ -72,9 +72,9 @@
procedure DrawComboBoxArrow(Canvas: TFCanvas; const ARect: TRect; IsPressed, IsEnabled: Boolean); virtual; abstract;
function GetComboBoxBtnSize: TSize; virtual; abstract;
// Scroll bars
- function GeTFScrollBarBorders(Orientation: TOrientation): TRect; virtual; abstract;
- function GeTFScrollBarBtnSize(Orientation: TOrientation): TSize; virtual; abstract;
- function GeTFScrollBarBtnMinSize: Integer; virtual; abstract;
+ function GetScrollBarBorders(Orientation: TOrientation): TRect; virtual; abstract;
+ function GetScrollBarBtnSize(Orientation: TOrientation): TSize; virtual; abstract;
+ function GetScrollBarBtnMinSize: Integer; virtual; abstract;
procedure DrawScrollBarBorder(Canvas: TFCanvas; const ARect: TRect); virtual; abstract;
procedure DrawScrollBarButton(Canvas: TFCanvas; const ARect: TRect; Direction: TArrowDirection; IsPressed, IsEnabled: Boolean); virtual; abstract;
// Scroll boxes
@@ -126,7 +126,7 @@
function GetEditBoxBorders: TRect; override;
// Check boxes
procedure DrawCheckBox(Canvas: TFCanvas; const ARect, LabelRect: TRect; Flags: TFCheckboxFlags); override;
- procedure GeTFCheckboxLayout(const LabelSize: TSize; var TotalSize: TSize; var LabelPos: TPoint); override;
+ procedure GetCheckboxLayout(const LabelSize: TSize; var TotalSize: TSize; var LabelPos: TPoint); override;
// Radio buttons
procedure DrawRadioButton(Canvas: TFCanvas; const ARect, LabelRect: TRect; Flags: TFCheckboxFlags); override;
procedure GetRadioButtonLayout(const LabelSize: TSize; var TotalSize: TSize; var LabelPos: TPoint); override;
@@ -135,9 +135,9 @@
function GetComboBoxArrowSize: TSize; override;
function GetComboBoxBtnSize: TSize; override;
// Scroll bars
- function GeTFScrollBarBorders(Orientation: TOrientation): TRect; override;
- function GeTFScrollBarBtnSize(Orientation: TOrientation): TSize; override;
- function GeTFScrollBarBtnMinSize: Integer; override;
+ function GetScrollBarBorders(Orientation: TOrientation): TRect; override;
+ function GetScrollBarBtnSize(Orientation: TOrientation): TSize; override;
+ function GetScrollBarBtnMinSize: Integer; override;
procedure DrawScrollBarBorder(Canvas: TFCanvas; const ARect: TRect); override;
procedure DrawScrollBarButton(Canvas: TFCanvas; const ARect: TRect; Direction: TArrowDirection; IsPressed, IsEnabled: Boolean); override;
// Scroll boxes
@@ -655,7 +655,7 @@ begin
DrawFocusRect(Canvas, Rect(Left - 2, Top - 2, Right + 2, Bottom + 2));
end;
-procedure TBasicStyle.GeTFCheckboxLayout(const LabelSize: TSize;
+procedure TBasicStyle.GetCheckboxLayout(const LabelSize: TSize;
var TotalSize: TSize; var LabelPos: TPoint);
begin
TotalSize := Size(LabelSize.cx + 21, Max(13, LabelSize.cy + 4));
@@ -764,18 +764,18 @@ begin
DrawDirectionArrows(Canvas, r, arrowDown);
end;
-function TBasicStyle.GeTFScrollBarBorders(Orientation: TOrientation): TRect;
+function TBasicStyle.GetScrollBarBorders(Orientation: TOrientation): TRect;
begin
Result := Rect(1, 1, 1, 1);
end;
-function TBasicStyle.GeTFScrollBarBtnSize(Orientation: TOrientation): TSize;
+function TBasicStyle.GetScrollBarBtnSize(Orientation: TOrientation): TSize;
begin
- Result.cx := 16;
- Result.cy := 16;
+ Result.cx := 18;
+ Result.cy := 18;
end;
-function TBasicStyle.GeTFScrollBarBtnMinSize: Integer;
+function TBasicStyle.GetScrollBarBtnMinSize: Integer;
begin
Result := 30;
end;