Skip to content

Feat: Misc Update #392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions Editor/Qml/ENumberInput.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Basic

Item {
property int value: spinBox.value
property int from: spinBox.from
property int to: spinBox.to
property bool editable: spinBox.editable

id: root
implicitWidth: spinBox.implicitWidth
implicitHeight: spinBox.implicitHeight

SpinBox {
id: spinBox
implicitHeight: textField.implicitHeight
value: root.value
editable: root.editable
from: root.from
to: root.to

contentItem: ETextField {
id: textField
implicitWidth: 40
text: spinBox.textFromValue(spinBox.value)
validator: spinBox.validator
}

down.indicator: Rectangle {
id: downIndicator
x: 0
implicitWidth: 25
implicitHeight: textField.implicitHeight
radius: 5
color: spinBox.down.hovered ? ETheme.secondaryBgColor : ETheme.primaryBgColor

EIcon {
name: 'minus'
anchors.centerIn: downIndicator
}
}

up.indicator: Rectangle {
id: upIndicator
x: spinBox.width - width
implicitWidth: 25
implicitHeight: textField.implicitHeight
radius: 5
color: spinBox.up.hovered ? ETheme.secondaryBgColor : ETheme.primaryBgColor

EIcon {
name: 'add'
anchors.centerIn: upIndicator
}
}

background: Rectangle {
implicitWidth: 100
radius: 5
color: ETheme.primaryBgColor
}
}
}
7 changes: 6 additions & 1 deletion Editor/Qml/ETextField.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import QtQuick.Controls.Basic
Item {
property string placeHolderText: ''
property int wrapMode: TextInput.NoWrap
property string text: ''
property string text: textField.text
property var validator: null

signal accepted()

id: root
implicitWidth: textField.implicitWidth
Expand All @@ -24,6 +27,8 @@ Item {
font.pixelSize: ETheme.contentFontSize
font.family: ETheme.fontFamily
wrapMode: root.wrapMode
validator: root.validator
onAccepted: root.accepted()

background: Rectangle {
radius: 5
Expand Down
54 changes: 54 additions & 0 deletions Editor/Qml/EWidgetSamples.qml
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,26 @@ Rectangle {
}
}

RowLayout {
ETextField {
id: textFieldWithValidator
Layout.preferredWidth: 300
placeHolderText: 'Hello World'
validator: IntValidator {
bottom: 1
top: 10
}
onAccepted: {
console.log('value accepted, value=' + text)
}
}

EText {
Layout.leftMargin: 5
text: 'With Validator'
}
}

RowLayout {
ETextField {
Layout.preferredWidth: 300
Expand All @@ -370,6 +390,40 @@ Rectangle {
}
}
}

RowLayout {
Layout.leftMargin: 5
Layout.topMargin: 35
EText {
text: 'NumberInput'
style: EText.Style.Title1
}
}

ColumnLayout {
Layout.margins: 5

RowLayout {
ENumberInput {}

EText {
Layout.leftMargin: 5
text: 'Default'
}
}

RowLayout {
ENumberInput {
from: 0
to: 10
}

EText {
Layout.leftMargin: 5
text: 'Limit 0-10'
}
}
}
}
}
}
18 changes: 10 additions & 8 deletions Engine/Source/Common/Include/Common/Concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <unordered_map>
#include <set>
#include <map>
#include <variant>

namespace Common {
template <typename T> concept BaseEqualComparable = requires(const T& lhs, const T& rhs) { { lhs == rhs } -> std::same_as<bool>; { lhs != rhs } -> std::same_as<bool>; };
Expand Down Expand Up @@ -64,12 +65,13 @@ namespace Common {

namespace Common {
// some types can perform operator== compare, but it requires element type also support operator== compare, so we test it further
template <typename T> struct EqualComparableTest<std::optional<T>> { static constexpr bool value = BaseEqualComparable<T>; };
template <typename T> struct EqualComparableTest<std::vector<T>> { static constexpr bool value = BaseEqualComparable<T>; };
template <typename T> struct EqualComparableTest<std::unordered_set<T>> { static constexpr bool value = BaseEqualComparable<T>; };
template <typename T> struct EqualComparableTest<std::set<T>> { static constexpr bool value = BaseEqualComparable<T>; };
template <typename T, size_t N> struct EqualComparableTest<std::array<T, N>> { static constexpr bool value = BaseEqualComparable<T>; };
template <typename K, typename V> struct EqualComparableTest<std::pair<K, V>> { static constexpr bool value = BaseEqualComparable<K> && BaseEqualComparable<V>; };
template <typename K, typename V> struct EqualComparableTest<std::unordered_map<K, V>> { static constexpr bool value = BaseEqualComparable<K> && BaseEqualComparable<V>; };
template <typename K, typename V> struct EqualComparableTest<std::map<K, V>> { static constexpr bool value = BaseEqualComparable<K> && BaseEqualComparable<V>; };
template <typename T> struct EqualComparableTest<std::optional<T>> { static constexpr bool value = EqualComparableTest<T>::value; };
template <typename T> struct EqualComparableTest<std::vector<T>> { static constexpr bool value = EqualComparableTest<T>::value; };
template <typename T> struct EqualComparableTest<std::unordered_set<T>> { static constexpr bool value = EqualComparableTest<T>::value; };
template <typename T> struct EqualComparableTest<std::set<T>> { static constexpr bool value = EqualComparableTest<T>::value; };
template <typename T, size_t N> struct EqualComparableTest<std::array<T, N>> { static constexpr bool value = EqualComparableTest<T>::value; };
template <typename K, typename V> struct EqualComparableTest<std::pair<K, V>> { static constexpr bool value = std::conjunction_v<EqualComparableTest<K>, EqualComparableTest<V>>; };
template <typename K, typename V> struct EqualComparableTest<std::unordered_map<K, V>> { static constexpr bool value = std::conjunction_v<EqualComparableTest<K>, EqualComparableTest<V>>; };
template <typename K, typename V> struct EqualComparableTest<std::map<K, V>> { static constexpr bool value = std::conjunction_v<EqualComparableTest<K>, EqualComparableTest<V>>; };
template <typename... T> struct EqualComparableTest<std::variant<T...>> { static constexpr bool value = std::conjunction_v<EqualComparableTest<T>...>; };
}
Loading