diff --git a/components/nicesidebar/source/NiceSideBar.pas b/components/nicesidebar/source/NiceSideBar.pas index 6a2461061..7f8ee05d3 100644 --- a/components/nicesidebar/source/NiceSideBar.pas +++ b/components/nicesidebar/source/NiceSideBar.pas @@ -304,6 +304,7 @@ type procedure ClearList; procedure ListChange(RebuildItems: Boolean); procedure DoDrawItem(Index: Integer); + procedure InvalidateItem(Index: Integer); // <--- function GetIndexAtPos(X, Y: Integer): Integer; function CreateItem: TSideBarItem; procedure UpdateItem(Index: Integer); @@ -842,8 +843,12 @@ begin begin FItemIndex := P^.ItemIndex; FSubItemIndex := P^.SubIndex; + InvalidateItem(LastSubIndex); + InvalidateItem(i); + { DoDrawItem(LastSubIndex); DoDrawItem(i); + } LastSubIndex := i; end; end; @@ -856,9 +861,14 @@ begin begin if FItems[FItemIndex].FExpanded then begin + InvalidateItem(LastIndex); + InvalidateItem(LastSubIndex); + InvalidateItem(i); + { DoDrawItem(LastIndex); DoDrawItem(LastSubIndex); DoDrawItem(i); + } LastIndex := i; LastSubIndex := -1; end else @@ -872,10 +882,16 @@ begin end else // on sub items begin + InvalidateItem(LastIndex); + InvalidateItem(LastSubIndex); + InvalidateItem(i); + InvalidateItem(i - FSubItemIndex - 1); + { DoDrawItem(LastIndex); DoDrawItem(LastSubIndex); DoDrawItem(i); DoDrawItem(i - FSubItemIndex - 1); + } LastSubIndex := i; LastIndex := i - FSubItemIndex - 1; end; @@ -901,8 +917,12 @@ begin if (HoverIndex <> SCTOPINDEX) then begin HoverIndex := SCTOPINDEX; + InvalidateItem(LastHover); + InvalidateItem(HoverIndex); + { DoDrawItem(LastHover); DoDrawItem(HoverIndex); + } LastHover := SCTOPINDEX; end; Exit; @@ -916,8 +936,12 @@ begin if (HoverIndex <> SCBOTTOMINDEX) then begin HoverIndex := SCBOTTOMINDEX; + InvalidateItem(LastHover); + InvalidateItem(HoverIndex); + { DoDrawItem(LastHover); DoDrawItem(HoverIndex); + } LastHover := SCBOTTOMINDEX; end; Exit; @@ -944,10 +968,11 @@ begin begin HoverIndex := i; if (LastHover >= 0) and (LastHover < FList.Count) - then DoDrawItem(LastHover); + then InvalidateItem(LastHover); //DoDrawItem(LastHover); if (HoverIndex > -1) then begin - DoDrawItem(HoverIndex); + InvalidateItem(HoverIndex); + //DoDrawItem(HoverIndex); P := PSBInfo(FList[i]); if Assigned(FOnHover) then FOnHover(Self, P^.ItemIndex, P^.SubIndex, P^.Caption); @@ -965,7 +990,7 @@ begin begin HoverIndex := -1; if (LastHover >= 0) and (LastHover < FList.Count) - then DoDrawItem(LastHover); + then InvalidateItem(LastHover); //DoDrawItem(LastHover); LastHover := -1; end; if Assigned(FOnHover) @@ -1068,6 +1093,28 @@ begin end; end; +procedure TNiceSideBar.InvalidateItem(Index: Integer); +var + Rc: TRect; + Info: PSBInfo; +begin + if Index = -1 then + exit; + + if Index = SCTOPINDEX then + Rc := ScTop + else + if Index = SCBOTTOMINDEX then + Rc := ScBottom + else + begin + Info := PSBInfo(FList[Index]); + CopyRect(Rc, Info^.Rc); + OffsetRect(Rc, 0, -DeltaY); + end; + InvalidateRect(Handle, @Rc, false); +end; + procedure TNiceSideBar.DoDrawItem(Index: Integer); var Info: PSBInfo; @@ -1622,7 +1669,8 @@ begin Break; end; end; - DoDrawItem(i); + InvalidateItem(i); + //DoDrawItem(i); end; procedure TNiceSideBar.UpdateItems; @@ -1671,8 +1719,12 @@ begin begin if FItems[FItemIndex].FExpanded then begin + InvalidateItem(LastIndex); + InvalidateItem(LastSubIndex); + { DoDrawItem(LastIndex); DoDrawItem(LastSubIndex); + } end else begin FItems[FItemIndex].Expand; @@ -1680,8 +1732,12 @@ begin end; end else begin + InvalidateItem(LastIndex); + InvalidateItem(LastSubIndex); + { DoDrawItem(LastIndex); DoDrawItem(LastSubIndex); + } end; if IsUpdating then @@ -1702,7 +1758,7 @@ begin end; end; if Redraw - then DoDrawItem(LastIndex); + then InvalidateItem(LastIndex); //DoDrawItem(LastIndex); end; end; @@ -1735,10 +1791,11 @@ begin end; end; end; - DoDrawItem(LastSubIndex); + InvalidateItem(LastSubIndex); + //DoDrawItem(LastSubIndex); LastSubIndex := i; if (i > -1) - then DoDrawItem(i); + then InvalidateItem(i); //DoDrawItem(i); end; end; @@ -1969,13 +2026,15 @@ begin begin LastHover := TopIndex; HoverIndex := TopIndex; - DoDrawItem(HoverIndex); + InvalidateItem(HoverIndex); + //DoDrawItem(HoverIndex); end else begin HoverIndex := Min(FList.Count-1, HoverIndex + 1); if (LastHover >= 0) and (LastHover < FList.Count) - then DoDrawItem(LastHover); - DoDrawItem(HoverIndex); + then InvalidateItem(LastHover); //DoDrawItem(LastHover); + InvalidateItem(HoverIndex); + //DoDrawItem(HoverIndex); LastHover := HoverIndex; end; if (HoverIndex >= BottomIndex-1) and ScBottomVisible then @@ -1999,13 +2058,15 @@ begin begin LastHover := BottomIndex; HoverIndex := BottomIndex; - DoDrawItem(HoverIndex); + InvalidateItem(HoverIndex); + //DoDrawItem(HoverIndex); end else begin HoverIndex := Max(0, HoverIndex - 1); if (LastHover >= 0) and (LastHover < FList.Count) - then DoDrawItem(LastHover); - DoDrawItem(HoverIndex); + then InvalidateItem(LastHover); //DoDrawItem(LastHover); + InvalidateItem(HoverIndex); + //DoDrawItem(HoverIndex); LastHover := HoverIndex; end; end else