mirror of
https://github.com/ilya-zlobintsev/LACT.git
synced 2026-08-19 01:14:43 -05:00
fix: apply no_scroll fix to SpinButtons on thermals page (#981)
This commit is contained in:
+40
-2
@@ -1,7 +1,10 @@
|
||||
use gtk::{
|
||||
FlowBox, FlowBoxChild, Widget,
|
||||
glib::object::{Cast, IsA},
|
||||
prelude::WidgetExt,
|
||||
glib::{
|
||||
object::{Cast, IsA},
|
||||
types::StaticType,
|
||||
},
|
||||
prelude::{AdjustmentExt, EventControllerExt, WidgetExt},
|
||||
};
|
||||
use relm4::Component;
|
||||
|
||||
@@ -33,3 +36,38 @@ impl<S: Default, T: Component<Init = S>> RelmDefaultLauchable for T {
|
||||
Self::builder().launch(S::default())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn make_event_controller_no_scroll() -> gtk::EventControllerScroll {
|
||||
let controller = gtk::EventControllerScroll::new(
|
||||
gtk::EventControllerScrollFlags::VERTICAL | gtk::EventControllerScrollFlags::HORIZONTAL,
|
||||
);
|
||||
controller.connect_scroll(|controller, dx, dy| {
|
||||
if let Some(parent) = controller
|
||||
.widget()
|
||||
.and_then(|widget| widget.ancestor(gtk::ScrolledWindow::static_type()))
|
||||
{
|
||||
let scrolled_window = parent.downcast::<gtk::ScrolledWindow>().unwrap();
|
||||
|
||||
if dy != 0.0 {
|
||||
let current = scrolled_window.vadjustment().value();
|
||||
let step = scrolled_window.vadjustment().step_increment();
|
||||
|
||||
// This is a bit of a hack, fractional values are generally touchpad inputs (in pixels),
|
||||
// while whole values are scroll wheel events (which should use the `step` value)
|
||||
// With newer GTK this should be changed to getting `unit()` from the scroll controller
|
||||
let delta = if dy.fract() == 0.0 { dy * step } else { dy };
|
||||
scrolled_window.vadjustment().set_value(current + delta);
|
||||
}
|
||||
|
||||
if dx != 0.0 {
|
||||
let current = scrolled_window.hadjustment().value();
|
||||
let step = scrolled_window.hadjustment().step_increment();
|
||||
let delta = if dx.fract() == 0.0 { dy * step } else { dy };
|
||||
scrolled_window.hadjustment().set_value(current + delta);
|
||||
}
|
||||
}
|
||||
|
||||
gtk::glib::Propagation::Stop
|
||||
});
|
||||
controller
|
||||
}
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
use crate::{
|
||||
APP_BROKER, I18N,
|
||||
app::{msg::AppMsg, pages::oc_adjustment::OcAdjustment},
|
||||
app::{ext::make_event_controller_no_scroll, msg::AppMsg, pages::oc_adjustment::OcAdjustment},
|
||||
};
|
||||
use gtk::{
|
||||
glib::{
|
||||
SignalHandlerId,
|
||||
object::{Cast, ObjectExt},
|
||||
types::StaticType,
|
||||
},
|
||||
prelude::{AdjustmentExt, EventControllerExt, OrientableExt, RangeExt, ScaleExt, WidgetExt},
|
||||
glib::{SignalHandlerId, object::ObjectExt},
|
||||
prelude::{AdjustmentExt, OrientableExt, RangeExt, ScaleExt, WidgetExt},
|
||||
};
|
||||
use i18n_embed_fl::fl;
|
||||
use lact_schema::request::ClockspeedType;
|
||||
@@ -193,38 +189,3 @@ impl ClockAdjustmentRow {
|
||||
(self.adjustment.value() / self.value_ratio) as i32
|
||||
}
|
||||
}
|
||||
|
||||
fn make_event_controller_no_scroll() -> gtk::EventControllerScroll {
|
||||
let controller = gtk::EventControllerScroll::new(
|
||||
gtk::EventControllerScrollFlags::VERTICAL | gtk::EventControllerScrollFlags::HORIZONTAL,
|
||||
);
|
||||
controller.connect_scroll(|controller, dx, dy| {
|
||||
if let Some(parent) = controller
|
||||
.widget()
|
||||
.and_then(|widget| widget.ancestor(gtk::ScrolledWindow::static_type()))
|
||||
{
|
||||
let scrolled_window = parent.downcast::<gtk::ScrolledWindow>().unwrap();
|
||||
|
||||
if dy != 0.0 {
|
||||
let current = scrolled_window.vadjustment().value();
|
||||
let step = scrolled_window.vadjustment().step_increment();
|
||||
|
||||
// This is a bit of a hack, fractional values are generally touchpad inputs (in pixels),
|
||||
// while whole values are scroll wheel events (which should use the `step` value)
|
||||
// With newer GTK this should be changed to getting `unit()` from the scroll controller
|
||||
let delta = if dy.fract() == 0.0 { dy * step } else { dy };
|
||||
scrolled_window.vadjustment().set_value(current + delta);
|
||||
}
|
||||
|
||||
if dx != 0.0 {
|
||||
let current = scrolled_window.hadjustment().value();
|
||||
let step = scrolled_window.hadjustment().step_increment();
|
||||
let delta = if dx.fract() == 0.0 { dy * step } else { dy };
|
||||
scrolled_window.hadjustment().set_value(current + delta);
|
||||
}
|
||||
}
|
||||
|
||||
gtk::glib::Propagation::Stop
|
||||
});
|
||||
controller
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
mod fan_curve_frame;
|
||||
|
||||
use super::{PageUpdate, oc_adjustment::OcAdjustment};
|
||||
use crate::app::ext::FlowBoxExt;
|
||||
use crate::app::ext::{FlowBoxExt, make_event_controller_no_scroll};
|
||||
use crate::{
|
||||
APP_BROKER, I18N,
|
||||
app::{
|
||||
@@ -593,11 +593,13 @@ impl relm4::WidgetTemplate for FanSettingRow {
|
||||
set_round_digits: 0,
|
||||
set_value_pos: gtk::PositionType::Right,
|
||||
set_margin_horizontal: 5,
|
||||
add_controller = make_event_controller_no_scroll(),
|
||||
},
|
||||
|
||||
#[name = "spinbutton"]
|
||||
gtk::SpinButton {
|
||||
set_width_request: 120,
|
||||
add_controller = make_event_controller_no_scroll(),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user