CrabUI
Loading...
Searching...
No Matches
CUIFrame.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 /// Draggable and resizable container for other components
14 /// </summary>
15 public class CUIFrame : CUIComponent
16 {
17 public event Action OnOpen;
18 public event Action OnClose;
19
20 [CUISerializable] public bool MoveToFrontOnClick { get; set; } = true;
21
22 /// <summary>
23 /// This will reveal the frame and append it to CUI.Main
24 /// </summary>
25 public void Open(CUIComponent Host = null)
26 {
27 Host ??= CUI.Main;
28 if (Host == null || Parent == Host) return;
29
30 Host.Append(this);
31 Revealed = true;
32 OnOpen?.Invoke();
33 }
34
35 /// <summary>
36 /// This will hide the frame and remove it from children of CUI.Main
37 /// </summary>
38 public void Close()
39 {
40 RemoveSelf();
41 Revealed = false;
42 OnClose?.Invoke();
43 }
44
45 public CUIFrame() : base()
46 {
47 CullChildren = true;
48 Resizible = true;
49 Draggable = true;
50 ConsumeMouseClicks = true;
51
52 //TODO remove this temporary workaround after events rework
53 OnMouseDown += (e) =>
54 {
55 if (MoveToFrontOnClick && CUI.Main.MouseOn == this) MoveToFront();
56 };
57
58 //From CUICloseButton
59 AddCommand("Close Frame", (o) => Close());
60 }
61
62 public CUIFrame(float? x = null, float? y = null, float? w = null, float? h = null) : this()
63 {
64 Relative = new CUINullRect(x, y, w, h);
65 }
66 }
67}
Base class for all components.
void MoveToFront()
Moves component to front in Parent.Children which makes it render after other childs.
bool Revealed
Visible + !IgnoreEvents.
CUINullRect Relative
Relative to parent size and position, [0..1].
virtual CUIComponent Append(CUIComponent child, string name=null, [CallerMemberName] string memberName="")
Adds children to the end of the list.
void AddCommand(string name, Action< object > action)
Manually adds command.
bool CullChildren
if child rect doesn't intersect with parent it won't be drawn and won't consume fps It also sets Hi...
Draggable and resizable container for other components.
Definition CUIFrame.cs:16
void Open(CUIComponent Host=null)
This will reveal the frame and append it to CUI.Main.
Definition CUIFrame.cs:25
void Close()
This will hide the frame and remove it from children of CUI.Main.
Definition CUIFrame.cs:38
In fact a static class managing static things.
Definition CUIErrors.cs:16
static CUIMainComponent Main
Orchestrates Drawing and updates, there could be only one CUI.Main is located under vanilla GUI.
Definition CUI.cs:84