From f6393a39262bd783136074a83b43f17f7cea78cc Mon Sep 17 00:00:00 2001 From: "Luke D. Jones" Date: Wed, 13 Mar 2024 23:30:06 +1300 Subject: [PATCH] Further fan-curve graph work --- asusd/src/ctrl_fancurves.rs | 4 +- rog-control-center/ui/widgets/graph.slint | 130 ++++++++++++++++++++-- 2 files changed, 120 insertions(+), 14 deletions(-) diff --git a/asusd/src/ctrl_fancurves.rs b/asusd/src/ctrl_fancurves.rs index 5f885303..dbf0da75 100644 --- a/asusd/src/ctrl_fancurves.rs +++ b/asusd/src/ctrl_fancurves.rs @@ -1,7 +1,5 @@ use std::path::PathBuf; use std::sync::Arc; -use std::thread::sleep; -use std::time::Duration; use config_traits::{StdConfig, StdConfigLoad}; use futures_lite::StreamExt; @@ -73,11 +71,11 @@ impl CtrlFanCurveZbus { ThrottlePolicy::Performance, ThrottlePolicy::Quiet, ] { - let mut dev = find_fan_curve_node()?; // For each profile we need to switch to it before we // can read the existing values from hardware. The ACPI method used // for this is what limits us. platform.set_throttle_thermal_policy(this.into())?; + let mut dev = find_fan_curve_node()?; fan_curves.set_active_curve_to_defaults(this, &mut dev)?; info!("{MOD_NAME}: {this:?}:"); diff --git a/rog-control-center/ui/widgets/graph.slint b/rog-control-center/ui/widgets/graph.slint index 7722827e..2a9a83d7 100644 --- a/rog-control-center/ui/widgets/graph.slint +++ b/rog-control-center/ui/widgets/graph.slint @@ -6,7 +6,19 @@ export component Graph inherits Rectangle { in-out property <[Node]> nodes; in property node_min: { x: 0px, y: 0px }; in property node_max: { x: 100px, y: 255px }; - property graph_padding: 20px; + property graph_padding: 40px; + property axis_font_size: 14px; + // Text { + // x: 0; + // text: "Fan PWM"; + // } + + // Text { + // x: root.width / 2; + // y: root.height - self.height; + // text: "Temperature"; + // } + graph := Rectangle { width: root.width - root.graph_padding * 2; height: root.height - root.graph_padding * 2; @@ -14,13 +26,66 @@ export component Graph inherits Rectangle { y: root.graph_padding; function scale_x_to_graph(x: length) -> length { ((x - node_min.x) / (node_max.x - node_min.x)) * graph.width - }function scale_y_to_graph(y: length) -> length { + }// + function scale_y_to_graph(y: length) -> length { ((y - node_min.y) / (node_max.y - node_min.y)) * graph.height - }function scale_x_to_node(x: length) -> length { + }// + function scale_x_to_node(x: length) -> length { (x / graph.width) * (node_max.x - node_min.x) - }function scale_y_to_node(y: length) -> length { + }// + function scale_y_to_node(y: length) -> length { (y / graph.height) * (node_max.y - node_min.y) - }for l[idx] in nodes: path := Rectangle { + }// + + for n in 11: Path { + viewbox-width: self.width / 1px; + viewbox-height: self.height / 1px; + stroke: Palette.alternate-foreground.darker(200%); + stroke-width: 1px; + MoveTo { + x: scale_x_to_graph(n*10px) / 1px; + y: 0; // scale_y_to_graph(n*1px) / 1px; + } + + LineTo { + x: scale_x_to_graph(n*10px) / 1px; + y: graph.height / 1px; //scale_y_to_graph(n*1px) / 1px; + } + } + + for n in 11: Text { + color: Palette.accent-background; + font-size <=> root.axis_font_size; + text: "\{n*10}c"; + x: scale_x_to_graph(n*10px) - self.width / 3; + y: graph.height + 2px; + } + + for n in 11: Path { + viewbox-width: self.width / 1px; + viewbox-height: self.height / 1px; + stroke: Palette.alternate-foreground.darker(200%); + stroke-width: 1px; + MoveTo { + x: 0; //scale_x_to_graph(n*10px) / 1px; + y: scale_y_to_graph(n*25.5px) / 1px; + } + + LineTo { + x: graph.width / 1px; //scale_x_to_graph(n*10px) / 1px; + y: scale_y_to_graph(n*25.5px) / 1px; + } + } + + for n in 11: Text { + color: Palette.accent-background; + font-size <=> root.axis_font_size; + text: "\{n*10}%"; + x: - self.width; + y: graph.height - scale_y_to_graph(n*25.5px) - self.height / 2; + } + + for l[idx] in nodes: path := Rectangle { if idx + 1 != nodes.length: Path { viewbox-width: self.width / 1px; viewbox-height: self.height / 1px; @@ -40,13 +105,18 @@ export component Graph inherits Rectangle { for n[idx] in nodes: Rectangle { states [ - pressed when touch.pressed: { - state.background: Palette.selection-background; + pressed when touch.pressed: { + point.background: Palette.selection-background; + tip.background: Palette.selection-background; + tip.opacity: 1.0; } hover when touch.has-hover: { - state.background: Palette.accent-background; + point.background: Palette.accent-background; + tip.background: Palette.accent-background; + tip.opacity: 1.0; } - ]state := Rectangle { + ]// + point := Rectangle { background: Palette.control-foreground; x: scale_x_to_graph(n.x) - self.width / 2; y: graph.height - scale_y_to_graph(n.y) - self.height / 2; @@ -94,13 +164,14 @@ export component Graph inherits Rectangle { n.y = nodes[idx - 1].y + pad; } } - }moved => { + }// + moved => { if (self.pressed) { n.x += scale_x_to_node(self.mouse-x - self.pressed-x); n.y -= scale_y_to_node(self.mouse-y - self.pressed-y); self.check(); // nodes[idx] = n; - } + } } clicked => { @@ -109,6 +180,43 @@ export component Graph inherits Rectangle { mouse-cursor: move; } } + + tip := Rectangle { + background: Palette.control-foreground; + opacity: 0.3; + x: final_x_pos(); + y: final_y_pos(); + width: label.preferred-width; + height: label.preferred-height; + function x_pos() -> length { + scale_x_to_graph(n.x) - label.preferred-width - 8px + }// + function final_x_pos() -> length { + if x_pos() > 0 { + x_pos() + } else { + x_pos() + label.preferred-width + } + }// + function y_pos() -> length { + graph.height - scale_y_to_graph(n.y) - self.height - 4px + }// + function final_y_pos() -> length { + if y_pos() > 0 { + y_pos() + } else { + y_pos() + label.preferred-height + } + }// + function fan_pct() -> int { + Math.floor(n.y / 1px) / 255 * 100 + }// + label := Text { + color: Palette.accent-foreground; + font-size: 16px; + text: "\{Math.floor(n.x / 1px)}c, \{fan_pct()}%"; + } + } } } }