CrabUI
Loading...
Searching...
No Matches
CUIHorizontalList.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 Height 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 LeftGap { get; set; } = 0f;
21 [CUISerializable] public float RightGap { get; set; } = 0f;
22
23 public override CUILayout Layout
24 {
25 get => layout;
26 set
27 {
28 layout = new CUILayoutHorizontalList();
29 layout.Host = this;
30 }
31 }
32 public CUILayoutHorizontalList ListLayout => (CUILayoutHorizontalList)Layout;
33
34 [CUISerializable]
35 public CUIDirection Direction
36 {
37 get => ListLayout.Direction;
38 set => ListLayout.Direction = value;
39 }
40
41 //TODO test, sync with vlist
42 [CUISerializable]
43 public float Gap
44 {
45 get => ListLayout.Gap;
46 set => ListLayout.Gap = value;
47 }
48
49 [CUISerializable]
50 public bool ResizeToHostHeight
51 {
52 get => ListLayout.ResizeToHostHeight;
53 set => ListLayout.ResizeToHostHeight = value;
54 }
55
56 public float Scroll
57 {
58 get => ChildrenOffset.X;
59 set
60 {
61 if (!Scrollable) return;
62 CUIProps.ChildrenOffset.SetValue(
63 ChildrenOffset with { X = value }
64 );
65 }
66 }
67
68 internal override CUIBoundaries ChildOffsetBounds => new CUIBoundaries(
69 minY: 0,
70 maxY: 0,
71 minX: LeftGap,
72 maxX: Math.Min(Real.Width - ListLayout.TotalWidth - RightGap, 0)
73 );
74 public CUIHorizontalList() : base()
75 {
76 CullChildren = true;
77
78
79 OnScroll += (m) => Scroll += m.Scroll * ScrollSpeed;
80 ChildrenBoundaries = CUIBoundaries.HorizontalTube;
81 }
82 }
83}
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...
Resizing components to it's Height and placing them sequentially.
Resizing components to it's Height and placing them sequentially.
Base class for all layouts.
Definition CUILayout.cs:18
Defining Boundaries, not the same as rect containing min/max x, y, z.