浏览代码

scroll: started buttons

mattias 4 月之前
父节点
当前提交
a51fbfc155
共有 4 个文件被更改,包括 82 次插入40 次删除
  1. 15 5
      demo/ScrollBox/MainUnit.lfm
  2. 21 4
      demo/ScrollBox/MainUnit.pas
  3. 10 0
      src/base/fresnel.dom.pas
  4. 36 31
      src/base/fresnel.renderer.pas

+ 15 - 5
demo/ScrollBox/MainUnit.lfm

@@ -3,7 +3,7 @@ object MainForm: TMainForm
   FormLeft = 450
   FormLeft = 450
   FormTop = 100
   FormTop = 100
   FormWidth = 350
   FormWidth = 350
-  FormHeight = 555
+  FormHeight = 605
   Stylesheet.Strings = (
   Stylesheet.Strings = (
     '#ScrollDiv1 {'
     '#ScrollDiv1 {'
     '  padding: 5px; '
     '  padding: 5px; '
@@ -14,7 +14,7 @@ object MainForm: TMainForm
   OnCreate = MainFormCreate
   OnCreate = MainFormCreate
   Visible = true
   Visible = true
   object Body1: TBody
   object Body1: TBody
-    style = 'font-size: 15px;'
+    style = 'font-size: 14px;'
     object ScrollDiv1: TDiv
     object ScrollDiv1: TDiv
       Style = 'background-color: blue;'#10'border-color: black;'#10'height:50px;'
       Style = 'background-color: blue;'#10'border-color: black;'#10'height:50px;'
       object Label1: TLabel
       object Label1: TLabel
@@ -100,21 +100,31 @@ object MainForm: TMainForm
         Caption = 'Overlay'
         Caption = 'Overlay'
         OnClick = OnOverlayClicked
         OnClick = OnOverlayClicked
       end
       end
-      object ThinCheckBox: TDemoCheckBox
+      object HaveButtonsCheckBox: TDemoCheckBox
         Style = 'margin: 6px;'
         Style = 'margin: 6px;'
-        Caption = 'Thin (scrollbar-width)'
-        OnClick = OnThinClicked
+        Caption = 'Have Buttons'
+        OnClick = OnHaveButtonsClicked
       end
       end
       object RTLCheckBox: TDemoCheckBox
       object RTLCheckBox: TDemoCheckBox
         Style = 'margin: 6px;'
         Style = 'margin: 6px;'
         Caption = 'RTL (direction)'
         Caption = 'RTL (direction)'
         OnClick = OnRTLClicked
         OnClick = OnRTLClicked
       end
       end
+      object ThinCheckBox: TDemoCheckBox
+        Style = 'margin: 6px;'
+        Caption = 'Thin (scrollbar-width)'
+        OnClick = OnThinClicked
+      end
       object BothEdgesCheckBox: TDemoCheckBox
       object BothEdgesCheckBox: TDemoCheckBox
         Style = 'margin: 6px;'
         Style = 'margin: 6px;'
         Caption = 'Both Edges (scrollbar-gutter)'
         Caption = 'Both Edges (scrollbar-gutter)'
         OnClick = OnBothEdgesClicked
         OnClick = OnBothEdgesClicked
       end
       end
+      object ColorCheckBox: TDemoCheckBox
+        Style = 'margin: 6px;'
+        Caption = 'Color (scrollbar-color)'
+        OnClick = OnColorClicked
+      end
     end
     end
   end
   end
 end
 end

+ 21 - 4
demo/ScrollBox/MainUnit.pas

@@ -36,17 +36,21 @@ type
     OverflowYAuto: TDemoRadioButton;
     OverflowYAuto: TDemoRadioButton;
     AutoHideCheckBox: TDemoCheckBox;
     AutoHideCheckBox: TDemoCheckBox;
     OverlayCheckBox: TDemoCheckBox;
     OverlayCheckBox: TDemoCheckBox;
-    ThinCheckBox: TDemoCheckBox;
+    HaveButtonsCheckBox: TDemoCheckBox;
     RTLCheckBox: TDemoCheckBox;
     RTLCheckBox: TDemoCheckBox;
+    ThinCheckBox: TDemoCheckBox;
     BothEdgesCheckBox: TDemoCheckBox;
     BothEdgesCheckBox: TDemoCheckBox;
+    ColorCheckBox: TDemoCheckBox;
     procedure MainFormCreate(Sender: TObject);
     procedure MainFormCreate(Sender: TObject);
     procedure OnAutoHideClicked(Event : TAbstractEvent);
     procedure OnAutoHideClicked(Event : TAbstractEvent);
     procedure OnOverflowXClicked(Event : TAbstractEvent);
     procedure OnOverflowXClicked(Event : TAbstractEvent);
     procedure OnOverflowYClicked(Event : TAbstractEvent);
     procedure OnOverflowYClicked(Event : TAbstractEvent);
     procedure OnOverlayClicked(Event : TAbstractEvent);
     procedure OnOverlayClicked(Event : TAbstractEvent);
-    procedure OnThinClicked(Event : TAbstractEvent);
+    procedure OnHaveButtonsClicked(Event : TAbstractEvent);
     procedure OnRTLClicked(Event : TAbstractEvent);
     procedure OnRTLClicked(Event : TAbstractEvent);
+    procedure OnThinClicked(Event : TAbstractEvent);
     procedure OnBothEdgesClicked(Event : TAbstractEvent);
     procedure OnBothEdgesClicked(Event : TAbstractEvent);
+    procedure OnColorClicked(Event : TAbstractEvent);
   private
   private
   public
   public
     procedure ApplyScrollbarGutter;
     procedure ApplyScrollbarGutter;
@@ -69,12 +73,12 @@ begin
   OverflowXAuto.Checked:=true;
   OverflowXAuto.Checked:=true;
   OverflowYAuto.Checked:=true;
   OverflowYAuto.Checked:=true;
 
 
-  OverlayCheckBox.Checked:=ScrollbarsOverlay;
   AutoHideCheckBox.Checked:=ScrollbarsAutoHide;
   AutoHideCheckBox.Checked:=ScrollbarsAutoHide;
+  HaveButtonsCheckBox.Checked:=ScrollbarsHaveButtons;
+  OverlayCheckBox.Checked:=ScrollbarsOverlay;
 
 
   // todo: step buttons
   // todo: step buttons
   // todo: stable
   // todo: stable
-  // todo: scrollbar-color: red #f004
 end;
 end;
 
 
 procedure TMainForm.OnAutoHideClicked(Event: TAbstractEvent);
 procedure TMainForm.OnAutoHideClicked(Event: TAbstractEvent);
@@ -105,6 +109,11 @@ begin
   ScrollbarsOverlay:=OverlayCheckBox.Checked;
   ScrollbarsOverlay:=OverlayCheckBox.Checked;
 end;
 end;
 
 
+procedure TMainForm.OnHaveButtonsClicked(Event: TAbstractEvent);
+begin
+  ScrollbarsHaveButtons:=HaveButtonsCheckBox.Checked;
+end;
+
 procedure TMainForm.OnThinClicked(Event: TAbstractEvent);
 procedure TMainForm.OnThinClicked(Event: TAbstractEvent);
 begin
 begin
   if ThinCheckBox.Checked then
   if ThinCheckBox.Checked then
@@ -126,6 +135,14 @@ begin
   ApplyScrollbarGutter;
   ApplyScrollbarGutter;
 end;
 end;
 
 
+procedure TMainForm.OnColorClicked(Event: TAbstractEvent);
+begin
+  if ColorCheckBox.Checked then
+    ScrollDiv1.SetStyleAttr('scrollbar-color','red #f006')
+  else
+    ScrollDiv1.SetStyleAttr('scrollbar-color','');
+end;
+
 procedure TMainForm.ApplyScrollbarGutter;
 procedure TMainForm.ApplyScrollbarGutter;
 var
 var
   s: String;
   s: String;

+ 10 - 0
src/base/fresnel.dom.pas

@@ -1676,6 +1676,7 @@ type
     FLayouter: TFresnelLayouter;
     FLayouter: TFresnelLayouter;
     FOnDomChanged: TNotifyEvent;
     FOnDomChanged: TNotifyEvent;
     FScrollbarsAutoHide: boolean;
     FScrollbarsAutoHide: boolean;
+    FScrollbarsHaveButtons: boolean;
     FScrollbarsOverlay: boolean;
     FScrollbarsOverlay: boolean;
     FScrollbarsThinWidth: array[boolean] of TFresnelLength;
     FScrollbarsThinWidth: array[boolean] of TFresnelLength;
     FScrollbarsWidth: array[boolean] of TFresnelLength;
     FScrollbarsWidth: array[boolean] of TFresnelLength;
@@ -1691,6 +1692,7 @@ type
     procedure SetScrollbarsAutoHide(AValue: boolean);
     procedure SetScrollbarsAutoHide(AValue: boolean);
     procedure SetScrollbarsColors(Col: TFresnelScrollbarColor; AValue: TFPColor
     procedure SetScrollbarsColors(Col: TFresnelScrollbarColor; AValue: TFPColor
       );
       );
+    procedure SetScrollbarsHaveButtons(AValue: boolean);
   protected
   protected
     class var FFresnelEventsRegistered: boolean;
     class var FFresnelEventsRegistered: boolean;
   protected
   protected
@@ -1820,6 +1822,7 @@ type
     property DPI[IsHorizontal: boolean]: TFresnelLength read GetDPI write SetDPI;
     property DPI[IsHorizontal: boolean]: TFresnelLength read GetDPI write SetDPI;
 
 
     property ScrollbarsAutoHide: boolean read FScrollbarsAutoHide write SetScrollbarsAutoHide;
     property ScrollbarsAutoHide: boolean read FScrollbarsAutoHide write SetScrollbarsAutoHide;
+    property ScrollbarsHaveButtons: boolean read FScrollbarsHaveButtons write SetScrollbarsHaveButtons;
     property ScrollbarsOverlay: boolean read FScrollbarsOverlay write SetScrollbarsOverlay;
     property ScrollbarsOverlay: boolean read FScrollbarsOverlay write SetScrollbarsOverlay;
     property ScrollbarsWidth[IsHorizontal: boolean]: TFresnelLength read GetScrollbarsWidth write SetScrollbarsWidth;
     property ScrollbarsWidth[IsHorizontal: boolean]: TFresnelLength read GetScrollbarsWidth write SetScrollbarsWidth;
     property ScrollbarsThinWidth[IsHorizontal: boolean]: TFresnelLength read GetScrollbarsThinWidth write SetScrollbarsThinWidth;
     property ScrollbarsThinWidth[IsHorizontal: boolean]: TFresnelLength read GetScrollbarsThinWidth write SetScrollbarsThinWidth;
@@ -6738,6 +6741,13 @@ begin
   Invalidate;
   Invalidate;
 end;
 end;
 
 
+procedure TFresnelViewport.SetScrollbarsHaveButtons(AValue: boolean);
+begin
+  if FScrollbarsHaveButtons=AValue then Exit;
+  FScrollbarsHaveButtons:=AValue;
+  Invalidate;
+end;
+
 function TFresnelViewport.GetDPI(IsHorizontal: boolean): TFresnelLength;
 function TFresnelViewport.GetDPI(IsHorizontal: boolean): TFresnelLength;
 begin
 begin
   Result:=FDPI[IsHorizontal];
   Result:=FDPI[IsHorizontal];

+ 36 - 31
src/base/fresnel.renderer.pas

@@ -714,7 +714,7 @@ var
   LNode: TUsedLayoutNode;
   LNode: TUsedLayoutNode;
   BarWidth, BarHeight: TFresnelLength;
   BarWidth, BarHeight: TFresnelLength;
   r, aPaddingBox: TFresnelRect;
   r, aPaddingBox: TFresnelRect;
-  aScrollbar: TRendererScrollBar;
+  HorzScrollbar, VertScrollbar: TRendererScrollBar;
   IsLeft, HasVertBar, HasHorzBar: Boolean;
   IsLeft, HasVertBar, HasHorzBar: Boolean;
   VP: TFresnelViewport;
   VP: TFresnelViewport;
 begin
 begin
@@ -741,7 +741,7 @@ begin
   aPaddingBox:=El.GetUsedPaddingBox;
   aPaddingBox:=El.GetUsedPaddingBox;
   //writeln('TFresnelRenderer.DrawScrollBars ',El.Name,' PaddingBox=',aPaddingBox.ToString);
   //writeln('TFresnelRenderer.DrawScrollBars ',El.Name,' PaddingBox=',aPaddingBox.ToString);
 
 
-  aScrollbar:=TRendererScrollBar(El.ScrollBarVertical);
+  VertScrollbar:=TRendererScrollBar(El.ScrollBarVertical);
   if HasVertBar then
   if HasVertBar then
   begin
   begin
     r:=aPaddingBox;
     r:=aPaddingBox;
@@ -753,24 +753,24 @@ begin
       r.Bottom:=Max(r.Top,r.Bottom-BarHeight);
       r.Bottom:=Max(r.Top,r.Bottom-BarHeight);
 
 
     if r.IsEmpty then
     if r.IsEmpty then
-      aScrollbar.Free
+      VertScrollbar.Free
     else begin
     else begin
-      if aScrollbar=nil then
-        aScrollbar:=CreateScrollBar(El,false);
-      aScrollbar.Size:=LNode.ScrollHeight;
-      aScrollbar.Page:=El.ClientHeight;
-      aScrollbar.Position:=El.ScrollTop;
-      aScrollbar.Box:=r;
-      aScrollbar.HasColor:=El.GetComputedScrollbarColor(aScrollbar.ThumbColor,aScrollbar.TrackColor);
+      if VertScrollbar=nil then
+        VertScrollbar:=CreateScrollBar(El,false);
+      VertScrollbar.Size:=LNode.ScrollHeight;
+      VertScrollbar.Page:=El.ClientHeight;
+      VertScrollbar.Position:=El.ScrollTop;
+      VertScrollbar.Box:=r;
+      VertScrollbar.HasColor:=El.GetComputedScrollbarColor(VertScrollbar.ThumbColor,VertScrollbar.TrackColor);
 
 
       {$IFDEF VerboseFresnelScrolling}
       {$IFDEF VerboseFresnelScrolling}
       writeln('TFresnelRenderer.DrawScrollBars ',El.Name,' Vertical ScrollHeight=',FloatToCSSStr(El.ScrollHeight),' ClientHeight=',FloatToCSSStr(El.ClientHeight),' ScrollTop=',FloatToCSSStr(El.ScrollTop)+' BarWidth='+FloatToCSSStr(BarWidth)+' r='+r.ToString);
       writeln('TFresnelRenderer.DrawScrollBars ',El.Name,' Vertical ScrollHeight=',FloatToCSSStr(El.ScrollHeight),' ClientHeight=',FloatToCSSStr(El.ClientHeight),' ScrollTop=',FloatToCSSStr(El.ScrollTop)+' BarWidth='+FloatToCSSStr(BarWidth)+' r='+r.ToString);
       {$ENDIF}
       {$ENDIF}
     end;
     end;
-  end else if aScrollbar<>nil then
-    aScrollbar.Free;
+  end else if VertScrollbar<>nil then
+    VertScrollbar.Free;
 
 
-  aScrollbar:=TRendererScrollBar(El.ScrollBarHorizontal);
+  HorzScrollbar:=TRendererScrollBar(El.ScrollBarHorizontal);
   if HasHorzBar then
   if HasHorzBar then
   begin
   begin
     r:=aPaddingBox;
     r:=aPaddingBox;
@@ -784,25 +784,24 @@ begin
     end;
     end;
 
 
     if r.IsEmpty then
     if r.IsEmpty then
-      aScrollbar.Free
+      HorzScrollbar.Free
     else begin
     else begin
-      if aScrollbar=nil then
-        aScrollbar:=CreateScrollBar(El,true);
-      aScrollbar.Size:=LNode.ScrollWidth;
-      aScrollbar.Page:=El.ClientWidth;
+      if HorzScrollbar=nil then
+        HorzScrollbar:=CreateScrollBar(El,true);
+      HorzScrollbar.Size:=LNode.ScrollWidth;
+      HorzScrollbar.Page:=El.ClientWidth;
       if El.ComputedDirection=CSSRegistry.kwRTL then
       if El.ComputedDirection=CSSRegistry.kwRTL then
-        aScrollbar.Position:=El.ScrollLeft+aScrollbar.Size-aScrollbar.Page
+        HorzScrollbar.Position:=El.ScrollLeft+HorzScrollbar.Size-HorzScrollbar.Page
       else
       else
-        aScrollbar.Position:=El.ScrollLeft;
-      aScrollbar.Box:=r;
-      aScrollbar.HasColor:=El.GetComputedScrollbarColor(aScrollbar.ThumbColor,aScrollbar.TrackColor);
+        HorzScrollbar.Position:=El.ScrollLeft;
+      HorzScrollbar.Box:=r;
 
 
       {$IFDEF VerboseFresnelScrolling}
       {$IFDEF VerboseFresnelScrolling}
       writeln('TFresnelRenderer.DrawScrollBars ',El.Name,' Horizontal ScrollWidth=',FloatToCSSStr(El.ScrollWidth),' ClientWidth=',FloatToCSSStr(El.ClientWidth),' ScrollLeft=',FloatToCSSStr(El.ScrollLeft)+' BarHeight='+FloatToCSSStr(BarHeight)+' r='+r.ToString);
       writeln('TFresnelRenderer.DrawScrollBars ',El.Name,' Horizontal ScrollWidth=',FloatToCSSStr(El.ScrollWidth),' ClientWidth=',FloatToCSSStr(El.ClientWidth),' ScrollLeft=',FloatToCSSStr(El.ScrollLeft)+' BarHeight='+FloatToCSSStr(BarHeight)+' r='+r.ToString);
       {$ENDIF}
       {$ENDIF}
     end;
     end;
-  end else if aScrollbar<>nil then
-    aScrollbar.Free;
+  end else if HorzScrollbar<>nil then
+    HorzScrollbar.Free;
 
 
   if HasVertBar or HasHorzBar then
   if HasVertBar or HasHorzBar then
   begin
   begin
@@ -813,15 +812,21 @@ begin
         and (VP.GetFirstPointerCaptureEl(El)=nil)
         and (VP.GetFirstPointerCaptureEl(El)=nil)
     then
     then
       exit;
       exit;
-    if HasHorzBar then
+    if HorzScrollbar<>nil then
     begin
     begin
-      aScrollbar:=TRendererScrollBar(El.ScrollBarHorizontal);
-      aScrollbar.Draw(Self);
+      HorzScrollbar.HasColor:=El.GetComputedScrollbarColor(HorzScrollbar.ThumbColor,HorzScrollbar.TrackColor);
+      HorzScrollbar.Draw(Self);
     end;
     end;
-    if HasVertBar then
+    if VertScrollbar<>nil then
     begin
     begin
-      aScrollbar:=TRendererScrollBar(El.ScrollBarVertical);
-      aScrollbar.Draw(Self);
+      if HorzScrollbar<>nil then
+      begin
+        VertScrollbar.HasColor:=HorzScrollbar.HasColor;
+        VertScrollbar.ThumbColor:=HorzScrollbar.ThumbColor;
+        VertScrollbar.TrackColor:=HorzScrollbar.TrackColor;
+      end else
+        VertScrollbar.HasColor:=El.GetComputedScrollbarColor(VertScrollbar.ThumbColor,VertScrollbar.TrackColor);
+      VertScrollbar.Draw(Self);
     end;
     end;
     if HasVertBar and HasHorzBar then
     if HasVertBar and HasHorzBar then
     begin
     begin
@@ -836,7 +841,7 @@ begin
         r.Left:=Max(aPaddingBox.Left,r.Right-BarWidth);
         r.Left:=Max(aPaddingBox.Left,r.Right-BarWidth);
       end;
       end;
       if not r.IsEmpty then
       if not r.IsEmpty then
-        aScrollbar.DrawCorner(Self,r);
+        HorzScrollbar.DrawCorner(Self,r);
     end;
     end;
   end;
   end;
 end;
 end;