Skip to content

Commit beeb4e6

Browse files
committed
Add cursors for controls
Have TextEdot use NotAllowed instead of Arrow for Disabled Make ScrollBar use {H,V}Resize Make BaseButton use Pointer/NotAllowed instead of Arrow Make ItemList use NotALlowed/Pointer/Arrow Make MenuTopButton use Pointer Make Slider use HResize Fix SplitContainer not changing DefaultCursorShape if it changed orientation Make Tree use Pointer/Arrow Make TabContainer use Pointer
1 parent 00c1a9f commit beeb4e6

9 files changed

Lines changed: 92 additions & 6 deletions

File tree

Robust.Client/UserInterface/Controls/BaseButton.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public bool Disabled
9090

9191
if (old != value)
9292
{
93+
DefaultCursorShape = Disabled ? CursorShape.NotAllowed : CursorShape.Pointer;
9394
DrawModeChanged();
9495
}
9596
}
@@ -234,6 +235,7 @@ public bool MuteSounds
234235
protected BaseButton()
235236
{
236237
MouseFilter = MouseFilterMode.Stop;
238+
DefaultCursorShape = Disabled ? CursorShape.NotAllowed : CursorShape.Pointer;
237239
}
238240

239241
protected virtual void DrawModeChanged()

Robust.Client/UserInterface/Controls/ItemList.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,16 +595,42 @@ protected internal override void MouseMove(GUIMouseMoveEventArgs args)
595595
{
596596
base.MouseMove(args);
597597

598+
DefaultCursorShape = CursorShape.Arrow;
599+
598600
for (var idx = 0; idx < _itemList.Count; idx++)
599601
{
600602
var item = _itemList[idx];
601603
if (item.Region == null) continue;
602604
if (!item.Region.Value.Contains(args.RelativePosition)) continue;
605+
606+
if (SelectMode != ItemListSelectMode.None)
607+
{
608+
if (item.Disabled)
609+
{
610+
DefaultCursorShape = CursorShape.NotAllowed;
611+
}
612+
else if (item.Selectable)
613+
{
614+
DefaultCursorShape = CursorShape.Pointer;
615+
}
616+
else
617+
{
618+
DefaultCursorShape = CursorShape.Arrow;
619+
}
620+
}
621+
603622
OnItemHover?.Invoke(new ItemListHoverEventArgs(idx, this));
604623
break;
605624
}
606625
}
607626

627+
protected internal override void MouseExited()
628+
{
629+
base.MouseExited();
630+
631+
DefaultCursorShape = CursorShape.Arrow;
632+
}
633+
608634
protected internal override void MouseWheel(GUIMouseWheelEventArgs args)
609635
{
610636
base.MouseWheel(args);

Robust.Client/UserInterface/Controls/MenuBar.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ public abstract class MenuTopButton : PanelContainer
235235
public MenuTopButton(Menu menu)
236236
{
237237
MouseFilter = MouseFilterMode.Pass;
238+
DefaultCursorShape = CursorShape.Pointer;
238239
ChildMenu = menu;
239240
}
240241

Robust.Client/UserInterface/Controls/ScrollBar.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ protected ScrollBar(OrientationMode orientation)
4545
ReservesSpace = true;
4646

4747
_orientation = orientation;
48+
DefaultCursorShape = orientation == OrientationMode.Horizontal
49+
? CursorShape.HResize
50+
: CursorShape.VResize;
4851
}
4952

5053
public bool IsAtEnd

