Skip to content

Commit

Permalink
Fix support normalized ranges for Slider with Qt style
Browse files Browse the repository at this point in the history
The OpenGL Texture import example uses a Slider in the range 0..1. That doesn't work with
QStyleOptionSlider out of the box because it's
using integer values.
  • Loading branch information
tronical committed Jun 28, 2023
1 parent c8185a9 commit 358d2b9
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions internal/backends/qt/qt_widgets/slider.rs
Expand Up @@ -36,12 +36,13 @@ pub struct NativeSlider {
}

cpp! {{
void initQSliderOptions(QStyleOptionSlider &option, bool pressed, bool enabled, int active_controls, int minimum, int maximum, int value) {
void initQSliderOptions(QStyleOptionSlider &option, bool pressed, bool enabled, int active_controls, float minimum, float maximum, float float_value) {
option.subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderHandle;
option.activeSubControls = { active_controls };
option.orientation = Qt::Horizontal;
option.maximum = maximum;
option.minimum = minimum;
option.maximum = maximum * 1024;
option.minimum = minimum * 1024;
int value = float_value * 1024;
option.sliderPosition = value;
option.sliderValue = value;
if (enabled) {
Expand Down Expand Up @@ -72,18 +73,18 @@ impl Item for NativeSlider {
_window_adapter: &Rc<dyn WindowAdapter>,
) -> LayoutInfo {
let enabled = self.enabled();
let value = self.value() as i32;
let min = self.minimum() as i32;
let max = self.maximum() as i32;
let value = self.value() as f32;
let min = self.minimum() as f32;
let max = self.maximum() as f32;
let data = self.data();
let active_controls = data.active_controls;
let pressed = data.pressed;

let size = cpp!(unsafe [
enabled as "bool",
value as "int",
min as "int",
max as "int",
value as "float",
min as "float",
max as "float",
active_controls as "int",
pressed as "bool"
] -> qttypes::QSize as "QSize" {
Expand Down Expand Up @@ -222,9 +223,9 @@ impl Item for NativeSlider {

fn_render! { this dpr size painter widget initial_state =>
let enabled = this.enabled();
let value = this.value() as i32;
let min = this.minimum() as i32;
let max = this.maximum() as i32;
let value = this.value() as f32;
let min = this.minimum() as f32;
let max = this.maximum() as f32;
let data = this.data();
let active_controls = data.active_controls;
let pressed = data.pressed;
Expand All @@ -233,9 +234,9 @@ impl Item for NativeSlider {
painter as "QPainterPtr*",
widget as "QWidget*",
enabled as "bool",
value as "int",
min as "int",
max as "int",
value as "float",
min as "float",
max as "float",
size as "QSize",
active_controls as "int",
pressed as "bool",
Expand Down

0 comments on commit 358d2b9

Please sign in to comment.