blob: cf01b462e5005bb2e8e80c343963a8bc23aef0f7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#pragma once
#include "label.h"
#include "widget.h"
#include <iomanip>
#include <sstream>
namespace GUI
{
class LabeledControl
: public Widget
{
public:
LabeledControl(Widget* parent, const std::string& name)
: Widget(parent)
{
layout.setResizeChildren(false);
layout.setHAlignment(HAlignment::center);
layout.setSpacing(2);
caption.setText(name);
caption.resize(100, 20);
caption.setAlignment(TextAlignment::center);
layout.addItem(&caption);
}
void setControl(Knob* control)
{
layout.addItem(control);
CONNECT(control, valueChangedNotifier, this, &LabeledControl::setValue);
setValue(control->value());
value.resize(100, 20);
value.setAlignment(TextAlignment::center);
layout.addItem(&value);
}
float offset{0.0f};
float scale{1.0f};
private:
VBoxLayout layout{this};
Label caption{this};
Label value{this};
void setValue(float new_value)
{
new_value *= scale;
new_value += offset;
std::stringstream stream;
stream << std::fixed << std::setprecision(2) << new_value;
value.setText(stream.str());
}
};
}
|