Skip to content

Commit b665035

Browse files
committed
upd
1 parent 514f51e commit b665035

File tree

18 files changed

+524
-308
lines changed

18 files changed

+524
-308
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
[![Foo](https://img.shields.io/badge/ПОДПИСАТЬСЯ-НА%20ОБНОВЛЕНИЯ-brightgreen.svg?style=social&logo=telegram&color=blue)](https://t.me/GyverLibs)
88

9-
# Settings [beta]
9+
# Settings
1010
Библиотека для создания простого веб-интерфейса настроек на esp8266/esp32
1111
- Веб-приложение весит всего 6кб и вшивается в программу в бинарном gzip виде, никакой возни с файлами
1212
- Удобный билдер панели управления из скетча
@@ -326,14 +326,33 @@ bool Button(size_t id, Text label, sets::Colors color);
326326

327327
// опции разделяются ;
328328
bool Select(size_t id, Text label, Text options, Text value = Text());
329+
330+
// для активации отправь пустой update на его id
331+
bool Confirm(size_t id, Text label);
329332
```
330333
331334
Здесь `Text` - универсальный текстовый формат, принимает строки в любом виде. При указании `value` отличным от стандартного будет отправлено его значение. Иначе будет отправлено значение из БД, если она подключена. Если в качестве значения нужно число - используйте конструктор `Value`, например `b.Color("col", "Color", Value(my_color));`, где `my_color` это `uint32_t`.
332335
336+
### Updater
337+
```cpp
338+
// пустой апдейт (например для вызова Confirm)
339+
void update(size_t id);
340+
341+
// апдейт с текстом
342+
void update(size_t id, Text value);
343+
344+
// апдейт с float
345+
void update(size_t id, float value, uint8_t dec = 2);
346+
347+
// апдейт с числом
348+
void update(size_t id, <любой численный тип> value);
349+
```
350+
333351
<a id="versions"></a>
334352

335353
## Версии
336354
- v1.0
355+
- v1.0.2
337356

338357
<a id="install"></a>
339358
## Установка

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Settings
2-
version=1.0.1
2+
version=1.0.2
33
author=AlexGyver <[email protected]>
44
maintainer=AlexGyver <[email protected]>
55
sentence=Simple UI webface builder for esp8266/esp32

src/core/builder.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ class Builder {
153153
return Button(id, label, (uint32_t)color);
154154
}
155155

156+
// misc
157+
158+
bool Confirm(size_t id, Text label) {
159+
if (_build.isLoad()) _widget(Code::confirm, id, label);
160+
return _checkSet(id);
161+
}
162+
156163
private:
157164
Build _build;
158165
GyverDB* _db = nullptr;

src/core/codes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ enum class Code : uint8_t {
3636
datetime,
3737
button,
3838
paragraph,
39+
confirm,
3940
};
4041

4142
}

src/core/updater.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ class Updater {
99
public:
1010
Updater(Packet& p) : p(p) {}
1111

12+
void update(size_t id) {
13+
p.beginObj();
14+
p.addUint(sets::Code::id, id);
15+
p.endObj();
16+
}
17+
1218
void update(size_t id, Text value) {
1319
p.beginObj();
1420
p.addUint(sets::Code::id, id);

src/web/settings.h

Lines changed: 317 additions & 298 deletions
Large diffs are not rendered by default.

web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "settings",
3-
"version": "1.0.0",
3+
"version": "1.0.2",
44
"main": "index.js",
55
"scripts": {
66
"build": "webpack --config ./webpack.single.js & webpack --config ./webpack.index.js",

web/src/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@import 'style/widget.css';
33
@import 'style/ui.css';
44
@import 'style/popup.css';
5+
@import 'style/dialog.css';
56
@import 'style/widget/switch.css';
67
@import 'style/widget/inputs.css';
78
@import 'style/widget/slider.css';

web/src/script/bson.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const codes = [
3131
'datetime',
3232
'button',
3333
'paragraph',
34+
'confirm',
3435
];
3536

3637
export default function decodeBson(b) {

web/src/script/dialog.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { Component } from "@alexgyver/component";
2+
3+
export function BaseDialog(label, content, actionOK, actionCancel) {
4+
let ctx = {};
5+
Component.make('div', {
6+
context: ctx,
7+
class: 'dialog_back',
8+
var: 'back',
9+
parent: document.body,
10+
child: {
11+
tag: 'div',
12+
class: 'dialog_cont',
13+
child: {
14+
tag: 'div',
15+
class: 'dialog',
16+
children: [
17+
{
18+
tag: 'label',
19+
text: label,
20+
},
21+
content,
22+
{
23+
tag: 'div',
24+
class: 'dialog_btns',
25+
children: [
26+
{
27+
tag: 'div',
28+
class: 'button',
29+
text: 'OK',
30+
events: {
31+
click: () => {
32+
actionOK();
33+
ctx.$back.remove();
34+
},
35+
},
36+
},
37+
{
38+
tag: 'div',
39+
style: 'width: 20px',
40+
},
41+
{
42+
tag: 'div',
43+
class: 'button',
44+
style: 'background: var(--error)',
45+
text: 'Cancel',
46+
events: {
47+
click: () => {
48+
actionCancel();
49+
ctx.$back.remove();
50+
},
51+
},
52+
}
53+
]
54+
}
55+
]
56+
}
57+
}
58+
});
59+
}
60+
61+
export function AsyncPrompt(label, value) {
62+
return new Promise(resolve => {
63+
let area = Component.make('textarea', {
64+
text: value,
65+
events: {
66+
input: () => area.style.height = area.scrollHeight + "px",
67+
}
68+
});
69+
area.style.height = area.scrollHeight + "px";
70+
BaseDialog(label, area, () => resolve(area.value), () => resolve(null));
71+
});
72+
}
73+
74+
export function AsyncConfirm(label) {
75+
return new Promise(resolve => {
76+
BaseDialog(label, null, () => resolve(1), () => resolve(0));
77+
});
78+
}

0 commit comments

Comments
 (0)