Robust.Client/UserInterface/Controls/Slider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public StyleBox? GrabberStyleBoxOverride
8181
public Slider()
8282
{
8383
MouseFilter = MouseFilterMode.Stop;
84+
DefaultCursorShape = CursorShape.HResize;
8485

8586
AddChild(new LayoutContainer
8687
{

Robust.Client/UserInterface/Controls/SplitContainer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public SplitOrientation Orientation
176176
set
177177
{
178178
_orientation = value;
179+
_splitDragArea.DefaultCursorShape = Vertical ? CursorShape.VResize : CursorShape.HResize;
179180
InvalidateMeasure();
180181
}
181182
}
@@ -185,7 +186,7 @@ public SplitContainer()
185186
MouseFilter = MouseFilterMode.Stop;
186187
AddChild(_splitDragArea);
187188
_splitDragArea.Visible = _resizeMode != SplitResizeMode.NotResizable;
188-
_splitDragArea.DefaultCursorShape = Vertical ? CursorShape.VResize : CursorShape.HResize;
189+
_splitDragArea.DefaultCursorShape = Vertical ? CursorShape.VResize : CursorShape.HResize;
189190
_splitDragArea.OnMouseUp += StopDragging;
190191
_splitDragArea.OnMouseDown += StartDragging;
191192
_splitDragArea.OnMouseMove += OnMove;

Robust.Client/UserInterface/Controls/TabContainer.cs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
34
using System.Numerics;
45
using Robust.Client.Graphics;
56
using Robust.Shared.Input;
@@ -325,14 +326,49 @@ protected internal override void KeyBindDown(GUIBoundKeyEventArgs args)
325326

326327
args.Handle();
327328

329+
if (!TryGetHoveredTab(args.RelativePixelPosition, out var index))
330+
{
331+
return;
332+
}
333+
334+
CurrentTab = index.Value;
335+
}
336+
337+
protected internal override void MouseMove(GUIMouseMoveEventArgs args)
338+
{
339+
base.MouseMove(args);
340+
341+
DefaultCursorShape = TryGetHoveredTab(args.RelativePixelPosition, out _)
342+
? CursorShape.Pointer
343+
: CursorShape.Arrow;
344+
}
345+
346+
protected internal override void MouseExited()
347+
{
348+
base.MouseExited();
349+
350+
DefaultCursorShape = CursorShape.Arrow;
351+
}
352+
353+
private bool TryGetHoveredTab(Vector2 position, [NotNullWhen(true)] out int? index)
354+
{
355+
index = null;
356+
357+
if (!TabsVisible || position.Y < 0 || position.Y > _enclosingTabHeight)
358+
{
359+
return false;
360+
}
361+
328362
foreach (var box in _tabBoxes)
329363
{
330-
if (box.Bounding.Contains(args.RelativePixelPosition))
364+
if (box.Bounding.Contains(position))
331365
{
332-
CurrentTab = box.Index;
333-
return;
366+
index = box.Index;
367+
return true;
334368
}
335369
}
370+
371+
return false;
336372
}
337373

338374
[System.Diagnostics.Contracts.Pure]

Robust.Client/UserInterface/Controls/TextEdit.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public TextEdit()
100100
CanKeyboardFocus = true;
101101
KeyboardFocusOnClick = true;
102102
MouseFilter = MouseFilterMode.Stop;
103-
DefaultCursorShape = CursorShape.IBeam;
103+
DefaultCursorShape = Editable ? CursorShape.IBeam : CursorShape.NotAllowed;
104104
}
105105

106106
/// <summary>
@@ -171,7 +171,7 @@ public bool Editable
171171
set
172172
{
173173
_editable = value;
174-
DefaultCursorShape = _editable ? CursorShape.IBeam : CursorShape.Arrow;
174+
DefaultCursorShape = _editable ? CursorShape.IBeam : CursorShape.NotAllowed;
175175
UpdatePseudoClass();
176176
}
177177
}

Robust.Client/UserInterface/Controls/Tree.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,22 @@ protected internal override void KeyBindDown(GUIBoundKeyEventArgs args)
106106
}
107107
}
108108

109+
protected internal override void MouseMove(GUIMouseMoveEventArgs args)
110+
{
111+
base.MouseMove(args);
112+
113+
DefaultCursorShape = _tryFindItemAtPosition(args.RelativePixelPosition)?.Selectable == true
114+
? CursorShape.Pointer
115+
: CursorShape.Arrow;
116+
}
117+
118+
protected internal override void MouseExited()
119+
{
120+
base.MouseExited();
121+
122+
DefaultCursorShape = CursorShape.Arrow;
123+
}
124+
109125
private Item? _tryFindItemAtPosition(Vector2 position)
110126
{
111127
var font = _getFont();

0 commit comments

Comments
 (0)