CODE HERE IS INCOMPLETE BUT IT'S NOT FAR OFF
here we set up a simple ruler using a TPanel,
a TBevel, and two TLabels for wee arrows.
The two labels have one character in, which
is the ò character (from the ext. ASCII set)
-THIS DISPLAYS AS A DOWN ARROW.
with code below, these arrows can be manually
slid along (by dragging)
if, however, you want them to refelect the
current mouse x position then adapt the code
in RULERSTWO.TXT
const
RulerAdj = 4/3;
type
Ruler: TPanel;
RulerLine: TBevel;
RMargSlider: TLabel;
LMargSlider: TLabel;
function headers
procedure SetupRuler;
in FormCreate
{Ruler.Left := Editor.Left;
RulerLine.Left := Editor.Left;}
SetupRuler;
procedures
procedure TEditorForm.SetNewFileMargins;
{this proc is called when a new file is loaded into the Editor, and here we
put both ruler sliders back to the left-hand side, and set the values in the
Margins structure to those determined by settings IN the new file (actually
determined by the underlying RTF tags within the file)...}
begin
LMargSlider.Left := sideLabelWidth;
RMargSlider.Left := sideLabelWidth;
Margins.L := Editor.Paragraph.FirstIndent;
Margins.R := Editor.Paragraph.RightIndent;
end;
procedure TEditorForm.SetDefaultMargins;
begin
Margins.L := defaultLMargin;
Margins.R := defaultRMargin;
LMargSlider.Left := sideLabelWidth;
RMargSlider.Left := sideLabelWidth;
Editor.Paragraph.FirstIndent := Margins.L;
{Editor.Paragraph.RightIndent := Margins.R;}
end;
procedure TEditorForm.SetupRuler;
{here we neatly and succinctly create a string with | characters spaced
at regular intervals such that when we make this string the CAPTION of the
ruler these characters appear as ruler measurement indicators (neat!)...}
const
rulerStrWidth = 640;
var
i, j: Integer;
S: String;
begin
Ruler.Left := Editor.Left + SideLabel.Width;
Ruler.Width := Editor.Width - sideLabelWidth;
RulerLine.Width := Editor.Width - sideLabelWidth;
LMargSlider.Left := Editor.Left;
RMargSlider.Left := Editor.Left - 1;
SetLength(S, rulerStrWidth);
i := 1;
S[i] := #9;
Inc(i);
S[i] := #9;
Inc(i);
while i < (rulerStrWidth - 1) do
begin
S[i] := #9;
Inc(i);
if (i > (rulerStrWidth - 1)) then break;
S[i] := '|';
Inc(i);
end;
Ruler.Caption := S;
{next line assumes both label components
used for ruler silders are the same width...}
HalfSliderWidth := (LMargSlider.Width div 2);
end;
procedure TEditorForm.FormResize(Sender: TObject);
begin
{Editor.Refresh;}
SetUpRuler;
SetEditRect;
end;
procedure TEditorForm.RMargSliderMouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if (RMargSlider.Left > Editor.Width) then
begin
RMargSlider.Left := (Editor.Width - 30);
Margins.R := (Editor.Width - 30);
end;
if (RMargSlider.Left < RulerLine.Left) then
begin
RMargSlider.Left := RulerLine.Left;
Margins.R := defaultRMargin;
end;
FDragging := False;
Editor.SelectAll;
Margins.R := Trunc((Ruler.ClientWidth-RMargSlider.Left+HalfSliderWidth-2) / RulerAdj)
-2*gutterWidth;
Editor.Paragraph.RightIndent := Margins.R;
Editor.SelLength := 0;
end;
procedure TEditorForm.LMargSliderMouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if (LMargSlider.Left > Editor.Width) then
begin
LMargSlider.Left := (Editor.Width - 30);
Margins.L := (Editor.Width - 30);
end;
if (LMargSlider.Left < RulerLine.Left) then
begin
LMargSlider.Left := RulerLine.Left;
Margins.L := 0;
end;
FDragging := False;
Editor.SelectAll;
Margins.L := Trunc((LMargSlider.Left+HalfSliderWidth-gutterWidth) / RulerAdj)
- (sideLabelWidth - 6);
{-Editor.Paragraph.FirstIndent;}
Editor.Paragraph.FirstIndent := Margins.L;
Editor.SelLength := 0;
end;
procedure TEditorForm.RMargSliderMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
RMargSlider.Left := RMargSlider.Left + X - HalfSliderWidth;
FDragging := True;
end;
procedure TEditorForm.RMargSliderMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
if FDragging then RMargSlider.Left := RMargSlider.Left + X - HalfSliderWidth;
end;
procedure TEditorForm.LMargSliderMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
LMargSlider.Left := LMargSlider.Left + X - HalfSliderWidth;
FDragging := True;
end;
procedure TEditorForm.LMargSliderMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
if FDragging then LMargSlider.Left := LMargSlider.Left + X - HalfSliderWidth;
end;
procedure TEditorForm.RMargSliderMouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if (RMargSlider.Left > Editor.Width) then
begin
RMargSlider.Left := (Editor.Width - 30);
Margins.R := (Editor.Width - 30);
end;
if (RMargSlider.Left < RulerLine.Left) then
begin
RMargSlider.Left := RulerLine.Left;
Margins.R := defaultRMargin;
end;
FDragging := False;
Editor.SelectAll;
Margins.R := Trunc((Ruler.ClientWidth-RMargSlider.Left+HalfSliderWidth-2) / RulerAdj)
-2*gutterWidth;
Editor.Paragraph.RightIndent := Margins.R;
Editor.SelLength := 0;
end;
procedure TEditorForm.LMargSliderMouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if (LMargSlider.Left > Editor.Width) then
begin
LMargSlider.Left := (Editor.Width - 30);
Margins.L := (Editor.Width - 30);
end;
if (LMargSlider.Left < RulerLine.Left) then
begin
LMargSlider.Left := RulerLine.Left;
Margins.L := 0;
end;
FDragging := False;
Editor.SelectAll;
Margins.L := Trunc((LMargSlider.Left+HalfSliderWidth-gutterWidth) / RulerAdj)
- (sideLabelWidth - 6);
{-Editor.Paragraph.FirstIndent;}
Editor.Paragraph.FirstIndent := Margins.L;
Editor.SelLength := 0;
end;