Skip to content

Commit 0084f6f

Browse files
committed
feat: number input basics
1 parent cc6fa61 commit 0084f6f

File tree

3 files changed

+124
-1
lines changed

3 files changed

+124
-1
lines changed

Editor/Qml/ENumberInput.qml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import QtQuick
2+
import QtQuick.Controls
3+
import QtQuick.Controls.Basic
4+
5+
Item {
6+
property int value: spinBox.value
7+
property int from: spinBox.from
8+
property int to: spinBox.to
9+
property bool editable: spinBox.editable
10+
11+
id: root
12+
implicitWidth: spinBox.implicitWidth
13+
implicitHeight: spinBox.implicitHeight
14+
15+
SpinBox {
16+
id: spinBox
17+
implicitHeight: textField.implicitHeight
18+
value: root.value
19+
editable: root.editable
20+
from: root.from
21+
to: root.to
22+
23+
contentItem: ETextField {
24+
id: textField
25+
implicitWidth: 40
26+
text: spinBox.textFromValue(spinBox.value)
27+
validator: spinBox.validator
28+
}
29+
30+
down.indicator: Rectangle {
31+
id: downIndicator
32+
x: 0
33+
implicitWidth: 25
34+
implicitHeight: textField.implicitHeight
35+
radius: 5
36+
color: spinBox.down.hovered ? ETheme.secondaryBgColor : ETheme.primaryBgColor
37+
38+
EIcon {
39+
name: 'minus'
40+
anchors.centerIn: downIndicator
41+
}
42+
}
43+
44+
up.indicator: Rectangle {
45+
id: upIndicator
46+
x: spinBox.width - width
47+
implicitWidth: 25
48+
implicitHeight: textField.implicitHeight
49+
radius: 5
50+
color: spinBox.up.hovered ? ETheme.secondaryBgColor : ETheme.primaryBgColor
51+
52+
EIcon {
53+
name: 'add'
54+
anchors.centerIn: upIndicator
55+
}
56+
}
57+
58+
background: Rectangle {
59+
implicitWidth: 100
60+
radius: 5
61+
color: ETheme.primaryBgColor
62+
}
63+
}
64+
}

Editor/Qml/ETextField.qml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import QtQuick.Controls.Basic
55
Item {
66
property string placeHolderText: ''
77
property int wrapMode: TextInput.NoWrap
8-
property string text: ''
8+
property string text: textField.text
9+
property var validator: null
10+
11+
signal accepted()
912

1013
id: root
1114
implicitWidth: textField.implicitWidth
@@ -24,6 +27,8 @@ Item {
2427
font.pixelSize: ETheme.contentFontSize
2528
font.family: ETheme.fontFamily
2629
wrapMode: root.wrapMode
30+
validator: root.validator
31+
onAccepted: root.accepted()
2732

2833
background: Rectangle {
2934
radius: 5

Editor/Qml/EWidgetSamples.qml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,26 @@ Rectangle {
350350
}
351351
}
352352

353+
RowLayout {
354+
ETextField {
355+
id: textFieldWithValidator
356+
Layout.preferredWidth: 300
357+
placeHolderText: 'Hello World'
358+
validator: IntValidator {
359+
bottom: 1
360+
top: 10
361+
}
362+
onAccepted: {
363+
console.log('value accepted, value=' + text)
364+
}
365+
}
366+
367+
EText {
368+
Layout.leftMargin: 5
369+
text: 'With Validator'
370+
}
371+
}
372+
353373
RowLayout {
354374
ETextField {
355375
Layout.preferredWidth: 300
@@ -370,6 +390,40 @@ Rectangle {
370390
}
371391
}
372392
}
393+
394+
RowLayout {
395+
Layout.leftMargin: 5
396+
Layout.topMargin: 35
397+
EText {
398+
text: 'NumberInput'
399+
style: EText.Style.Title1
400+
}
401+
}
402+
403+
ColumnLayout {
404+
Layout.margins: 5
405+
406+
RowLayout {
407+
ENumberInput {}
408+
409+
EText {
410+
Layout.leftMargin: 5
411+
text: 'Default'
412+
}
413+
}
414+
415+
RowLayout {
416+
ENumberInput {
417+
from: 0
418+
to: 10
419+
}
420+
421+
EText {
422+
Layout.leftMargin: 5
423+
text: 'Limit 0-10'
424+
}
425+
}
426+
}
373427
}
374428
}
375429
}

0 commit comments

Comments
 (0)