Skip to content

Commit

Permalink
WIP numeric widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
darbyjohnston committed Apr 30, 2023
1 parent d696c50 commit 6f22630
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 21 deletions.
16 changes: 8 additions & 8 deletions etc/Icons/Decrement.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 10 additions & 10 deletions etc/Icons/Increment.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 15 additions & 2 deletions lib/tlUI/FloatEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ namespace tl
int digits = 3;
int precision = 2;

struct SizeData
{
int margin = 0;
};
SizeData size;

std::shared_ptr<observer::ValueObserver<float> > valueObserver;
std::shared_ptr<observer::ValueObserver<math::FloatRange> > rangeObserver;
};
Expand All @@ -34,8 +40,12 @@ namespace tl
TLRENDER_P();

p.lineEdit = LineEdit::create(context, shared_from_this());

p.incrementButton = IncButton::create(context, shared_from_this());
p.incrementButton->setIcon("Increment");

p.decrementButton = IncButton::create(context, shared_from_this());
p.decrementButton->setIcon("Decrement");

setModel(FloatModel::create(context));

Expand Down Expand Up @@ -118,7 +128,7 @@ namespace tl
const int buttonsWidth = std::max(
p.incrementButton->getSizeHint().x,
p.decrementButton->getSizeHint().x);
g.max.x -= buttonsWidth;
g.max.x -= p.size.margin + buttonsWidth;
p.lineEdit->setGeometry(g);
g = value;
g.min.x = g.max.x - buttonsWidth;
Expand All @@ -133,11 +143,14 @@ namespace tl
{
IWidget::sizeHintEvent(event);
TLRENDER_P();

p.size.margin = event.style->getSizeRole(SizeRole::MarginInside, event.displayScale);

_sizeHint = p.lineEdit->getSizeHint();
const int buttonsWidth = std::max(
p.incrementButton->getSizeHint().x,
p.decrementButton->getSizeHint().x);
_sizeHint.x += buttonsWidth;
_sizeHint.x += p.size.margin + buttonsWidth;
}

void FloatEdit::_textUpdate()
Expand Down
1 change: 1 addition & 0 deletions lib/tlUI/IncButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace tl
const std::shared_ptr<IWidget>& parent)
{
IButton::_init("tl::ui::IncButton", context, parent);
setButtonRole(ColorRole::None);
}

