diff --git a/source/fluid/actions.d b/source/fluid/actions.d index 51ff3d0d..0ec40e08 100644 --- a/source/fluid/actions.d +++ b/source/fluid/actions.d @@ -189,7 +189,9 @@ unittest { root.children[1].scrollIntoView; root.draw(); - auto getPositions() => io.textures.map!(a => a.position).array; + auto getPositions() { + return io.textures.map!(a => a.position).array; + } // Find label positions auto positions = getPositions(); diff --git a/source/fluid/backend/headless.d b/source/fluid/backend/headless.d index f96abd47..cdc01659 100644 --- a/source/fluid/backend/headless.d +++ b/source/fluid/backend/headless.d @@ -56,8 +56,8 @@ class HeadlessBackend : FluidBackend { Vector2 start, end; Color color; - bool isClose(Vector2 a, Vector2 b) const - => ( + bool isClose(Vector2 a, Vector2 b) const { + return ( .isClose(start.x, this.start.x) && .isClose(start.y, this.start.y) && .isClose(end.x, this.end.x) @@ -67,6 +67,7 @@ class HeadlessBackend : FluidBackend { && .isClose(end.y, this.end.y) && .isClose(start.x, this.start.x) && .isClose(start.y, this.start.y)); + } } @@ -75,13 +76,14 @@ class HeadlessBackend : FluidBackend { Vector2 a, b, c; Color color; - bool isClose(Vector2 a, Vector2 b, Vector2 c) const - => .isClose(a.x, this.a.x) - && .isClose(a.y, this.a.y) - && .isClose(b.x, this.b.x) - && .isClose(b.y, this.b.y) - && .isClose(c.x, this.c.x) - && .isClose(c.y, this.c.y); + bool isClose(Vector2 a, Vector2 b, Vector2 c) const { + return .isClose(a.x, this.a.x) + && .isClose(a.y, this.a.y) + && .isClose(b.x, this.b.x) + && .isClose(b.y, this.b.y) + && .isClose(c.x, this.c.x) + && .isClose(c.y, this.c.y); + } } @@ -92,10 +94,11 @@ class HeadlessBackend : FluidBackend { Color color; bool outlineOnly; - bool isClose(Vector2 position, float radius) const - => .isClose(position.x, this.position.x) - && .isClose(position.y, this.position.y) - && .isClose(radius, this.radius); + bool isClose(Vector2 position, float radius) const { + return .isClose(position.x, this.position.x) + && .isClose(position.y, this.position.y) + && .isClose(radius, this.radius); + } } @@ -106,25 +109,25 @@ class HeadlessBackend : FluidBackend { alias rectangle this; - bool isClose(Rectangle rectangle) const - - => isClose(rectangle.tupleof); - - bool isClose(float x, float y, float width, float height) const - - => .isClose(this.rectangle.x, x) - && .isClose(this.rectangle.y, y) - && .isClose(this.rectangle.width, width) - && .isClose(this.rectangle.height, height); - - bool isStartClose(Vector2 start) const + bool isClose(Rectangle rectangle) const { + return isClose(rectangle.tupleof); + } - => isStartClose(start.tupleof); + bool isClose(float x, float y, float width, float height) const { + return .isClose(this.rectangle.x, x) + && .isClose(this.rectangle.y, y) + && .isClose(this.rectangle.width, width) + && .isClose(this.rectangle.height, height); + } - bool isStartClose(float x, float y) const + bool isStartClose(Vector2 start) const { + return isStartClose(start.tupleof); + } - => .isClose(this.rectangle.x, x) - && .isClose(this.rectangle.y, y); + bool isStartClose(float x, float y) const { + return .isClose(this.rectangle.x, x) + && .isClose(this.rectangle.y, y); + } } @@ -153,24 +156,24 @@ class HeadlessBackend : FluidBackend { } - Vector2 position() const - - => Vector2(rectangle.x, rectangle.y); - - DrawnRectangle drawnRectangle() const + Vector2 position() const { + return Vector2(rectangle.x, rectangle.y); + } - => DrawnRectangle(rectangle, tint); + DrawnRectangle drawnRectangle() const { + return DrawnRectangle(rectangle, tint); + } alias isPositionClose = isStartClose; - bool isStartClose(Vector2 start) const - - => isStartClose(start.tupleof); - - bool isStartClose(float x, float y) const + bool isStartClose(Vector2 start) const { + return isStartClose(start.tupleof); + } - => .isClose(rectangle.x, x) - && .isClose(rectangle.y, y); + bool isStartClose(float x, float y) const { + return .isClose(rectangle.x, x) + && .isClose(rectangle.y, y); + } } @@ -312,49 +315,49 @@ class HeadlessBackend : FluidBackend { } /// Check if the given mouse button has just been pressed/released or, if it's held down or not (up). - bool isPressed(MouseButton button) const - - => mouse[button] == State.pressed; - - bool isReleased(MouseButton button) const - - => mouse[button] == State.released; - - bool isDown(MouseButton button) const + bool isPressed(MouseButton button) const { + return mouse[button] == State.pressed; + } - => mouse[button] == State.pressed - || mouse[button] == State.repeated - || mouse[button] == State.down; + bool isReleased(MouseButton button) const { + return mouse[button] == State.released; + } - bool isUp(MouseButton button) const + bool isDown(MouseButton button) const { + return mouse[button] == State.pressed + || mouse[button] == State.repeated + || mouse[button] == State.down; + } - => mouse[button] == State.released - || mouse[button] == State.up; + bool isUp(MouseButton button) const { + return mouse[button] == State.released + || mouse[button] == State.up; + } /// Check if the given keyboard key has just been pressed/released or, if it's held down or not (up). - bool isPressed(KeyboardKey key) const - - => keyboard[key] == State.pressed; - - bool isReleased(KeyboardKey key) const - - => keyboard[key] == State.released; - - bool isDown(KeyboardKey key) const + bool isPressed(KeyboardKey key) const { + return keyboard[key] == State.pressed; + } - => keyboard[key] == State.pressed - || keyboard[key] == State.repeated - || keyboard[key] == State.down; + bool isReleased(KeyboardKey key) const { + return keyboard[key] == State.released; + } - bool isUp(KeyboardKey key) const + bool isDown(KeyboardKey key) const { + return keyboard[key] == State.pressed + || keyboard[key] == State.repeated + || keyboard[key] == State.down; + } - => keyboard[key] == State.released - || keyboard[key] == State.up; + bool isUp(KeyboardKey key) const { + return keyboard[key] == State.released + || keyboard[key] == State.up; + } /// If true, the given keyboard key has been virtually pressed again, through a long-press. - bool isRepeated(KeyboardKey key) const - - => keyboard[key] == State.repeated; + bool isRepeated(KeyboardKey key) const { + return keyboard[key] == State.repeated; + } /// Get next queued character from user's input. The queue should be cleared every frame. Return null if no /// character was pressed. @@ -383,121 +386,114 @@ class HeadlessBackend : FluidBackend { } /// Check if the given gamepad button has been pressed/released or, if it's held down or not (up). - int isPressed(GamepadButton button) const - - => gamepad[button] == State.pressed; - - int isReleased(GamepadButton button) const - - => gamepad[button] == State.released; - - int isDown(GamepadButton button) const - - => gamepad[button] == State.pressed - || gamepad[button] == State.repeated - || gamepad[button] == State.down; - - int isUp(GamepadButton button) const - - => gamepad[button] == State.released - || gamepad[button] == State.up; - - int isRepeated(GamepadButton button) const + int isPressed(GamepadButton button) const { + return gamepad[button] == State.pressed; + } + + int isReleased(GamepadButton button) const { + return gamepad[button] == State.released; + } + + int isDown(GamepadButton button) const { + return gamepad[button] == State.pressed + || gamepad[button] == State.repeated + || gamepad[button] == State.down; + } + + int isUp(GamepadButton button) const { + return gamepad[button] == State.released + || gamepad[button] == State.up; + } - => gamepad[button] == State.repeated; + int isRepeated(GamepadButton button) const { + return gamepad[button] == State.repeated; + } /// Get/set mouse position - Vector2 mousePosition(Vector2 value) + Vector2 mousePosition(Vector2 value) { + return _mousePosition = value;} - => _mousePosition = value; - - Vector2 mousePosition() const - - => _mousePosition; + Vector2 mousePosition() const { + return _mousePosition; + } /// Get/set mouse scroll - Vector2 scroll(Vector2 value) - - => _scroll = scroll; - - Vector2 scroll() const + Vector2 scroll(Vector2 value) { + return _scroll = scroll; + } - => _scroll; + Vector2 scroll() const { + return _scroll; + } string clipboard(string value) @trusted { - return _clipboard = value; - } string clipboard() const @trusted { - return _clipboard; - } /// Get time elapsed since last frame in seconds. - float deltaTime() const - - => _deltaTime; + float deltaTime() const { + return _deltaTime; + } /// True if the user has just resized the window. - bool hasJustResized() const - - => _justResized; + bool hasJustResized() const { + return _justResized; + } /// Get or set the size of the window. Vector2 windowSize(Vector2 value) { - resize(value); return value; - } - Vector2 windowSize() const - - => _windowSize; - - float scale() const - - => _scale; + Vector2 windowSize() const { + return _windowSize; + } - float scale(float value) + float scale() const { + return _scale; + } - => _scale = value; + float scale(float value) { + return _scale = value; + } /// Get HiDPI scale of the window. This is not currently supported by this backend. - Vector2 dpi() const - - => _dpi * _scale; + Vector2 dpi() const { + return _dpi * _scale; + } /// Set area within the window items will be drawn to; any pixel drawn outside will be discarded. Rectangle area(Rectangle rect) { - _scissorsOn = true; return _area = rect; - } - Rectangle area() const + Rectangle area() const { - => _scissorsOn ? _area : Rectangle(0, 0, _windowSize.tupleof); + if (_scissorsOn) + return _area; + else + return Rectangle(0, 0, _windowSize.tupleof); + } /// Restore the capability to draw anywhere in the window. void restoreArea() { - _scissorsOn = false; - } /// Get or set mouse cursor icon. - FluidMouseCursor mouseCursor(FluidMouseCursor cursor) - - => _cursor = cursor; - - FluidMouseCursor mouseCursor() const + FluidMouseCursor mouseCursor(FluidMouseCursor cursor) { + return _cursor = cursor; + } - => _cursor; + FluidMouseCursor mouseCursor() const { + return _cursor; + } TextureReaper* reaper() return scope { @@ -718,21 +714,23 @@ class HeadlessBackend : FluidBackend { /// Get items from the canvas that match the given type. version (Fluid_HeadlessOutput) { - auto filterCanvas(T)() + auto filterCanvas(T)() { - => canvas[] + return canvas[] - // Filter out items that don't match what was requested - .filter!(a => a.match!( - (T item) => true, - (_) => false - )) + // Filter out items that don't match what was requested + .filter!(a => a.match!( + (T item) => true, + (_) => false + )) + + // Return items that match + .map!(a => a.match!( + (T item) => item, + (_) => assert(false), + )); - // Return items that match - .map!(a => a.match!( - (T item) => item, - (_) => assert(false), - )); + } alias lines = filterCanvas!DrawnLine; alias triangles = filterCanvas!DrawnTriangle; @@ -827,9 +825,9 @@ class HeadlessBackend : FluidBackend { } /// ditto - string toSVG() const - - => Element.XMLDeclaration1_0 ~ this.toSVGElement; + string toSVG() const { + return Element.XMLDeclaration1_0 ~ this.toSVGElement; + } /// ditto Element toSVGElement() const { diff --git a/source/fluid/backend/package.d b/source/fluid/backend/package.d index 7ffec57e..cfed1aff 100644 --- a/source/fluid/backend/package.d +++ b/source/fluid/backend/package.d @@ -313,17 +313,25 @@ shared struct TextureTombstone { } /// Check if a request for destruction has been made for the texture. - bool isDestroyed() @system => _references.atomicLoad == 0; + bool isDestroyed() @system { + return _references.atomicLoad == 0; + } /// Check if the texture has been disowned by the backend. A disowned tombstone refers to a texture that has been /// freed. - private bool isDisowned() @system => _disowned.atomicLoad; + private bool isDisowned() @system { + return _disowned.atomicLoad; + } /// Get number of references to this tombstone. - private int references() @system => _references.atomicLoad; + private int references() @system { + return _references.atomicLoad; + } /// Get the backend owning this texture. - inout(shared FluidBackend) backend() inout => _backend; + inout(shared FluidBackend) backend() inout { + return _backend; + } /// Mark the texture as destroyed. void markDestroyed() @system { @@ -995,40 +1003,42 @@ struct Texture { /// If relevant, the texture is to use this palette. Color[] palette; - bool opEquals(const Texture other) const + bool opEquals(const Texture other) const { + return id == other.id + && width == other.width + && height == other.height + && dpiX == other.dpiX + && dpiY == other.dpiY; - => id == other.id - && width == other.width - && height == other.height - && dpiX == other.dpiX - && dpiY == other.dpiY; + } - version (Have_raylib_d)void opAssign(raylib.Texture rayTexture) @system { + version (Have_raylib_d) + void opAssign(raylib.Texture rayTexture) @system { this = rayTexture.toFluid(); } /// Get the backend for this texture. Doesn't work after freeing the tombstone. - inout(FluidBackend) backend() inout @trusted - - => cast(inout FluidBackend) tombstone.backend; + inout(FluidBackend) backend() inout @trusted { + return cast(inout FluidBackend) tombstone.backend; + } /// DPI value of the texture. - Vector2 dpi() const - - => Vector2(dpiX, dpiY); + Vector2 dpi() const { + return Vector2(dpiX, dpiY); + } /// Get texture size as a vector. - Vector2 canvasSize() const - - => Vector2(width, height); + Vector2 canvasSize() const { + return Vector2(width, height); + } /// Get the size the texture will occupy within the viewport. - Vector2 viewportSize() const - - => Vector2( + Vector2 viewportSize() const { + return Vector2( width * 96 / dpiX, height * 96 / dpiY ); + } /// Update the texture to match the given image. void update(Image image) @system { diff --git a/source/fluid/backend/raylib5.d b/source/fluid/backend/raylib5.d index 5029585d..b8db49b8 100644 --- a/source/fluid/backend/raylib5.d +++ b/source/fluid/backend/raylib5.d @@ -79,22 +79,38 @@ class Raylib5Backend : FluidBackend { @trusted { - bool isPressed(MouseButton button) const - => IsMouseButtonPressed(button.toRaylib); - bool isReleased(MouseButton button) const - => IsMouseButtonReleased(button.toRaylib); - bool isDown(MouseButton button) const - => IsMouseButtonDown(button.toRaylib); - bool isUp(MouseButton button) const - => IsMouseButtonUp(button.toRaylib); - - bool isPressed(KeyboardKey key) const => IsKeyPressed(key.toRaylib); - bool isReleased(KeyboardKey key) const => IsKeyReleased(key.toRaylib); - bool isDown(KeyboardKey key) const => IsKeyDown(key.toRaylib); - bool isUp(KeyboardKey key) const => IsKeyUp(key.toRaylib); - bool isRepeated(KeyboardKey key) const => IsKeyPressedRepeat(key.toRaylib); - - dchar inputCharacter() => cast(dchar) GetCharPressed(); + bool isPressed(MouseButton button) const { + return IsMouseButtonPressed(button.toRaylib); + } + bool isReleased(MouseButton button) const { + return IsMouseButtonReleased(button.toRaylib); + } + bool isDown(MouseButton button) const { + return IsMouseButtonDown(button.toRaylib); + } + bool isUp(MouseButton button) const { + return IsMouseButtonUp(button.toRaylib); + } + + bool isPressed(KeyboardKey key) const { + return IsKeyPressed(key.toRaylib); + } + bool isReleased(KeyboardKey key) const { + return IsKeyReleased(key.toRaylib); + } + bool isDown(KeyboardKey key) const { + return IsKeyDown(key.toRaylib); + } + bool isUp(KeyboardKey key) const { + return IsKeyUp(key.toRaylib); + } + bool isRepeated(KeyboardKey key) const { + return IsKeyPressedRepeat(key.toRaylib); + } + + dchar inputCharacter() { + return cast(dchar) GetCharPressed(); + } int isPressed(GamepadButton button) const { auto btn = button.toRaylib; diff --git a/source/fluid/code_input.d b/source/fluid/code_input.d index 8e1f0fa6..09653c69 100644 --- a/source/fluid/code_input.d +++ b/source/fluid/code_input.d @@ -1969,9 +1969,9 @@ unittest { .front .indent; - }; + } - }; + } auto indentor = new Indentor; auto highlighter = new class Indentor, CodeHighlighter { diff --git a/source/fluid/file_input.d b/source/fluid/file_input.d index 2f495853..c1437d2b 100644 --- a/source/fluid/file_input.d +++ b/source/fluid/file_input.d @@ -505,12 +505,18 @@ class FileInputSuggestion : Button { } /// File input the button belongs to. - inout(FileInput) parent() inout => _input; + inout(FileInput) parent() inout { + return _input; + } /// Index of the button. - int index() const => _index; + int index() const { + return _index; + } /// True if this suggestion is selected. - bool isSelected() const => _input.currentSuggestion == _index+1; + bool isSelected() const { + return _input.currentSuggestion == _index+1; + } } diff --git a/source/fluid/image_view.d b/source/fluid/image_view.d index f49365d0..56aea78c 100644 --- a/source/fluid/image_view.d +++ b/source/fluid/image_view.d @@ -150,20 +150,6 @@ class ImageView : Node { io.assertTexture(root.texture, Vector2(0, 0), color!"fff"); - version (Have_raylib_d) { - import std.string: toStringz; - raylib.Image LoadImage(string path) => raylib.LoadImage(path.toStringz); - raylib.Texture LoadTexture(string path) => raylib.LoadTexture(path.toStringz); - void InitWindow() => raylib.InitWindow(80, 80, ""); - void CloseWindow() => raylib.CloseWindow(); - - InitWindow; - raylib.Texture rayTexture = LoadTexture("logo.png"); - fluid.Texture texture = rayTexture.toFluid; - - io.assertTexture(root.texture, Vector2(0, 0), color!"fff"); - CloseWindow; - } } /// Get the current texture. diff --git a/source/fluid/input.d b/source/fluid/input.d index dcd242e5..7eab4c13 100644 --- a/source/fluid/input.d +++ b/source/fluid/input.d @@ -219,7 +219,9 @@ struct InputStroke { } /// Get number of items in the stroke. - size_t length() const => input.length; + size_t length() const { + return input.length; + } /// Get a copy of the input stroke with the last item removed, if any. /// diff --git a/source/fluid/text.d b/source/fluid/text.d index 9e606784..4072f1f3 100644 --- a/source/fluid/text.d +++ b/source/fluid/text.d @@ -114,9 +114,11 @@ struct StyledText(StyleRange = TextStyleSlice[]) { } - inout(FluidBackend) backend() inout + inout(FluidBackend) backend() inout { - => node.tree.backend; + return node.tree.backend; + + } Rope opAssign(Rope text) { diff --git a/source/fluid/typeface.d b/source/fluid/typeface.d index 9ae5d23c..c042c862 100644 --- a/source/fluid/typeface.d +++ b/source/fluid/typeface.d @@ -76,7 +76,9 @@ interface Typeface { bool opEquals(const Object object) @safe const; /// Get the default Fluid typeface. - static defaultTypeface() => FreetypeTypeface.defaultTypeface; + static defaultTypeface() { + return FreetypeTypeface.defaultTypeface; + } /// Default word splitter used by measure/draw. alias defaultWordChunks = .breakWords; @@ -331,7 +333,10 @@ auto breakWords(Range)(Range range) { Range range; Range front = Range.init; - bool empty() const => front.empty; + bool empty() const { + return front.empty; + } + void popFront() { dchar lastChar = 0; @@ -619,9 +624,15 @@ class FreetypeTypeface : Typeface { } - ref inout(int) indentWidth() inout => _indentWidth; - bool isOwner() const => _isOwner; - bool isOwner(bool value) @system => _isOwner = value; + ref inout(int) indentWidth() inout { + return _indentWidth; + } + bool isOwner() const { + return _isOwner; + } + bool isOwner(bool value) @system { + return _isOwner = value; + } long glyphCount() const { diff --git a/source/fluid/utils.d b/source/fluid/utils.d index 84ac8644..3c030f67 100644 --- a/source/fluid/utils.d +++ b/source/fluid/utils.d @@ -188,10 +188,10 @@ bool contains(Rectangle rectangle, Vector2 point) { /// Check if the two rectangles overlap. bool overlap(Rectangle a, Rectangle b) { - const x = start(b).x <= a.x && a.x <= end(b).x - || start(a).x <= b.x && b.x <= end(a).x; - const y = start(b).y <= a.y && a.y <= end(b).y - || start(a).y <= b.y && b.y <= end(a).y; + const x = (start(b).x <= a.x && a.x <= end(b).x) + || (start(a).x <= b.x && b.x <= end(a).x); + const y = (start(b).y <= a.y && a.y <= end(b).y) + || (start(a).y <= b.y && b.y <= end(a).y); return x && y; @@ -200,16 +200,24 @@ bool overlap(Rectangle a, Rectangle b) { // Extremely useful Rectangle utilities /// Get the top-left corner of a rectangle. -Vector2 start(Rectangle r) => Vector2(r.x, r.y); +Vector2 start(Rectangle r) { + return Vector2(r.x, r.y); +} /// Get the bottom-right corner of a rectangle. -Vector2 end(Rectangle r) => Vector2(r.x + r.w, r.y + r.h); +Vector2 end(Rectangle r) { + return Vector2(r.x + r.w, r.y + r.h); +} /// Get the center of a rectangle. -Vector2 center(Rectangle r) => Vector2(r.x + r.w/2, r.y + r.h/2); +Vector2 center(Rectangle r) { + return Vector2(r.x + r.w/2, r.y + r.h/2); +} /// Get the size of a rectangle. -Vector2 size(Rectangle r) => Vector2(r.w, r.h); +Vector2 size(Rectangle r) { + return Vector2(r.w, r.h); +} /// Get names of static fields in the given object. ///