From bfad32122a462c6f8dbb154c5cdf239c86f55645 Mon Sep 17 00:00:00 2001 From: "Jean-Marc.Levecque" Date: Mon, 6 Jul 2015 21:54:55 +0200 Subject: Allow tabs color setting Signed-off-by: Jean-Marc.Levecque --- src/gui/fpg_tab.pas | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/gui/fpg_tab.pas b/src/gui/fpg_tab.pas index 414c89a2..cf566c8b 100644 --- a/src/gui/fpg_tab.pas +++ b/src/gui/fpg_tab.pas @@ -55,6 +55,7 @@ type FPageControl: TfpgPageControl; FText: string; FTabVisible: boolean; + FTabColor: TfpgColor; function GetPageControl: TfpgPageControl; function GetPageIndex: Integer; function GetText: string; @@ -72,6 +73,7 @@ type property PageIndex: Integer read GetPageIndex write SetPageIndex; property PageControl: TfpgPageControl read FPageControl write SetPageControl; property TabVisible: boolean read FTabVisible write FTabVisible; + property TabColor: Tfpgcolor read FTabColor write FTabColor; published property BackgroundColor; property Enabled; @@ -130,7 +132,8 @@ type procedure SetTabPosition(const AValue: TfpgTabPosition); procedure DoPageChange(ATabSheet: TfpgTabSheet); procedure DoTabSheetClosing(ATabSheet: TfpgTabSheet); - function DrawTab(const rect: TfpgRect; const Selected: Boolean = False; const Mode: Integer = 1): TfpgRect; + function DrawTab(const ATabSheet: TfpgTabSheet; const rect: TfpgRect; const Selected: Boolean = False; + const Mode: Integer = 1): TfpgRect; procedure pmCloseTab(Sender: TObject); function GetActiveTabColor: TfpgColor; procedure SetActiveTabColor(AValue: TfpgColor); @@ -257,6 +260,7 @@ begin FTabVisible:= True; FFocusable := True; FBackgroundColor := Parent.BackgroundColor; + FTabColor := Parent.BackgroundColor; FTextColor := Parent.TextColor; FIsContainer := True; end; @@ -656,7 +660,8 @@ begin end; { Mode = 1 means the background tabs. Mode = 2 means the Active Tab } -function TfpgPageControl.DrawTab(const rect: TfpgRect; const Selected: Boolean = False; const Mode: Integer = 1): TfpgRect; +function TfpgPageControl.DrawTab(const ATabSheet: TfpgTabSheet; const rect: TfpgRect; const Selected: Boolean = False; + const Mode: Integer = 1): TfpgRect; var r: TfpgRect; begin @@ -676,7 +681,7 @@ begin Canvas.SetColor(ActiveTabColor); end else - Canvas.SetColor(BackgroundColor); + Canvas.SetColor(ATabSheet.TabColor); case TabPosition of tpTop: @@ -936,7 +941,7 @@ begin end; // paint tab button r2.Width := ButtonWidth(h.Text); - r3 := DrawTab(r2, h = ActivePage); + r3 := DrawTab(h, r2, h = ActivePage); // paint text on non-active tabs if h <> ActivePage then Canvas.DrawText(lp + (ButtonWidth(h.Text) div 2) - fpgStyle.DefaultFont.TextWidth(GetTabText(h.Text)) div 2, @@ -956,7 +961,7 @@ begin r2.Height := Height - TabH; Canvas.DrawButtonFace(r2, []); // Draw text of ActivePage, because we didn't before. - DrawTab(r3, false, 2); + DrawTab(h, r3, false, 2); Canvas.DrawText(r3.Left+4, r3.Top+5, r3.Width, r3.Height, ActivePage.Text, lTxtFlags); end; @@ -980,7 +985,7 @@ begin end; // paint tab button r2.Width := ButtonWidth(h.Text); - r3 := DrawTab(r2, h = ActivePage); + r3 := DrawTab(h, r2, h = ActivePage); // paint text on non-active tabs if h <> ActivePage then Canvas.DrawText(lp + (ButtonWidth(h.Text) div 2) - fpgStyle.DefaultFont.TextWidth(GetTabText(h.Text)) div 2, @@ -1000,7 +1005,7 @@ begin Canvas.DrawButtonFace(r2, []); // Draw text of ActivePage, because we didn't before. - DrawTab(r3, false, 2); + DrawTab(h, r3, false, 2); Canvas.DrawText(r3.Left+4, r3.Top+3, r3.Width, r3.Height, ActivePage.Text, lTxtFlags); end; @@ -1025,7 +1030,7 @@ begin h.SetPosition(FMargin+2, FMargin+2, Width - ((FMargin+2)*2) - TabW, Height - ((FMargin+2)*2)); end; // paint tab button - r3 := DrawTab(r2, h = ActivePage); + r3 := DrawTab(h, r2, h = ActivePage); // paint text on non-active tabs if h <> ActivePage then @@ -1045,7 +1050,7 @@ begin Canvas.DrawButtonFace(r2, []); // Draw text of ActivePage, because we didn't before. - DrawTab(r3, false, 2); + DrawTab(h, r3, false, 2); Canvas.DrawText(r3.left+toffset, r3.Top, r3.Width, r3.Height, ActivePage.Text, lTxtFlags); end; @@ -1070,7 +1075,7 @@ begin h.SetPosition(FMargin+2+TabW, FMargin+2, Width - ((FMargin+2)*2) - TabW, Height - ((FMargin+2)*2)); end; // paint tab button - r3 := DrawTab(r2, h = ActivePage); + r3 := DrawTab(h, r2, h = ActivePage); // paint text on non-active tabs if h <> ActivePage then @@ -1090,7 +1095,7 @@ begin Canvas.DrawButtonFace(r2, []); // Draw text of ActivePage, because we didn't before. - DrawTab(r3, false, 2); + DrawTab(h, r3, false, 2); Canvas.DrawText(r3.left+toffset, r3.Top, r3.Width, r3.Height, ActivePage.Text, lTxtFlags); end; end; { case } -- cgit v1.2.3-70-g09d2 From 45b8d2fc9c0ce79ccec1fc610b3c3467f5cccee1 Mon Sep 17 00:00:00 2001 From: "Jean-Marc.Levecque" Date: Sat, 11 Jul 2015 09:19:32 +0200 Subject: Allow tabtext color setting Signed-off-by: Jean-Marc.Levecque --- examples/gui/tabtest/tabtest.lpr | 2 ++ src/gui/fpg_tab.pas | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/examples/gui/tabtest/tabtest.lpr b/examples/gui/tabtest/tabtest.lpr index 52f7ec17..bea86f8c 100644 --- a/examples/gui/tabtest/tabtest.lpr +++ b/examples/gui/tabtest/tabtest.lpr @@ -107,6 +107,7 @@ begin pcMain.Height := 300; pcMain.Anchors := [anLeft, anTop, anRight, anBottom]; pcMain.ActiveTabColor:= clOrangeRed; + pcMain.ActiveTabTextColor:= clYellow; // pcMain.FixedTabWidth:=150; // Tab One @@ -127,6 +128,7 @@ begin tsThree.Text := 'Tab Three'; tsThree.BackgroundColor:= clWheat; tsThree.TabColor:= clLightBlue; + tsThree.TabTextColor:= clWhite; CreateLabel(tsThree, 80, 50, 'TabSheet Three'); // Tab Four diff --git a/src/gui/fpg_tab.pas b/src/gui/fpg_tab.pas index cf566c8b..dfb55ad2 100644 --- a/src/gui/fpg_tab.pas +++ b/src/gui/fpg_tab.pas @@ -56,6 +56,7 @@ type FText: string; FTabVisible: boolean; FTabColor: TfpgColor; + FTabTextColor: TfpgColor; function GetPageControl: TfpgPageControl; function GetPageIndex: Integer; function GetText: string; @@ -74,6 +75,7 @@ type property PageControl: TfpgPageControl read FPageControl write SetPageControl; property TabVisible: boolean read FTabVisible write FTabVisible; property TabColor: Tfpgcolor read FTabColor write FTabColor; + property TabTextColor: TfpgColor read FTabTextColor write FTabTextColor; published property BackgroundColor; property Enabled; @@ -107,6 +109,7 @@ type FLastRClickPos: TfpgPoint; FUpdateCount: Integer; FActiveTabColor: TfpgColor; + FActiveTabTextColor: TfpgColor; function GetActivePageIndex: integer; function GetPage(AIndex: integer): TfpgTabSheet; function GetPageCount: Integer; @@ -137,6 +140,8 @@ type procedure pmCloseTab(Sender: TObject); function GetActiveTabColor: TfpgColor; procedure SetActiveTabColor(AValue: TfpgColor); + function GetActiveTabTextColor: TfpgColor; + procedure SetActiveTabTextColor(AValue: TfpgColor); protected procedure SetBackgroundColor(const AValue: TfpgColor); override; procedure OrderSheets; // currently using bubblesort @@ -163,6 +168,7 @@ type published property ActivePageIndex: integer read GetActivePageIndex write SetActivePageIndex default 0; property ActiveTabColor: TfpgColor read GetActiveTabColor write SetActiveTabColor default clWindowBackground; + property ActiveTabTextColor: TfpgColor read GetActiveTabTextColor write SetActiveTabTextColor; property Align; property BackgroundColor; property Enabled; @@ -793,6 +799,20 @@ begin end; end; +function TfpgPageControl.GetActiveTabTextColor: TfpgColor; +begin + Result := FActiveTabTextColor; +end; + +procedure TfpgPageControl.SetActiveTabTextColor(AValue: TfpgColor); +begin + if FActiveTabTextColor <> AValue then + begin + FActiveTabTextColor := AValue; + RePaint; + end; +end; + procedure TfpgPageControl.SetBackgroundColor(const AValue: TfpgColor); var lWasMatch: boolean; @@ -944,9 +964,11 @@ begin r3 := DrawTab(h, r2, h = ActivePage); // paint text on non-active tabs if h <> ActivePage then + begin + Canvas.SetTextColor(h.TabTextColor); Canvas.DrawText(lp + (ButtonWidth(h.Text) div 2) - fpgStyle.DefaultFont.TextWidth(GetTabText(h.Text)) div 2, Height-TabH+toffset, GetTabText(h.Text), lTxtFlags); - + end; r2.Left := r2.Left + r2.Width; lp := lp + ButtonWidth(h.Text); if h <> TfpgTabSheet(FPages.Last) then @@ -962,6 +984,7 @@ begin Canvas.DrawButtonFace(r2, []); // Draw text of ActivePage, because we didn't before. DrawTab(h, r3, false, 2); + Canvas.SetTextColor(ActiveTabTextColor); Canvas.DrawText(r3.Left+4, r3.Top+5, r3.Width, r3.Height, ActivePage.Text, lTxtFlags); end; @@ -988,8 +1011,11 @@ begin r3 := DrawTab(h, r2, h = ActivePage); // paint text on non-active tabs if h <> ActivePage then + begin + Canvas.SetTextColor(h.TabTextColor); Canvas.DrawText(lp + (ButtonWidth(h.Text) div 2) - fpgStyle.DefaultFont.TextWidth(GetTabText(h.Text)) div 2, FMargin+toffset, GetTabText(h.Text), lTxtFlags); + end; r2.Left := r2.Left + r2.Width; lp := lp + ButtonWidth(h.Text); if h <> TfpgTabSheet(FPages.Last) then @@ -1006,6 +1032,7 @@ begin // Draw text of ActivePage, because we didn't before. DrawTab(h, r3, false, 2); + Canvas.SetTextColor(ActiveTabTextColor); Canvas.DrawText(r3.Left+4, r3.Top+3, r3.Width, r3.Height, ActivePage.Text, lTxtFlags); end; @@ -1034,7 +1061,10 @@ begin // paint text on non-active tabs if h <> ActivePage then + begin + Canvas.SetTextColor(h.TabTextColor); Canvas.DrawText(r2.left+toffset, r2.Top, r2.Width, r2.Height, GetTabText(h.Text), lTxtFlags); + end; r2.Top += r2.Height; lp := r2.Top; if h <> TfpgTabSheet(FPages.Last) then @@ -1051,6 +1081,7 @@ begin // Draw text of ActivePage, because we didn't before. DrawTab(h, r3, false, 2); + Canvas.SetTextColor(ActiveTabTextColor); Canvas.DrawText(r3.left+toffset, r3.Top, r3.Width, r3.Height, ActivePage.Text, lTxtFlags); end; @@ -1079,7 +1110,10 @@ begin // paint text on non-active tabs if h <> ActivePage then + begin + Canvas.SetTextColor(h.TabTextColor); Canvas.DrawText(r2.left+toffset, r2.Top, r2.Width, r2.Height, GetTabText(h.Text), lTxtFlags); + end; r2.Top += r2.Height; lp := r2.Top; if h <> TfpgTabSheet(FPages.Last) then @@ -1096,6 +1130,7 @@ begin // Draw text of ActivePage, because we didn't before. DrawTab(h, r3, false, 2); + Canvas.SetTextColor(ActiveTabTextColor); Canvas.DrawText(r3.left+toffset, r3.Top, r3.Width, r3.Height, ActivePage.Text, lTxtFlags); end; end; { case } @@ -1229,6 +1264,7 @@ begin FTextColor := Parent.TextColor; FBackgroundColor := Parent.BackgroundColor; FActiveTabColor := FBackgroundColor; + FActiveTabTextColor := FTextColor; FFocusable := True; FOnChange := nil; FFixedTabWidth := 0; -- cgit v1.2.3-70-g09d2 From 0e8976c7deb832b59f1d0680332483eb2c4dc679 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Tue, 11 Aug 2015 18:18:45 +0100 Subject: ActiveTabColor/ActiveTabTextColor now defaults to clDefault The problem was that if you didn't specify ActiveTab*Color values, but did specify a Tabsheet to have a different color, when that tabsheet became the active one the color changed to clWindowBackground. This looked odd. Now the ActiveTab*Color = clDefault that tabsheet will still maintain its color, even if it is a background tab or a active tab. When you assign any other color value to ActiveTab*Color (not clDefault), then they will take preference. * Also prevent an error when calling DrawTab with the ATabSheet parameter being nil * refactored some color assignment code --- src/gui/fpg_tab.pas | 57 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/gui/fpg_tab.pas b/src/gui/fpg_tab.pas index dfb55ad2..f15b59fa 100644 --- a/src/gui/fpg_tab.pas +++ b/src/gui/fpg_tab.pas @@ -1,7 +1,7 @@ { fpGUI - Free Pascal GUI Toolkit - Copyright (C) 2006 - 2014 See the file AUTHORS.txt, included in this + Copyright (C) 2006 - 2015 See the file AUTHORS.txt, included in this distribution, for details of the copyright. See the file COPYING.modifiedLGPL, included in this distribution, @@ -135,8 +135,7 @@ type procedure SetTabPosition(const AValue: TfpgTabPosition); procedure DoPageChange(ATabSheet: TfpgTabSheet); procedure DoTabSheetClosing(ATabSheet: TfpgTabSheet); - function DrawTab(const ATabSheet: TfpgTabSheet; const rect: TfpgRect; const Selected: Boolean = False; - const Mode: Integer = 1): TfpgRect; + function DrawTab(const ATabSheet: TfpgTabSheet; const rect: TfpgRect; const Selected: Boolean = False; const Mode: Integer = 1): TfpgRect; procedure pmCloseTab(Sender: TObject); function GetActiveTabColor: TfpgColor; procedure SetActiveTabColor(AValue: TfpgColor); @@ -167,8 +166,8 @@ type property OnClosingTabSheet: TTabSheetClosing read FOnClosingTabSheet write FOnClosingTabSheet; published property ActivePageIndex: integer read GetActivePageIndex write SetActivePageIndex default 0; - property ActiveTabColor: TfpgColor read GetActiveTabColor write SetActiveTabColor default clWindowBackground; - property ActiveTabTextColor: TfpgColor read GetActiveTabTextColor write SetActiveTabTextColor; + property ActiveTabColor: TfpgColor read GetActiveTabColor write SetActiveTabColor default clDefault; + property ActiveTabTextColor: TfpgColor read GetActiveTabTextColor write SetActiveTabTextColor default clDefault; property Align; property BackgroundColor; property Enabled; @@ -670,7 +669,18 @@ function TfpgPageControl.DrawTab(const ATabSheet: TfpgTabSheet; const rect: Tfpg const Mode: Integer = 1): TfpgRect; var r: TfpgRect; + + procedure ApplyCorrectTabColorToCanvas; + begin + if ActiveTabColor = clDefault then + Canvas.SetColor(ATabSheet.TabColor) + else + Canvas.SetColor(ActiveTabColor); + end; + begin + if not Assigned(ATabSheet) then + raise Exception.Create('DrawTab parameter error. ATabSheet may not be nil.'); r := rect; if Selected then begin @@ -684,7 +694,7 @@ begin r.Height -= 1; if TabPosition = tpBottom then r.Top += 1; - Canvas.SetColor(ActiveTabColor); + ApplyCorrectTabColorToCanvas; end else Canvas.SetColor(ATabSheet.TabColor); @@ -719,7 +729,7 @@ begin Canvas.DrawLine(r.Right, r.Bottom-2, r.Right, r.Top-1); // right outer edge if Mode = 2 then { selected tab } begin - Canvas.SetColor(ActiveTabColor); + ApplyCorrectTabColorToCanvas; Canvas.DrawLine(r.Left+1, r.Top-1, r.Right-1, r.Top-1); end; end; @@ -841,6 +851,15 @@ var toffset: integer; lTxtFlags: TfpgTextFlags; ActivePageVisible: Boolean; + + procedure ApplyCorrectTabTextColorToCanvas(ATab: TfpgTabSheet); + begin + if ActiveTabTextColor = clDefault then + Canvas.SetTextColor(ATab.TabTextColor) + else + Canvas.SetTextColor(ActiveTabTextColor); + end; + begin if not HasHandle then Exit; //==> @@ -848,10 +867,10 @@ begin if PageCount = 0 then Exit; //==> - TabW:=FixedTabWidth; - TabH:=FixedTabHeight; + TabW := FixedTabWidth; + TabH := FixedTabHeight; ActivePageVisible := false; - If TabH = 0 then + if TabH <= 1 then TabH := TAB_HEIGHT; h := TfpgTabSheet(FPages.First); if h = nil then @@ -862,7 +881,6 @@ begin if not Enabled then Include(lTxtFlags, txtDisabled); - if TabPosition in [tpTop, tpBottom] then begin if MaxButtonWidthSum > (Width-(FMargin*2)) then @@ -982,9 +1000,11 @@ begin r2.Width := Width; r2.Height := Height - TabH; Canvas.DrawButtonFace(r2, []); + // Draw text of ActivePage, because we didn't before. + h := self.ActivePage; DrawTab(h, r3, false, 2); - Canvas.SetTextColor(ActiveTabTextColor); + ApplyCorrectTabTextColorToCanvas(h); Canvas.DrawText(r3.Left+4, r3.Top+5, r3.Width, r3.Height, ActivePage.Text, lTxtFlags); end; @@ -1031,8 +1051,9 @@ begin Canvas.DrawButtonFace(r2, []); // Draw text of ActivePage, because we didn't before. + h := self.ActivePage; DrawTab(h, r3, false, 2); - Canvas.SetTextColor(ActiveTabTextColor); + ApplyCorrectTabTextColorToCanvas(h); Canvas.DrawText(r3.Left+4, r3.Top+3, r3.Width, r3.Height, ActivePage.Text, lTxtFlags); end; @@ -1080,8 +1101,9 @@ begin Canvas.DrawButtonFace(r2, []); // Draw text of ActivePage, because we didn't before. + h := self.ActivePage; DrawTab(h, r3, false, 2); - Canvas.SetTextColor(ActiveTabTextColor); + ApplyCorrectTabTextColorToCanvas(h); Canvas.DrawText(r3.left+toffset, r3.Top, r3.Width, r3.Height, ActivePage.Text, lTxtFlags); end; @@ -1129,8 +1151,9 @@ begin Canvas.DrawButtonFace(r2, []); // Draw text of ActivePage, because we didn't before. + h := self.ActivePage; DrawTab(h, r3, false, 2); - Canvas.SetTextColor(ActiveTabTextColor); + ApplyCorrectTabTextColorToCanvas(h); Canvas.DrawText(r3.left+toffset, r3.Top, r3.Width, r3.Height, ActivePage.Text, lTxtFlags); end; end; { case } @@ -1263,8 +1286,8 @@ begin FTextColor := Parent.TextColor; FBackgroundColor := Parent.BackgroundColor; - FActiveTabColor := FBackgroundColor; - FActiveTabTextColor := FTextColor; + FActiveTabColor := clDefault; + FActiveTabTextColor := clDefault; FFocusable := True; FOnChange := nil; FFixedTabWidth := 0; -- cgit v1.2.3-70-g09d2