diff options
author | Rafael Lima <rafael.palma.lima@gmail.com> | 2024-07-16 20:52:28 +0200 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2024-07-22 07:05:00 +0200 |
commit | 180f0c1ec8e195043b5f4298737a219026a8b944 (patch) | |
tree | b8788fb1dd2f2caedb77eeb0e268aedb0c96689a /vcl | |
parent | ba0e0093b0ed2816a18e54eef0a92220d7b04a4d (diff) |
tdf#161501 Improve visuals of selected entries in Vertical tabs
This patch improves the following in vertical tabs:
1) Selected entries are painted natively when possible
2) Entries are a bit taller
3) Text is now vertically centered (for items that are text-only)
4) In native controls a mark is drawn on the selected tab
Change-Id: I42a8e002130030d1484c4149b146258921436af9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170554
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Tested-by: Jenkins
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/control/imivctl.hxx | 4 | ||||
-rw-r--r-- | vcl/source/control/imivctl1.cxx | 57 |
2 files changed, 56 insertions, 5 deletions
diff --git a/vcl/source/control/imivctl.hxx b/vcl/source/control/imivctl.hxx index 9a46b6c1bbc1..8363149bf60e 100644 --- a/vcl/source/control/imivctl.hxx +++ b/vcl/source/control/imivctl.hxx @@ -70,6 +70,10 @@ namespace o3tl { #define VER_DIST_BMP_STRING 3 // width offset of highlight rectangle for Text #define LROFFS_TEXT 2 +// Vertical text padding when the item contains only text +#define VERT_TEXT_PADDING 4 +// Width of the marker used for the selected tab (native controls only) +#define TAB_MARK_WIDTH 3 #define DEFAULT_MAX_VIRT_WIDTH 200 #define DEFAULT_MAX_VIRT_HEIGHT 200 diff --git a/vcl/source/control/imivctl1.cxx b/vcl/source/control/imivctl1.cxx index 4d37fe8c085b..20aeb9839a6c 100644 --- a/vcl/source/control/imivctl1.cxx +++ b/vcl/source/control/imivctl1.cxx @@ -81,7 +81,7 @@ SvxIconChoiceCtrl_Impl::SvxIconChoiceCtrl_Impl( aVisRectChangedIdle.SetInvokeHandler(LINK(this,SvxIconChoiceCtrl_Impl,VisRectChangedHdl)); Clear( true ); - Size gridSize((nWinStyle & WB_DETAILS) ? 150 : 140, (nWinStyle & WB_DETAILS) ? 20 : 70); + Size gridSize((nWinStyle & WB_DETAILS) ? 150 : 140, (nWinStyle & WB_DETAILS) ? 26 : 70); if(pView->GetDPIScaleFactor() > 1) { gridSize.setHeight( gridSize.Height() * ( pView->GetDPIScaleFactor()) ); @@ -990,7 +990,20 @@ void SvxIconChoiceCtrl_Impl::PaintItem(const tools::Rectangle& rRect, { if (eItem == IcnViewFieldType::Text) { - rRenderContext.DrawText(rRect, pEntry->GetText(), nCurTextDrawFlags); + if (nWinBits & WB_DETAILS) + { + // Vertically center text when the entry is text-only + tools::Long nBoundingHeight(CalcBoundingHeight()); + tools::Long nStringHeight = GetItemSize(IcnViewFieldType::Text).Height(); + tools::Long nNewY = (nBoundingHeight - nStringHeight) / 2; + Point aRectTL(rRect.TopLeft().getX(), rRect.TopLeft().getY() + nNewY); + tools::Rectangle aTextRect(aRectTL, rRect.GetSize()); + rRenderContext.DrawText(aTextRect, pEntry->GetText(), nCurTextDrawFlags); + } + else + { + rRenderContext.DrawText(rRect, pEntry->GetText(), nCurTextDrawFlags); + } } else { @@ -1054,9 +1067,38 @@ void SvxIconChoiceCtrl_Impl::PaintEntry(SvxIconChoiceCtrlEntry* pEntry, const Po PaintEmphasis(aTextRect, bSelected, rRenderContext); + // Background of selected entry + tools::Rectangle aFocusRect(CalcFocusRect(pEntry)); + bool bNativeSelection = rRenderContext.IsNativeControlSupported(ControlType::WindowBackground, ControlPart::Entire); if (bSelected) - vcl::RenderTools::DrawSelectionBackground(rRenderContext, *pView, CalcFocusRect(pEntry), - bActiveSelection ? 1 : 2, false, false, false); + { + if (bNativeSelection) + { + ControlState nState = ControlState::ENABLED; + ImplControlValue aControlValue(0); + bNativeSelection = rRenderContext.DrawNativeControl(ControlType::WindowBackground, ControlPart::Entire, + aFocusRect, nState, aControlValue, OUString()); + } + + if (bNativeSelection) + { + // If a native control was drawn, then draw a mark at the left side of the selected tab + aFocusRect.setWidth(TAB_MARK_WIDTH); + Color aOldFillColor(rRenderContext.GetFillColor()); + Color aOldLineColor(rRenderContext.GetLineColor()); + Color aAccentColor(rRenderContext.GetSettings().GetStyleSettings().GetAccentColor()); + rRenderContext.SetFillColor(aAccentColor); + rRenderContext.SetLineColor(aAccentColor); + rRenderContext.DrawRect(aFocusRect); + rRenderContext.SetFillColor(aOldFillColor); + rRenderContext.SetLineColor(aOldLineColor); + } + else + { + vcl::RenderTools::DrawSelectionBackground(rRenderContext, *pView, aFocusRect, + bActiveSelection ? 1 : 2, false, false, false); + } + } if (pEntry->IsFocused()) DrawFocusRect(rRenderContext, pEntry); @@ -1080,6 +1122,11 @@ void SvxIconChoiceCtrl_Impl::PaintEntry(SvxIconChoiceCtrlEntry* pEntry, const Po } PaintItem(aBmpRect, IcnViewFieldType::Image, pEntry, nBmpPaintFlags, rRenderContext); + + // Move text a bit to the right for native controls due to the tab mark (applies to text-only entries) + if (bNativeSelection && (nWinBits & WB_DETAILS)) + aTextRect.SetPos(Point(aTextRect.GetPos().X() + TAB_MARK_WIDTH, aTextRect.GetPos().Y())); + PaintItem(aTextRect, IcnViewFieldType::Text, pEntry, nTextPaintFlags, rRenderContext); rRenderContext.Pop(); @@ -1233,7 +1280,7 @@ tools::Long SvxIconChoiceCtrl_Impl::CalcBoundingHeight() const break; case WB_DETAILS: - nHeight = nStringHeight; + nHeight = nStringHeight + 2 * VERT_TEXT_PADDING;; break; case WB_SMALLICON: |