File size: 4,367 Bytes
d46f4a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package net.minecraft.client.gui.layouts;

import java.util.function.Consumer;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.components.StringWidget;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public class HeaderAndFooterLayout implements Layout {
    public static final int DEFAULT_HEADER_AND_FOOTER_HEIGHT = 33;
    private static final int CONTENT_MARGIN_TOP = 30;
    private final FrameLayout headerFrame = new FrameLayout();
    private final FrameLayout footerFrame = new FrameLayout();
    private final FrameLayout contentsFrame = new FrameLayout();
    private final Screen screen;
    private int headerHeight;
    private int footerHeight;

    public HeaderAndFooterLayout(Screen p_270234_) {
        this(p_270234_, 33);
    }

    public HeaderAndFooterLayout(Screen p_270404_, int p_270984_) {
        this(p_270404_, p_270984_, p_270984_);
    }

    public HeaderAndFooterLayout(Screen p_270083_, int p_270134_, int p_270996_) {
        this.screen = p_270083_;
        this.headerHeight = p_270134_;
        this.footerHeight = p_270996_;
        this.headerFrame.defaultChildLayoutSetting().align(0.5F, 0.5F);
        this.footerFrame.defaultChildLayoutSetting().align(0.5F, 0.5F);
    }

    @Override
    public void setX(int p_270309_) {
    }

    @Override
    public void setY(int p_270318_) {
    }

    @Override
    public int getX() {
        return 0;
    }

    @Override
    public int getY() {
        return 0;
    }

    @Override
    public int getWidth() {
        return this.screen.width;
    }

    @Override
    public int getHeight() {
        return this.screen.height;
    }

    public int getFooterHeight() {
        return this.footerHeight;
    }

    public void setFooterHeight(int p_270260_) {
        this.footerHeight = p_270260_;
    }

    public void setHeaderHeight(int p_270135_) {
        this.headerHeight = p_270135_;
    }

    public int getHeaderHeight() {
        return this.headerHeight;
    }

    public int getContentHeight() {
        return this.screen.height - this.getHeaderHeight() - this.getFooterHeight();
    }

    @Override
    public void visitChildren(Consumer<LayoutElement> p_270213_) {
        this.headerFrame.visitChildren(p_270213_);
        this.contentsFrame.visitChildren(p_270213_);
        this.footerFrame.visitChildren(p_270213_);
    }

    @Override
    public void arrangeElements() {
        int i = this.getHeaderHeight();
        int j = this.getFooterHeight();
        this.headerFrame.setMinWidth(this.screen.width);
        this.headerFrame.setMinHeight(i);
        this.headerFrame.setPosition(0, 0);
        this.headerFrame.arrangeElements();
        this.footerFrame.setMinWidth(this.screen.width);
        this.footerFrame.setMinHeight(j);
        this.footerFrame.arrangeElements();
        this.footerFrame.setY(this.screen.height - j);
        this.contentsFrame.setMinWidth(this.screen.width);
        this.contentsFrame.arrangeElements();
        int k = i + 30;
        int l = this.screen.height - j - this.contentsFrame.getHeight();
        this.contentsFrame.setPosition(0, Math.min(k, l));
    }

    public <T extends LayoutElement> T addToHeader(T p_270636_) {
        return this.headerFrame.addChild(p_270636_);
    }

    public <T extends LayoutElement> T addToHeader(T p_270870_, Consumer<LayoutSettings> p_300314_) {
        return this.headerFrame.addChild(p_270870_, p_300314_);
    }

    public void addTitleHeader(Component p_330651_, Font p_331722_) {
        this.headerFrame.addChild(new StringWidget(p_330651_, p_331722_));
    }

    public <T extends LayoutElement> T addToFooter(T p_270951_) {
        return this.footerFrame.addChild(p_270951_);
    }

    public <T extends LayoutElement> T addToFooter(T p_270362_, Consumer<LayoutSettings> p_301265_) {
        return this.footerFrame.addChild(p_270362_, p_301265_);
    }

    public <T extends LayoutElement> T addToContents(T p_270895_) {
        return this.contentsFrame.addChild(p_270895_);
    }

    public <T extends LayoutElement> T addToContents(T p_270611_, Consumer<LayoutSettings> p_299569_) {
        return this.contentsFrame.addChild(p_270611_, p_299569_);
    }
}