我正在尝试通过减少执行某些操作所需的点击量来改进 GUI。但是,困扰我的一个 VCL 组件是 TValueListEditor,它包含一个键和值列表,所有这些都由下拉列表控制。选择一个选项总是需要点击三下,而只需要两下:
此时,最上面一行有焦点,可以使用下拉菜单更改值(单击两次)。但是,当用户想要编辑不同的键时,他首先必须将焦点更改为该键,然后才能使用下拉菜单(单击三下)。
有没有办法在所有行上显示下拉箭头以防止额外的点击?
这是我想要实现的模型示例:
我正在尝试通过减少执行某些操作所需的点击量来改进 GUI。但是,困扰我的一个 VCL 组件是 TValueListEditor,它包含一个键和值列表,所有这些都由下拉列表控制。选择一个选项总是需要点击三下,而只需要两下:
此时,最上面一行有焦点,可以使用下拉菜单更改值(单击两次)。但是,当用户想要编辑不同的键时,他首先必须将焦点更改为该键,然后才能使用下拉菜单(单击三下)。
有没有办法在所有行上显示下拉箭头以防止额外的点击?
这是我想要实现的模型示例:
uses
Vcl.Themes;
type
TValueListEditor = class(Vcl.ValEdit.TValueListEditor)
private
procedure DrawDropDownButton(ACol, ARow: Integer; ARect: TRect;
AState: TGridDrawState);
function MouseOverButton(X: Integer): Boolean;
protected
procedure DrawCell(ACol, ARow: Integer; ARect: TRect;
AState: TGridDrawState); override;
procedure DrawCellHighlight(const ARect: TRect; AState: TGridDrawState;
ACol, ARow: Integer); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer); override;
end;
{ TValueListEditor }
type
TInplaceEditListAccess = class(Vcl.Grids.TInplaceEditList);
procedure TValueListEditor.DrawCell(ACol, ARow: Integer; ARect: TRect;
AState: TGridDrawState);
begin
inherited DrawCell(ACol, ARow, ARect, AState);
DrawDropDownButton(ACol, ARow, ARect, AState);
end;
procedure TValueListEditor.DrawCellHighlight(const ARect: TRect;
AState: TGridDrawState; ACol, ARow: Integer);
var
R: TRect;
begin
R := ARect;
if ItemProps[ARow - FixedRows].HasPickList then
Dec(R.Right, EditList.ButtonWidth);
inherited DrawCellHighLight(R, AState, ACol, ARow);
DrawDropDownButton(ACol, ARow, ARect, AState);
end;
procedure TValueListEditor.DrawDropDownButton(ACol, ARow: Integer;
ARect: TRect; AState: TGridDrawState);
var
Details: TThemedElementDetails;
begin
if (ACol = 1) and (ARow >= FixedRows) and not (gdFocused in AState) and
ItemProps[ARow - FixedRows].HasPickList then
begin
ARect.Left := ARect.Right - EditList.ButtonWidth;
Details := StyleServices.GetElementDetails(tgDropDownButtonNormal);
StyleServices.DrawElement(Canvas.Handle, Details, ARect);
end;
end;
procedure TValueListEditor.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
var
ACol: Integer;
ARow: Integer;
begin
inherited MouseDown(Button, Shift, X, Y);
MouseToCell(X, Y, ACol, ARow);
if (Button = mbLeft) and (ARow > FixedRows) and
ItemProps[ARow - FixedRows].HasPickList and
not EditList.ListVisible and MouseOverButton(X) then
begin
EditorMode := True;
TInplaceEditListAccess(EditList).DropDown;
end;
end;
function TValueListEditor.MouseOverButton(X: Integer): Boolean;
begin
Result := (UseRightToLeftAlignment and (X < EditList.ButtonWidth)) or
(not UseRightToLeftAlignment and (X > ClientWidth - EditList.ButtonWidth));
end;