CrabUI
Loading...
Searching...
No Matches
CUIVerticalList.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4
5using Barotrauma;
6using Microsoft.Xna.Framework;
7using Microsoft.Xna.Framework.Input;
8using Microsoft.Xna.Framework.Graphics;
9
10namespace CrabUI
11{
12 /// <summary>
13 /// Resizing components to it's Width and placing them sequentially
14 /// </summary>
16 {
17 [CUISerializable] public bool Scrollable { get; set; }
18 [CUISerializable] public float ScrollSpeed { get; set; } = 1.0f;
19
20 [CUISerializable] public float TopGap { get; set; }
21 [CUISerializable] public float BottomGap { get; set; }
22
23 public override CUILayout Layout
24 {
25 get => layout;
26 set
27 {
28 layout = new CUILayoutVerticalList();
29 layout.Host = this;
30 }
31 }
32 public CUILayoutVerticalList ListLayout => (CUILayoutVerticalList)Layout;
33
34
35 [CUISerializable]
36 public CUIDirection Direction
37 {
38 get => ListLayout.Direction;
39 set => ListLayout.Direction = value;
40 }
41
42 [CUISerializable]
43 public float Gap
44 {
45 get => ListLayout.Gap;
46 set => ListLayout.Gap = value;
47 }
48
49 [CUISerializable]
50 public bool ResizeToHostWidth
51 {
52 get => ListLayout.ResizeToHostWidth;
53 set => ListLayout.ResizeToHostWidth = value;
54 }
55
56 public float Scroll
57 {
58 get => ChildrenOffset.Y;
59 set
60 {
61 if (!Scrollable) return;
62 CUIProps.ChildrenOffset.SetValue(
63 ChildrenOffset with { Y = value }
64 );
65 }
66 }
67
68 internal override CUIBoundaries ChildOffsetBounds => new CUIBoundaries(
69 minX: 0,
70 maxX: 0,
71 maxY: TopGap,
72 minY: Math.Min(Real.Height - ListLayout.TotalHeight - BottomGap, 0)
73 );
74
75
76 public CUIVerticalList() : base()
77 {
78 CullChildren = true;
79
80
81 OnScroll += (m) => Scroll += m.Scroll * ScrollSpeed;
82
83 ChildrenBoundaries = CUIBoundaries.VerticalTube;
84 }
85
86 }
87}
Base class for all components.
CUI3DOffset ChildrenOffset
Will shift all children by this much, e.g. this is how scroll works It's also 3D.
CUIComponentProps CUIProps
Just a wrapper for CUIProps idk how to separate them better.
Definition CUIProps.cs:27
CUIRect Real
Calculated prop, position on real screen in pixels Should be fully calculated after CUIMainComponent....
Func< CUIRect, CUIBoundaries > ChildrenBoundaries
Limits to children positions.
bool CullChildren
if child rect doesn't intersect with parent it won't be drawn and won't consume fps It also sets Hi...
Base class for all layouts.
Definition CUILayout.cs:18
Resizing components to it's Width and placing them sequentially.
Resizing components to it's Width and placing them sequentially.
Defining Boundaries, not the same as rect containing min/max x, y, z.