mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-23 13:18:35 +01:00
Compare commits
No commits in common. "a58470de9fdc0ab46222df2f378c3b2d312bf676" and "dbd52d5b9d1c3b113860a6bb42e7f1728f5ce8d8" have entirely different histories.
a58470de9f
...
dbd52d5b9d
3 changed files with 3 additions and 18 deletions
|
@ -13,7 +13,7 @@ protected override void LoadContent() {
|
||||||
// Load your other content here
|
// Load your other content here
|
||||||
|
|
||||||
// Initialize the Ui system
|
// Initialize the Ui system
|
||||||
this.UiSystem = new UiSystem(this, this.GraphicsDevice, new UntexturedStyle(this.SpriteBatch));
|
this.UiSystem = new UiSystem(this.Window, this.GraphicsDevice, new UntexturedStyle(this.SpriteBatch));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update(GameTime gameTime) {
|
protected override void Update(GameTime gameTime) {
|
||||||
|
|
|
@ -6,7 +6,6 @@ namespace MLEM.Ui.Elements {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A group element to be used inside of a <see cref="UiSystem"/>.
|
/// A group element to be used inside of a <see cref="UiSystem"/>.
|
||||||
/// A group is an element that has no rendering or interaction on its own, but that can aid with automatic placement of child elements.
|
/// A group is an element that has no rendering or interaction on its own, but that can aid with automatic placement of child elements.
|
||||||
/// If a grouping whose children scroll, and which has a <see cref="ScrollBar"/>, is desired, a <see cref="Panel"/> with its <see cref="Panel.Texture"/> set to <see langword="null"/> can be used.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Group : Element {
|
public class Group : Element {
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ namespace MLEM.Ui.Elements {
|
||||||
/// A panel element to be used inside of a <see cref="UiSystem"/>.
|
/// A panel element to be used inside of a <see cref="UiSystem"/>.
|
||||||
/// The panel is a complex element that displays a box as a background to all of its child elements.
|
/// The panel is a complex element that displays a box as a background to all of its child elements.
|
||||||
/// Additionally, a panel can be set to scroll overflowing elements on construction, which causes all elements that don't fit into the panel to be hidden until scrolled to using a <see cref="ScrollBar"/>.
|
/// Additionally, a panel can be set to scroll overflowing elements on construction, which causes all elements that don't fit into the panel to be hidden until scrolled to using a <see cref="ScrollBar"/>.
|
||||||
/// If an element similar to a <see cref="Group"/>, but with scrolling content, is desired, a panel with its <see cref="Texture"/> set to <see langword="null"/> can be used.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Panel : Element {
|
public class Panel : Element {
|
||||||
|
|
||||||
|
@ -25,8 +24,7 @@ namespace MLEM.Ui.Elements {
|
||||||
public readonly ScrollBar ScrollBar;
|
public readonly ScrollBar ScrollBar;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The texture that this panel should have.
|
/// The texture that this panel should have, or null if it should be invisible.
|
||||||
/// If this is set to <see langword="null"/>, this panel will not have a texture, but all of its content will still be visible.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public StyleProp<NinePatch> Texture;
|
public StyleProp<NinePatch> Texture;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -66,7 +64,6 @@ namespace MLEM.Ui.Elements {
|
||||||
private StyleProp<float> scrollBarOffset;
|
private StyleProp<float> scrollBarOffset;
|
||||||
private float lastScrollOffset;
|
private float lastScrollOffset;
|
||||||
private bool childrenDirtyForScroll;
|
private bool childrenDirtyForScroll;
|
||||||
private bool scrollBarMaxHistoryDirty;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new panel with the given settings.
|
/// Creates a new panel with the given settings.
|
||||||
|
@ -86,7 +83,6 @@ namespace MLEM.Ui.Elements {
|
||||||
|
|
||||||
if (scrollOverflow) {
|
if (scrollOverflow) {
|
||||||
this.scrollBarMaxHistory = new float[3];
|
this.scrollBarMaxHistory = new float[3];
|
||||||
this.scrollBarMaxHistoryDirty = true;
|
|
||||||
this.ResetScrollBarMaxHistory();
|
this.ResetScrollBarMaxHistory();
|
||||||
|
|
||||||
this.ScrollBar = new ScrollBar(Anchor.TopRight, Vector2.Zero, 0, 0) {
|
this.ScrollBar = new ScrollBar(Anchor.TopRight, Vector2.Zero, 0, 0) {
|
||||||
|
@ -176,14 +172,6 @@ namespace MLEM.Ui.Elements {
|
||||||
base.RemoveChildren(e => e != this.ScrollBar && (condition == null || condition(e)));
|
base.RemoveChildren(e => e != this.ScrollBar && (condition == null || condition(e)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override void Update(GameTime time) {
|
|
||||||
// reset the scroll bar's max history when an update happens, at which point we know that any scroll bar recursion has "settled"
|
|
||||||
// (this reset ensures that the max history is recursion-internal and old values aren't reused when elements get modified later)
|
|
||||||
this.ResetScrollBarMaxHistory();
|
|
||||||
base.Update(time);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) {
|
public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) {
|
||||||
// draw children onto the render target if we have one
|
// draw children onto the render target if we have one
|
||||||
|
@ -346,7 +334,6 @@ namespace MLEM.Ui.Elements {
|
||||||
this.scrollBarMaxHistory[0] = this.scrollBarMaxHistory[1];
|
this.scrollBarMaxHistory[0] = this.scrollBarMaxHistory[1];
|
||||||
this.scrollBarMaxHistory[1] = this.scrollBarMaxHistory[2];
|
this.scrollBarMaxHistory[1] = this.scrollBarMaxHistory[2];
|
||||||
this.scrollBarMaxHistory[2] = scrollBarMax;
|
this.scrollBarMaxHistory[2] = scrollBarMax;
|
||||||
this.scrollBarMaxHistoryDirty = true;
|
|
||||||
|
|
||||||
this.ScrollBar.MaxValue = scrollBarMax;
|
this.ScrollBar.MaxValue = scrollBarMax;
|
||||||
this.relevantChildrenDirty = true;
|
this.relevantChildrenDirty = true;
|
||||||
|
@ -432,10 +419,9 @@ namespace MLEM.Ui.Elements {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResetScrollBarMaxHistory() {
|
private void ResetScrollBarMaxHistory() {
|
||||||
if (this.scrollOverflow && this.scrollBarMaxHistoryDirty) {
|
if (this.scrollOverflow) {
|
||||||
for (var i = 0; i < this.scrollBarMaxHistory.Length; i++)
|
for (var i = 0; i < this.scrollBarMaxHistory.Length; i++)
|
||||||
this.scrollBarMaxHistory[i] = -1;
|
this.scrollBarMaxHistory[i] = -1;
|
||||||
this.scrollBarMaxHistoryDirty = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue