@@ -49,10 +49,7 @@ void flush()
4949}
5050
5151// / The value field a slider owns, so a typed commit can be exercised.
52- QLineEdit *field_of (QWidget *slider)
53- {
54- return slider->findChild <QLineEdit *>();
55- }
52+ QLineEdit *field_of (QWidget *slider) { return slider->findChild <QLineEdit *>(); }
5653
5754// / Press, drag and release at `x`, which is how a rail is actually driven.
5855void click_rail (QWidget *slider, int x)
@@ -125,8 +122,7 @@ int main(int argc, char **argv)
125122 const float linear_value = linear_slider.get ();
126123 const float log_value = log_slider.get ();
127124
128- std::cout << " same press: linear=" << linear_value << " log=" << log_value
129- << ' \n ' ;
125+ std::cout << " same press: linear=" << linear_value << " log=" << log_value << ' \n ' ;
130126
131127 check (linear_value > 0 .f , " the linear rail responded to a press" );
132128 check (log_value < linear_value,
@@ -170,8 +166,7 @@ int main(int argc, char **argv)
170166 Q_EMIT field->editingFinished ();
171167 flush ();
172168
173- check (slider.get () > 64 .f ,
174- " a typed value above the rail maximum is accepted" );
169+ check (slider.get () > 64 .f , " a typed value above the rail maximum is accepted" );
175170 check (std::abs (slider.get () - 512 .f ) < 1e-2f ,
176171 " a typed value is held to the real maximum, not to the rail" );
177172 }
@@ -203,8 +198,53 @@ int main(int argc, char **argv)
203198 Q_EMIT field->editingFinished ();
204199 flush ();
205200
206- check (slider.get () <= 64 .f ,
207- " a hard maximum of 64 still clamps a typed value" );
201+ check (slider.get () <= 64 .f , " a hard maximum of 64 still clamps a typed value" );
202+ }
203+ }
204+
205+ // --- the readout honours the declared presentation type -----------------
206+ //
207+ // HydraulicParticle declares its rates as "{:.2e}" over [1e-6, 1e-1]. Rendered
208+ // fixed, 1e-3 comes out as 0.00100000 and overruns the value field; Otto saw
209+ // it clipped to a run of zeroes with no decimal point in sight.
210+ {
211+ auto *attr = make_attr (container, " drag_rate" , 1e-3f , 1e-6f , 1e-1f );
212+ attr->metadata ().add (meta::keys::ui::format, std::string (" {:.2e}" ));
213+ attr->metadata ().add (meta::keys::ui::log_scale, true );
214+
215+ industrial::ParamSlider slider (*attr, ctx);
216+ slider.resize (400 , 36 );
217+ flush ();
218+
219+ QLineEdit *field = field_of (&slider);
220+ check (field != nullptr , " the rate slider has a value field" );
221+
222+ if (field)
223+ {
224+ std::cout << " scientific readout: " << field->text ().toStdString () << ' \n ' ;
225+ check (field->text ().contains (' e' ) || field->text ().contains (' E' ),
226+ " a {:.2e} attribute renders with an exponent" );
227+ check (field->text ().size () <= 10 ,
228+ " the scientific readout is short enough for the value field" );
229+ }
230+ }
231+
232+ // --- a fixed spec still widens rather than rounding a small value away ---
233+ {
234+ auto *attr = make_attr (container, " fixed_small" , 0 .001f , 0 .f , 1 .f );
235+ attr->metadata ().add (meta::keys::ui::format, std::string (" {:.2f}" ));
236+
237+ industrial::ParamSlider slider (*attr, ctx);
238+ slider.resize (400 , 36 );
239+ flush ();
240+
241+ QLineEdit *field = field_of (&slider);
242+ if (field)
243+ {
244+ std::cout << " fixed readout: " << field->text ().toStdString () << ' \n ' ;
245+ check (field->text () != " 0.00" ,
246+ " a small value under a fixed spec does not read as zero" );
247+ check (!field->text ().contains (' e' ), " a fixed spec is not promoted to scientific" );
208248 }
209249 }
210250
0 commit comments