mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-23 13:18:35 +01:00
Compare commits
3 commits
dbd52d5b9d
...
a58470de9f
Author | SHA1 | Date | |
---|---|---|---|
a58470de9f | |||
b733d1df0e | |||
c46b11f4fc |
3 changed files with 18 additions and 3 deletions
|
@ -13,7 +13,7 @@ protected override void LoadContent() {
|
|||
// Load your other content here
|
||||
|
||||
// Initialize the Ui system
|
||||
this.UiSystem = new UiSystem(this.Window, this.GraphicsDevice, new UntexturedStyle(this.SpriteBatch));
|
||||
this.UiSystem = new UiSystem(this, this.GraphicsDevice, new UntexturedStyle(this.SpriteBatch));
|
||||
}
|
||||
|
||||
protected override void Update(GameTime gameTime) {
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace MLEM.Ui.Elements {
|
|||
/// <summary>
|
||||
/// 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.
|
||||
/// 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>
|
||||
public class Group : Element {
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ namespace MLEM.Ui.Elements {
|
|||
/// 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.
|
||||
/// 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>
|
||||
public class Panel : Element {
|
||||
|
||||
|
@ -24,7 +25,8 @@ namespace MLEM.Ui.Elements {
|
|||
public readonly ScrollBar ScrollBar;
|
||||
|
||||
/// <summary>
|
||||
/// The texture that this panel should have, or null if it should be invisible.
|
||||
/// The texture that this panel should have.
|
||||
/// 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>
|
||||
public StyleProp<NinePatch> Texture;
|
||||
/// <summary>
|
||||
|
@ -64,6 +66,7 @@ namespace MLEM.Ui.Elements {
|
|||
private StyleProp<float> scrollBarOffset;
|
||||
private float lastScrollOffset;
|
||||
private bool childrenDirtyForScroll;
|
||||
private bool scrollBarMaxHistoryDirty;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new panel with the given settings.
|
||||
|
@ -83,6 +86,7 @@ namespace MLEM.Ui.Elements {
|
|||
|
||||
if (scrollOverflow) {
|
||||
this.scrollBarMaxHistory = new float[3];
|
||||
this.scrollBarMaxHistoryDirty = true;
|
||||
this.ResetScrollBarMaxHistory();
|
||||
|
||||
this.ScrollBar = new ScrollBar(Anchor.TopRight, Vector2.Zero, 0, 0) {
|
||||
|
@ -172,6 +176,14 @@ namespace MLEM.Ui.Elements {
|
|||
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 />
|
||||
public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) {
|
||||
// draw children onto the render target if we have one
|
||||
|
@ -334,6 +346,7 @@ namespace MLEM.Ui.Elements {
|
|||
this.scrollBarMaxHistory[0] = this.scrollBarMaxHistory[1];
|
||||
this.scrollBarMaxHistory[1] = this.scrollBarMaxHistory[2];
|
||||
this.scrollBarMaxHistory[2] = scrollBarMax;
|
||||
this.scrollBarMaxHistoryDirty = true;
|
||||
|
||||
this.ScrollBar.MaxValue = scrollBarMax;
|
||||
this.relevantChildrenDirty = true;
|
||||
|
@ -419,9 +432,10 @@ namespace MLEM.Ui.Elements {
|
|||
}
|
||||
|
||||
private void ResetScrollBarMaxHistory() {
|
||||
if (this.scrollOverflow) {
|
||||
if (this.scrollOverflow && this.scrollBarMaxHistoryDirty) {
|
||||
for (var i = 0; i < this.scrollBarMaxHistory.Length; i++)
|
||||
this.scrollBarMaxHistory[i] = -1;
|
||||
this.scrollBarMaxHistoryDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue