further wip clocks control

This commit is contained in:
Ilya Zlobintsev
2023-01-07 20:17:50 +02:00
parent e7228c603a
commit 6b8a7fd74b
4 changed files with 72 additions and 58 deletions

View File

@@ -1,30 +1,26 @@
use super::{oc_adjustment, section_box};
use anyhow::{anyhow, Context};
use gtk::prelude::*;
use gtk::*;
use lact_client::schema::{ClocksTable, ClocksTableGen};
use super::section_box;
#[derive(Clone)]
pub struct ClocksFrame {
pub container: Box,
pub max_sclk_adjustment: Adjustment,
pub max_mclk_adjustment: Adjustment,
max_sclk_adjustment: Adjustment,
max_mclk_adjustment: Adjustment,
}
impl ClocksFrame {
pub fn new() -> Self {
let container = section_box("Maximum Clocks");
let container = section_box("Maximum Clocks", 0, 5);
container.hide();
let max_sclk_adjustment = Adjustment::new(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
let max_mclk_adjustment = Adjustment::new(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
let (sclk_box, max_sclk_adjustment) = oc_adjustment(None, "MHz");
let (mclk_box, max_mclk_adjustment) = oc_adjustment(None, "MHz");
let max_sclk_scale = scale(&max_sclk_adjustment);
let max_mclk_scale = scale(&max_mclk_adjustment);
container.append(&max_sclk_scale);
container.append(&max_mclk_scale);
container.append(&sclk_box);
container.append(&mclk_box);
Self {
container,
@@ -59,10 +55,19 @@ impl ClocksFrame {
}
}
fn scale(adjustment: &Adjustment) -> Scale {
/*fn scale(adjustment: &Adjustment) -> Scale {
Scale::builder()
.orientation(Orientation::Horizontal)
.adjustment(adjustment)
.draw_value(true)
.hexpand(true)
.build()
}
fn range_label() -> Label {
Label::builder()
.yalign(0.7)
.margin_start(10)
.margin_end(10)
.build()
}*/

View File

@@ -4,14 +4,16 @@ mod power_cap_frame;
mod stats_grid;
mod warning_frame;
use std::{cell::Cell, rc::Rc};
use clocks_frame::ClocksFrame;
use gtk::prelude::*;
use gtk::*;
use gtk::{glib::clone, prelude::*};
use lact_client::schema::{ClocksTableGen, DeviceStats, PerformanceLevel};
use performance_level_frame::PerformanceLevelFrame;
use power_cap_frame::PowerCapFrame;
use stats_grid::StatsGrid;
use tracing::warn;
use tracing::{error, warn};
use warning_frame::WarningFrame;
#[derive(Clone)]
@@ -134,12 +136,12 @@ impl OcPage {
}
}
fn section_box(title: &str) -> Box {
fn section_box(title: &str, spacing: i32, margin: i32) -> Box {
let container = Box::builder()
.orientation(Orientation::Vertical)
.spacing(5)
.margin_start(5)
.margin_end(5)
.spacing(spacing)
.margin_start(margin)
.margin_end(margin)
.build();
let label = Label::builder()
@@ -151,3 +153,45 @@ fn section_box(title: &str) -> Box {
container.append(&label);
container
}
fn oc_adjustment(
default_value: Option<Rc<Cell<Option<f64>>>>,
value_suffix: &'static str,
) -> (Box, Adjustment) {
let root_box = Box::new(Orientation::Horizontal, 0);
let label = Label::new(None);
root_box.append(&label);
let adjustment = Adjustment::new(0.0, 0.0, 0.0, 1.0, 10.0, 0.0);
adjustment.connect_value_changed(clone!(@strong label => move |adj| {
let text = format!("{}/{} {}", adj.value().round(), adj.upper(), value_suffix);
label.set_label(&text);
}));
let scale = Scale::builder()
.orientation(Orientation::Horizontal)
.adjustment(&adjustment)
.hexpand(true)
.round_digits(0)
.build();
scale.set_draw_value(false);
root_box.append(&scale);
if let Some(default_value) = default_value {
let reset_button = Button::with_label("Default");
reset_button.connect_clicked(clone!(@strong adjustment => move |_| {
if let Some(cap) = default_value.get() {
adjustment.set_value(cap);
} else {
error!("Could not set default cap, value not provided");
}
}));
root_box.append(&reset_button);
}
(root_box, adjustment)
}

View File

@@ -12,7 +12,7 @@ pub struct PerformanceLevelFrame {
impl PerformanceLevelFrame {
pub fn new() -> Self {
let container = section_box("Performance level");
let container = section_box("Performance level", 5, 5);
let root_box = Box::new(Orientation::Horizontal, 5);

View File

@@ -1,9 +1,7 @@
use super::section_box;
use glib::clone;
use super::{oc_adjustment, section_box};
use gtk::prelude::*;
use gtk::*;
use std::{cell::Cell, rc::Rc};
use tracing::error;
#[derive(Clone)]
pub struct PowerCapFrame {
@@ -14,42 +12,9 @@ pub struct PowerCapFrame {
impl PowerCapFrame {
pub fn new() -> Self {
let container = section_box("Power Usage Limit");
let root_box = Box::new(Orientation::Horizontal, 0);
let label = Label::new(None);
root_box.append(&label);
let adjustment = Adjustment::new(0.0, 0.0, 0.0, 1.0, 10.0, 0.0);
adjustment.connect_value_changed(clone!(@strong label => move |adj| {
label.set_markup(&format!("{}/{} W", adj.value().round(), adj.upper()));
}));
let scale = Scale::builder()
.orientation(Orientation::Horizontal)
.adjustment(&adjustment)
.hexpand(true)
.build();
scale.set_draw_value(false);
root_box.append(&scale);
let container = section_box("Power Usage Limit", 5, 5);
let default_cap = Rc::new(Cell::new(None));
let reset_button = Button::with_label("Default");
reset_button.connect_clicked(clone!(@strong adjustment, @strong default_cap => move |_| {
if let Some(cap) = default_cap.get() {
adjustment.set_value(cap);
} else {
error!("Could not set default cap, value not provided");
}
}));
root_box.append(&reset_button);
let (root_box, adjustment) = oc_adjustment(Some(default_cap.clone()), "W");
container.append(&root_box);
Self {