-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4fa9c7d
commit 457a80f
Showing
5 changed files
with
162 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
102 changes: 102 additions & 0 deletions
102
lact-gui/src/app/root_stack/oc_page/power_cap_section.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
use crate::app::page_section::PageSection; | ||
use gtk::glib::{self, subclass::types::ObjectSubclassIsExt, Object}; | ||
|
||
glib::wrapper! { | ||
pub struct PowerCapSection(ObjectSubclass<imp::PowerCapSection>) | ||
@extends PageSection, gtk::Box, gtk::Widget, | ||
@implements gtk::Orientable, gtk::Accessible, gtk::Buildable; | ||
} | ||
|
||
impl PowerCapSection { | ||
pub fn new() -> Self { | ||
Object::builder().build() | ||
} | ||
|
||
pub fn get_user_cap(&self) -> Option<f64> { | ||
let imp = self.imp(); | ||
imp.adjustment.get_changed_value(true) | ||
} | ||
|
||
pub fn set_initial_value(&self, value: f64) { | ||
self.imp().adjustment.set_initial_value(value); | ||
} | ||
} | ||
|
||
impl Default for PowerCapSection { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
mod imp { | ||
use crate::app::{page_section::PageSection, root_stack::oc_page::oc_adjustment::OcAdjustment}; | ||
use gtk::{ | ||
glib::{self, clone, subclass::InitializingObject, Properties, StaticTypeExt}, | ||
prelude::{ButtonExt, ObjectExt}, | ||
subclass::{ | ||
prelude::*, | ||
widget::{CompositeTemplateClass, WidgetImpl}, | ||
}, | ||
Button, CompositeTemplate, | ||
}; | ||
use std::cell::RefCell; | ||
|
||
#[derive(CompositeTemplate, Default, Properties)] | ||
#[properties(wrapper_type = super::PowerCapSection)] | ||
#[template(file = "ui/oc_page/power_cap_section.blp")] | ||
pub struct PowerCapSection { | ||
#[property(get, set)] | ||
pub current_value: RefCell<f64>, | ||
#[property(get, set)] | ||
pub max_value: RefCell<f64>, | ||
#[property(get, set)] | ||
pub min_value: RefCell<f64>, | ||
#[property(get, set)] | ||
pub default_value: RefCell<f64>, | ||
#[property(get, set)] | ||
pub value_text: RefCell<String>, | ||
|
||
#[template_child] | ||
pub adjustment: TemplateChild<OcAdjustment>, | ||
#[template_child] | ||
pub reset_button: TemplateChild<Button>, | ||
} | ||
|
||
#[glib::object_subclass] | ||
impl ObjectSubclass for PowerCapSection { | ||
const NAME: &'static str = "PowerCapSection"; | ||
type Type = super::PowerCapSection; | ||
type ParentType = PageSection; | ||
|
||
fn class_init(class: &mut Self::Class) { | ||
OcAdjustment::ensure_type(); | ||
class.bind_template(); | ||
} | ||
|
||
fn instance_init(obj: &InitializingObject<Self>) { | ||
obj.init_template(); | ||
} | ||
} | ||
|
||
#[glib::derived_properties] | ||
impl ObjectImpl for PowerCapSection { | ||
fn constructed(&self) { | ||
self.parent_constructed(); | ||
|
||
let obj = self.obj(); | ||
|
||
obj.connect_current_value_notify(clone!(@strong obj => move |section| { | ||
let text = format!("{}/{} W", section.current_value(), section.max_value()); | ||
section.set_value_text(text); | ||
})); | ||
|
||
self.reset_button | ||
.connect_clicked(clone!(@strong obj => move |_| { | ||
obj.set_current_value(obj.default_value()); | ||
})); | ||
} | ||
} | ||
|
||
impl WidgetImpl for PowerCapSection {} | ||
impl BoxImpl for PowerCapSection {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Gtk 4.0; | ||
|
||
template $PowerCapSection: $PageSection { | ||
name: "Power usage limit"; | ||
|
||
Box { | ||
orientation: horizontal; | ||
|
||
Label value_label { | ||
label: bind template.value-text; | ||
} | ||
|
||
Scale { | ||
orientation: horizontal; | ||
hexpand: true; | ||
round-digits: 0; | ||
margin-start: 5; | ||
margin-end: 5; | ||
draw-value: false; | ||
adjustment: adjustment; | ||
} | ||
|
||
Button reset_button { | ||
label: "Default"; | ||
} | ||
} | ||
} | ||
|
||
$OcAdjustment adjustment { | ||
value: bind template.current-value bidirectional; | ||
lower: bind template.min-value; | ||
upper: bind template.max-value; | ||
} |