mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-24 21:48:35 +01:00
Compare commits
No commits in common. "45f970e0f20ee7230e8fd25873df1d9b4510a7d5" and "5f2eb1845fbd01abff2e2a2d411fdf249b3afdec" have entirely different histories.
45f970e0f2
...
5f2eb1845f
3 changed files with 3 additions and 70 deletions
|
@ -10,14 +10,6 @@
|
|||
- Check out [the demos](https://github.com/Ellpeck/MLEM/tree/release/Demos) on [Desktop](https://github.com/Ellpeck/MLEM/tree/release/Demos.DesktopGL) or [Android](https://github.com/Ellpeck/MLEM/tree/release/Demos.Android)
|
||||
- See [the changelog](https://mlem.ellpeck.de/CHANGELOG.html) for information on updates
|
||||
|
||||
# Packages
|
||||
- **MLEM** is the base package, which provides extension methods and additional features for MonoGame
|
||||
- **MLEM.Ui** features a mouse, keyboard, gamepad and touch ready Ui system that features automatic anchoring, sizing and several ready-to-use element types.
|
||||
- **MLEM.Extended** ties in with MonoGame.Extended and other MonoGame libraries
|
||||
- **MLEM.Data** provides simple data and network handling
|
||||
- **MLEM.Startup** combines MLEM with some other useful libraries into a quick Game startup class
|
||||
- **MLEM.Templates** contains cross-platform project templates
|
||||
|
||||
# Made with MLEM
|
||||
- [A Breath of Spring Air](https://ellpeck.itch.io/a-breath-of-spring-air), a short platformer ([Source](https://git.ellpeck.de/Ellpeck/GreatSpringGameJam))
|
||||
- [Don't Wake Up](https://ellpeck.itch.io/dont-wake-up), a short puzzle game ([Source](https://github.com/Ellpeck/DontLetGo))
|
||||
|
|
|
@ -178,6 +178,9 @@ namespace MLEM.Ui.Elements {
|
|||
/// If this is true, pressing <see cref="Keys.Enter"/> will insert a new line into the <see cref="Text"/> if the <see cref="InputRule"/> allows it.
|
||||
/// Additionally, text will be rendered with horizontal soft wraps, and lines that are outside of the text field's bounds will be hidden.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Moving up and down through the text field, and clicking on text to start editing at the mouse's position, are currently not supported.
|
||||
/// </remarks>
|
||||
public bool Multiline {
|
||||
get => this.multiline;
|
||||
set {
|
||||
|
@ -260,10 +263,6 @@ namespace MLEM.Ui.Elements {
|
|||
this.CaretPos--;
|
||||
} else if (this.Input.IsKeyPressed(Keys.Right)) {
|
||||
this.CaretPos++;
|
||||
} else if (this.Multiline && this.Input.IsKeyPressed(Keys.Up)) {
|
||||
this.MoveCaretToLine(this.CaretLine - 1);
|
||||
} else if (this.Multiline && this.Input.IsKeyPressed(Keys.Down)) {
|
||||
this.MoveCaretToLine(this.CaretLine + 1);
|
||||
} else if (this.Input.IsKeyPressed(Keys.Home)) {
|
||||
this.CaretPos = 0;
|
||||
} else if (this.Input.IsKeyPressed(Keys.End)) {
|
||||
|
@ -366,31 +365,6 @@ namespace MLEM.Ui.Elements {
|
|||
this.HandleTextChange();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the <see cref="CaretPos"/> to the given line, if it exists.
|
||||
/// Additionally maintains the <see cref="CaretPosInLine"/> roughly based on the visual distance that the caret has from the left border of the current <see cref="CaretLine"/>.
|
||||
/// </summary>
|
||||
/// <param name="line">The line to move the caret to</param>
|
||||
/// <returns>True if the caret was moved, false if it was not (which indicates that the line with the given <paramref name="line"/> index does not exist)</returns>
|
||||
public bool MoveCaretToLine(int line) {
|
||||
var (destStart, destEnd) = this.GetLineBounds(line);
|
||||
if (destEnd > 0) {
|
||||
// find the position whose distance from the start is closest to the current distance from the start
|
||||
var destAccum = "";
|
||||
while (destAccum.Length < destEnd - destStart) {
|
||||
if (this.Font.Value.MeasureString(destAccum).X >= this.caretDrawOffset) {
|
||||
this.CaretPos = destStart + destAccum.Length;
|
||||
return true;
|
||||
}
|
||||
destAccum += this.text[destStart + destAccum.Length];
|
||||
}
|
||||
// if we don't find a proper position, just move to the end of the destination line
|
||||
this.CaretPos = destEnd;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void InitStyle(UiStyle style) {
|
||||
base.InitStyle(style);
|
||||
|
@ -524,31 +498,6 @@ namespace MLEM.Ui.Elements {
|
|||
}
|
||||
}
|
||||
|
||||
private (int, int) GetLineBounds(int boundLine) {
|
||||
if (this.splitText != null) {
|
||||
var line = 0;
|
||||
var index = 0;
|
||||
var startOfLineIndex = 0;
|
||||
for (var d = 0; d < this.splitText.Length; d++) {
|
||||
var split = this.splitText[d];
|
||||
for (var i = 0; i < split.Length; i++) {
|
||||
index++;
|
||||
if (split[i] == '\n') {
|
||||
if (boundLine == line)
|
||||
return (startOfLineIndex, index - 1);
|
||||
line++;
|
||||
startOfLineIndex = index;
|
||||
}
|
||||
}
|
||||
if (boundLine == line)
|
||||
return (startOfLineIndex, index - 1);
|
||||
line++;
|
||||
startOfLineIndex = index;
|
||||
}
|
||||
}
|
||||
return default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A delegate method used for <see cref="TextField.OnTextChange"/>
|
||||
/// </summary>
|
||||
|
|
|
@ -10,14 +10,6 @@
|
|||
- Check out [the demos](https://github.com/Ellpeck/MLEM/tree/main/Demos) on [Desktop](https://github.com/Ellpeck/MLEM/tree/main/Demos.DesktopGL) or [Android](https://github.com/Ellpeck/MLEM/tree/main/Demos.Android)
|
||||
- See [the changelog](https://github.com/Ellpeck/MLEM/blob/main/CHANGELOG.md) for information on updates
|
||||
|
||||
# Packages
|
||||
- **MLEM** is the base package, which provides extension methods and additional features for MonoGame
|
||||
- **MLEM.Ui** features a mouse, keyboard, gamepad and touch ready Ui system that features automatic anchoring, sizing and several ready-to-use element types.
|
||||
- **MLEM.Extended** ties in with MonoGame.Extended and other MonoGame libraries
|
||||
- **MLEM.Data** provides simple data and network handling
|
||||
- **MLEM.Startup** combines MLEM with some other useful libraries into a quick Game startup class
|
||||
- **MLEM.Templates** contains cross-platform project templates
|
||||
|
||||
# Made with MLEM
|
||||
- [A Breath of Spring Air](https://ellpeck.itch.io/a-breath-of-spring-air), a short platformer ([Source](https://git.ellpeck.de/Ellpeck/GreatSpringGameJam))
|
||||
- [Don't Wake Up](https://ellpeck.itch.io/dont-wake-up), a short puzzle game ([Source](https://github.com/Ellpeck/DontLetGo))
|
||||
|
|
Loading…
Reference in a new issue