Skip to content

Commit

Permalink
Add workarounds for older compilers
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthaTi committed Sep 26, 2024
1 parent 4e40b0c commit 29701d6
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 28 deletions.
4 changes: 2 additions & 2 deletions source/fluid/code_input.d
Original file line number Diff line number Diff line change
Expand Up @@ -2065,9 +2065,9 @@ unittest {
else
return 1;

};
}

};
}

// Every new line indents. If "end" is found in the text, every new line *outdents*, effectively making the text
// flat.
Expand Down
23 changes: 11 additions & 12 deletions source/fluid/input.d
Original file line number Diff line number Diff line change
Expand Up @@ -764,18 +764,24 @@ interface FluidHoverable {
/// Returns:
/// * `true` if the handler took care of the action; processing of the action will finish.
/// * `false` if the action should be handled by the default input action handler.
bool inputActionImpl(InputActionID id, bool active);
bool inputActionImpl(immutable InputActionID id, bool active);

/// Run input actions.
///
/// Use `mixin enableInputActions` to implement.
///
/// Manual implementation is discouraged; override `inputActionImpl` instead.
bool runInputAction(InputActionID action, bool active = true);
bool runInputActionImpl(immutable InputActionID action, bool active = true);

final bool runInputAction(immutable InputActionID action, bool active = true) {

return runInputActionImpl(action, active);

}

final bool runInputAction(alias action)(bool active = true) {

return runInputAction(InputActionID.from!action, active);
return runInputActionImpl(InputActionID.from!action, active);

}

Expand Down Expand Up @@ -814,22 +820,15 @@ interface FluidHoverable {
static assert(is(typeof(this) : Node),
format!"%s : FluidHoverable must inherit from Node"(typeid(this)));

// For some reason, a simple alias to FluidHoverable.runInputAction doesn't work
final bool runInputAction(alias action)(bool active = true) {

return runInputAction(InputActionID.from!action, active);

}

// Provide a default implementation of inputActionImpl
static if (!is(typeof(super) : FluidHoverable))
bool inputActionImpl(InputActionID id, bool active) {
bool inputActionImpl(immutable InputActionID id, bool active) {

return false;

}

override bool runInputAction(InputActionID action, bool active = true) {
override bool runInputActionImpl(immutable InputActionID action, bool active) {

import std.meta : Filter;

Expand Down
2 changes: 1 addition & 1 deletion source/fluid/map_frame.d
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ class MapFrame : Frame {
const position = MapPosition(rectangle.start);

// Already a child
if (children.canFind(node)) {
if (children.canFind!"a is b"(node)) {

positions[node] = position;

Expand Down
8 changes: 7 additions & 1 deletion source/fluid/node.d
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ abstract class Node {
/// Direct changes are discouraged, and are likely to be discarded when reloading themes. Use themes instead.
ref inout(Style) style() inout { return _style; }

override bool opEquals(Object other) const {

return this is other;

}

bool opEquals(const Node otherNode) const {

return this is otherNode;
Expand Down Expand Up @@ -538,7 +544,7 @@ abstract class Node {

root.draw();

assert(visitedNodes == allNodes[1..3]);
assert(visitedNodes[] == allNodes[1..3]);

}

Expand Down
34 changes: 27 additions & 7 deletions source/fluid/structs.d
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ struct Layout {
/// Tags are optional "marks" left on nodes that are used to apply matching styles. Tags closely resemble
/// [HTML classes](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/class).
///
/// Tags have to be explicitly defined before usage, by creating an enum and marking it with the `@NodeTag` attribute.
/// Tags have to be explicitly defined before usage by creating an enum and marking it with the `@NodeTag` attribute.
/// Such tags can then be applied by passing them to the constructor.
enum NodeTag;

Expand All @@ -197,6 +197,8 @@ unittest {
myTag,
}

static assert(isNodeTag!(Tags.myTag));

auto myLabel = label(
.tags!(Tags.myTag),
"Hello, World!"
Expand All @@ -207,16 +209,34 @@ unittest {
}

/// Check if the given item is a node tag.
enum isNodeTag(alias tag)
template isNodeTag(alias tag) {

// @NodeTag enum Tag;
// enum Tag { @NodeTag tag }
= (isSomeEnum!tag
&& hasUDA!(tag, NodeTag))
enum isDirectTag
= isSomeEnum!tag
&& hasUDA!(tag, NodeTag);

// Get the parent symbol
alias parent = __traits(parent, tag);

// @NodeTag enum Enum { tag }
|| (!isType!tag
&& is(__traits(parent, tag) == enum)
&& hasUDA!(typeof(tag), NodeTag));
enum isTagMember
= !isType!tag
&& is(parent == enum)
&& hasUDA!(typeof(tag), NodeTag);

pragma(msg, tag, " ", isDirectTag, " ", isTagMember);
pragma(msg, " isDirectTag: ", isSomeEnum!tag,
", ", hasUDA!(tag, NodeTag));
pragma(msg, " parent: ", parent);
pragma(msg, " isTagMember: ", !isType!tag,
", ", is(__traits(parent, tag) == enum),
", ", hasUDA!(typeof(tag), NodeTag));

enum isNodeTag = isDirectTag || isTagMember;

}

/// Test if the given symbol is an enum, or an enum member.
enum isSomeEnum(alias tag)
Expand Down
11 changes: 6 additions & 5 deletions source/fluid/theme.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import std.traits;
import std.exception;

import fluid.node;
import fluid.utils;
import fluid.style;
import fluid.backend;
import fluid.structs;
Expand Down Expand Up @@ -1535,9 +1536,9 @@ private struct FieldValueStaticArray(E, size_t n) {
isSet = true;

// Assign each field
foreach (i, ref field; this.value.tupleof) {
foreach (i, ref field; this.value[]) {

field = value.tupleof[i];
field = value[i];

}

Expand Down Expand Up @@ -1599,8 +1600,8 @@ private struct FieldValueStaticArray(E, size_t n) {

if (!isSet) return;

foreach (i, field; this.value.tupleof) {
field.apply(value.tupleof[i]);
foreach (i, field; this.value[]) {
field.apply(value[i]);
}

}
Expand All @@ -1612,7 +1613,7 @@ private struct FieldValueStaticArray(E, size_t n) {

value.isSet = true;

foreach (i, field; this.value.tupleof) {
foreach (i, field; this.value[]) {
field.apply(value.value[i]);
}

Expand Down

0 comments on commit 29701d6

Please sign in to comment.