@@ -49,6 +49,7 @@ WidgetSlider::WidgetSlider(ElementFormControl* _parent)
49
49
50
50
track = nullptr ;
51
51
bar = nullptr ;
52
+ progress = nullptr ;
52
53
arrows[0 ] = nullptr ;
53
54
arrows[1 ] = nullptr ;
54
55
@@ -69,6 +70,8 @@ WidgetSlider::~WidgetSlider()
69
70
{
70
71
if (bar)
71
72
parent->RemoveChild (bar);
73
+ if (track && progress)
74
+ track->RemoveChild (progress);
72
75
if (track)
73
76
parent->RemoveChild (track);
74
77
@@ -94,20 +97,23 @@ bool WidgetSlider::Initialise()
94
97
// Create all of our child elements as standard elements, and abort if we can't create them.
95
98
ElementPtr track_element = Factory::InstanceElement (parent, " *" , " slidertrack" , XMLAttributes ());
96
99
ElementPtr bar_element = Factory::InstanceElement (parent, " *" , " sliderbar" , XMLAttributes ());
100
+ ElementPtr progress_element = Factory::InstanceElement (parent, " *" , " sliderprogress" , XMLAttributes ());
97
101
ElementPtr arrow0_element = Factory::InstanceElement (parent, " *" , " sliderarrowdec" , XMLAttributes ());
98
102
ElementPtr arrow1_element = Factory::InstanceElement (parent, " *" , " sliderarrowinc" , XMLAttributes ());
99
103
100
- if (!track_element || !bar_element || !arrow0_element || !arrow1_element)
104
+ if (!track_element || !bar_element || !progress_element || ! arrow0_element || !arrow1_element)
101
105
return false ;
102
106
103
107
// Add them as non-DOM elements.
104
108
track = parent->AppendChild (std::move (track_element), false );
109
+ progress = track->AppendChild (std::move (progress_element), false );
105
110
bar = parent->AppendChild (std::move (bar_element), false );
106
111
arrows[0 ] = parent->AppendChild (std::move (arrow0_element), false );
107
112
arrows[1 ] = parent->AppendChild (std::move (arrow1_element), false );
108
113
109
114
const Property drag_property = Property (Style::Drag::Drag);
110
115
track->SetProperty (PropertyId::Drag, drag_property);
116
+ progress->SetProperty (PropertyId::Drag, drag_property);
111
117
bar->SetProperty (PropertyId::Drag, drag_property);
112
118
113
119
// Attach the listeners
@@ -155,6 +161,7 @@ void WidgetSlider::SetBarPosition(float _bar_position)
155
161
{
156
162
bar_position = Math::Clamp (_bar_position, 0 .0f , 1 .0f );
157
163
PositionBar ();
164
+ ResizeProgress ();
158
165
}
159
166
160
167
float WidgetSlider::GetBarPosition ()
@@ -314,12 +321,14 @@ void WidgetSlider::FormatElements(const Vector2f containing_block, float slider_
314
321
}
315
322
316
323
FormatBar ();
324
+ FormatProgress ();
317
325
318
326
if (parent->IsDisabled ())
319
327
{
320
328
// Propagate disabled state to child elements
321
329
bar->SetPseudoClass (" disabled" , true );
322
330
track->SetPseudoClass (" disabled" , true );
331
+ progress->SetPseudoClass (" disabled" , true );
323
332
arrows[0 ]->SetPseudoClass (" disabled" , true );
324
333
arrows[1 ]->SetPseudoClass (" disabled" , true );
325
334
}
@@ -346,6 +355,33 @@ void WidgetSlider::FormatBar()
346
355
PositionBar ();
347
356
}
348
357
358
+ void WidgetSlider::FormatProgress ()
359
+ {
360
+ Box progress_box;
361
+ ElementUtilities::BuildBox (progress_box, parent->GetBox ().GetSize (), progress);
362
+ auto & computed = progress->GetComputedValues ();
363
+
364
+ Vector2f progress_box_content = progress_box.GetSize ();
365
+
366
+ if (orientation == HORIZONTAL)
367
+ {
368
+ if (computed.height ().type == Style::Height::Auto)
369
+ progress_box_content.y = track->GetBox ().GetSize ().y ;
370
+ }
371
+
372
+ // Set the new dimensions on the progress element to re-decorate it.
373
+ progress_box.SetContent (progress_box_content);
374
+ progress->SetBox (progress_box);
375
+
376
+ Vector2f offset = track->GetRelativeOffset ();
377
+ offset.x += progress->GetBox ().GetEdge (BoxArea::Margin, BoxEdge::Left);
378
+ offset.y += progress->GetBox ().GetEdge (BoxArea::Margin, BoxEdge::Top);
379
+
380
+ progress->SetOffset (offset, parent);
381
+
382
+ ResizeProgress ();
383
+ }
384
+
349
385
Element* WidgetSlider::GetParent () const
350
386
{
351
387
return parent;
@@ -364,7 +400,7 @@ void WidgetSlider::ProcessEvent(Event& event)
364
400
if (event.GetParameter (" button" , -1 ) != 0 )
365
401
break ;
366
402
367
- if (event.GetTargetElement () == track)
403
+ if (event.GetTargetElement () == track || event. GetTargetElement () == progress )
368
404
{
369
405
float mouse_position, bar_halfsize;
370
406
@@ -409,7 +445,7 @@ void WidgetSlider::ProcessEvent(Event& event)
409
445
410
446
case EventId::Dragstart:
411
447
{
412
- if (event.GetTargetElement () == bar || event.GetTargetElement () == track)
448
+ if (event.GetTargetElement () == bar || event.GetTargetElement () == track || event. GetTargetElement () == progress )
413
449
{
414
450
bar->SetPseudoClass (" active" , true );
415
451
@@ -422,7 +458,7 @@ void WidgetSlider::ProcessEvent(Event& event)
422
458
break ;
423
459
case EventId::Drag:
424
460
{
425
- if (event.GetTargetElement () == bar || event.GetTargetElement () == track)
461
+ if (event.GetTargetElement () == bar || event.GetTargetElement () == track || event. GetTargetElement () == progress )
426
462
{
427
463
float new_bar_offset = event.GetParameter <float >((orientation == HORIZONTAL ? " mouse_x" : " mouse_y" ), 0 ) - bar_drag_anchor;
428
464
float new_bar_position = AbsolutePositionToBarPosition (new_bar_offset);
@@ -433,7 +469,7 @@ void WidgetSlider::ProcessEvent(Event& event)
433
469
break ;
434
470
case EventId::Dragend:
435
471
{
436
- if (event.GetTargetElement () == bar || event.GetTargetElement () == track)
472
+ if (event.GetTargetElement () == bar || event.GetTargetElement () == track || event. GetTargetElement () == progress )
437
473
{
438
474
bar->SetPseudoClass (" active" , false );
439
475
}
@@ -559,6 +595,21 @@ void WidgetSlider::PositionBar()
559
595
}
560
596
}
561
597
598
+ void WidgetSlider::ResizeProgress ()
599
+ {
600
+ Box progress_box = progress->GetBox ();
601
+ Vector2f new_size = progress_box.GetSize ();
602
+
603
+ if (orientation == VERTICAL) {
604
+ new_size.y = bar->GetOffsetTop ();
605
+ } else {
606
+ new_size.x = bar->GetOffsetLeft ();
607
+ }
608
+
609
+ progress_box.SetContent (new_size);
610
+ progress->SetBox (progress_box);
611
+ }
612
+
562
613
float WidgetSlider::SetValueInternal (float new_value, bool force_submit_change_event)
563
614
{
564
615
if (min_value < max_value)
0 commit comments