IncButton::IncButton() :
Expand Down
18 changes: 18 additions & 0 deletions lib/tlUI/Resources/Decrement_192.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const std::vector<uint8_t> Decrement_192_png = {
137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68,
82, 0, 0, 0, 20, 0, 0, 0, 20, 8, 6, 0, 0, 0, 141,
137, 29, 13, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 29, 135,
0, 0, 29, 135, 1, 143, 229, 241, 101, 0, 0, 0, 25, 116, 69,
88, 116, 83, 111, 102, 116, 119, 97, 114, 101, 0, 119, 119, 119, 46,
105, 110, 107, 115, 99, 97, 112, 101, 46, 111, 114, 103, 155, 238, 60,
26, 0, 0, 0, 111, 73, 68, 65, 84, 56, 141, 237, 145, 177, 13,
128, 48, 12, 4, 175, 65, 172, 128, 196, 34, 52, 204, 66, 151, 153,
96, 29, 10, 38, 65, 98, 133, 136, 6, 42, 55, 40, 137, 29, 183,
228, 36, 183, 167, 183, 14, 26, 255, 98, 3, 30, 231, 173, 41, 97,
7, 236, 14, 217, 1, 244, 185, 149, 3, 112, 86, 200, 46, 96, 212,
94, 159, 128, 104, 144, 221, 192, 172, 201, 132, 197, 32, 12, 86, 153,
80, 138, 148, 140, 160, 145, 139, 84, 140, 160, 241, 141, 100, 138, 160,
33, 145, 170, 34, 104, 4, 28, 17, 26, 62, 94, 252, 31, 79, 166,
82, 143, 225, 44, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96,
130,
};
15 changes: 15 additions & 0 deletions lib/tlUI/Resources/Decrement_96.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const std::vector<uint8_t> Decrement_96_png = {
137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68,
82, 0, 0, 0, 10, 0, 0, 0, 10, 8, 6, 0, 0, 0, 141,
50, 207, 189, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 14, 195,
0, 0, 14, 195, 1, 199, 111, 168, 100, 0, 0, 0, 25, 116, 69,
88, 116, 83, 111, 102, 116, 119, 97, 114, 101, 0, 119, 119, 119, 46,
105, 110, 107, 115, 99, 97, 112, 101, 46, 111, 114, 103, 155, 238, 60,
26, 0, 0, 0, 72, 73, 68, 65, 84, 24, 149, 99, 96, 24, 112,
48, 147, 129, 129, 225, 63, 14, 60, 3, 89, 33, 43, 3, 3, 195,
33, 44, 138, 142, 49, 48, 48, 176, 163, 155, 42, 193, 192, 192, 240,
4, 73, 209, 115, 6, 6, 6, 105, 92, 78, 176, 96, 96, 96, 248,
193, 192, 192, 240, 139, 129, 129, 193, 150, 144, 123, 211, 160, 152, 198,
0, 0, 202, 71, 19, 235, 160, 57, 234, 71, 0, 0, 0, 0, 73,
69, 78, 68, 174, 66, 96, 130,
};
18 changes: 18 additions & 0 deletions lib/tlUI/Resources/Increment_192.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const std::vector<uint8_t> Increment_192_png = {
137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68,
82, 0, 0, 0, 20, 0, 0, 0, 20, 8, 6, 0, 0, 0, 141,
137, 29, 13, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 29, 135,
0, 0, 29, 135, 1, 143, 229, 241, 101, 0, 0, 0, 25, 116, 69,
88, 116, 83, 111, 102, 116, 119, 97, 114, 101, 0, 119, 119, 119, 46,
105, 110, 107, 115, 99, 97, 112, 101, 46, 111, 114, 103, 155, 238, 60,
26, 0, 0, 0, 115, 73, 68, 65, 84, 56, 141, 237, 145, 177, 9,
128, 48, 20, 5, 175, 17, 87, 16, 156, 196, 194, 117, 204, 76, 118,
153, 197, 198, 69, 4, 87, 8, 54, 218, 248, 65, 196, 228, 199, 40,
22, 146, 7, 215, 30, 60, 14, 242, 190, 154, 1, 186, 183, 100, 13,
224, 128, 5, 104, 159, 202, 42, 96, 2, 214, 157, 25, 168, 83, 101,
5, 48, 28, 100, 194, 8, 148, 41, 194, 254, 66, 38, 216, 187, 50,
19, 144, 9, 209, 145, 36, 130, 38, 140, 138, 116, 142, 160, 17, 140,
228, 139, 160, 225, 141, 20, 138, 160, 97, 181, 235, 121, 127, 218, 6,
147, 194, 79, 195, 57, 81, 166, 32, 0, 0, 0, 0, 73, 69, 78,
68, 174, 66, 96, 130,
};
15 changes: 15 additions & 0 deletions lib/tlUI/Resources/Increment_96.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const std::vector<uint8_t> Increment_96_png = {
137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68,
82, 0, 0, 0, 10, 0, 0, 0, 10, 8, 6, 0, 0, 0, 141,
50, 207, 189, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 14, 195,
0, 0, 14, 195, 1, 199, 111, 168, 100, 0, 0, 0, 25, 116, 69,
88, 116, 83, 111, 102, 116, 119, 97, 114, 101, 0, 119, 119, 119, 46,
105, 110, 107, 115, 99, 97, 112, 101, 46, 111, 114, 103, 155, 238, 60,
26, 0, 0, 0, 78, 73, 68, 65, 84, 24, 149, 189, 206, 177, 9,
128, 48, 0, 68, 209, 215, 136, 43, 8, 78, 98, 225, 58, 58, 147,
157, 179, 216, 184, 136, 224, 10, 98, 163, 141, 129, 16, 34, 169, 244,
224, 119, 175, 56, 254, 216, 136, 161, 132, 58, 28, 56, 209, 191, 161,
6, 27, 174, 167, 29, 109, 138, 42, 44, 17, 10, 173, 168, 99, 56,
101, 80, 104, 46, 253, 253, 120, 55, 233, 149, 19, 246, 75, 18, 8,
46, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130,
};
2 changes: 1 addition & 1 deletion lib/tlUI/Style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace tl
p.sizeRoles[SizeRole::Margin] = 10;
p.sizeRoles[SizeRole::MarginSmall] = 5;
p.sizeRoles[SizeRole::MarginLarge] = 20;
p.sizeRoles[SizeRole::MarginInside] = 1;
p.sizeRoles[SizeRole::MarginInside] = 2;
p.sizeRoles[SizeRole::Spacing] = 10;
p.sizeRoles[SizeRole::SpacingSmall] = 5;
p.sizeRoles[SizeRole::SpacingLarge] = 20;
Expand Down

0 comments on commit 6f22630

Please sign in to comment.