generated from OBJNULL/Dockerized-Rust
App uses backend to created prices on slint
This commit is contained in:
parent
494b38a89b
commit
2a2ee14a15
1 changed files with 38 additions and 3 deletions
|
@ -1,6 +1,10 @@
|
|||
// Libraries
|
||||
slint::include_modules!();
|
||||
use slint::{ModelRc, SharedString, VecModel};
|
||||
use std::io::Result;
|
||||
use std::rc::Rc;
|
||||
|
||||
use super::Backend;
|
||||
|
||||
// Macros
|
||||
macro_rules! map_err {
|
||||
|
@ -11,7 +15,8 @@ macro_rules! map_err {
|
|||
|
||||
// Structures
|
||||
pub struct App {
|
||||
app: Prorater,
|
||||
app: Rc<Prorater>,
|
||||
backend: Rc<Backend>,
|
||||
}
|
||||
|
||||
// Implementations
|
||||
|
@ -23,12 +28,28 @@ impl App {
|
|||
/// ```rs
|
||||
/// let app = App::new()?;
|
||||
/// ```
|
||||
pub fn new() -> Result<Self> {
|
||||
pub fn new(backend: Rc<Backend>) -> Result<Self> {
|
||||
// Creating our new app
|
||||
let app = map_err!(Prorater::new())?;
|
||||
|
||||
// Setting the Membership Options
|
||||
let memberships = {
|
||||
let vec_model: VecModel<SharedString> = {
|
||||
let result = VecModel::from(vec![SharedString::from("Select One...")]);
|
||||
for i in backend.get_memberships() {
|
||||
result.push(SharedString::from(i));
|
||||
}
|
||||
result
|
||||
};
|
||||
ModelRc::new(vec_model)
|
||||
};
|
||||
app.set_membership_names(memberships.clone());
|
||||
|
||||
// Turning the App into an Rc
|
||||
let app = Rc::new(app);
|
||||
|
||||
// Returning Self
|
||||
Ok(Self { app })
|
||||
Ok(Self { app, backend })
|
||||
}
|
||||
|
||||
// Functions
|
||||
|
@ -39,6 +60,20 @@ impl App {
|
|||
/// app.start()?;
|
||||
/// ```
|
||||
pub fn start(&self) -> Result<()> {
|
||||
// Creating an Rc of our App
|
||||
let app = Rc::clone(&self.app);
|
||||
|
||||
// Setting the on_submit function
|
||||
self.app.on_on_calculate(move || {
|
||||
// Getting the prices of the stuff
|
||||
let current_membership = app.get_current_membership();
|
||||
let new_membership = app.get_new_membership();
|
||||
|
||||
// DEBUG
|
||||
println!("Current Membership: {}", current_membership);
|
||||
println!("New Membership: {}", new_membership);
|
||||
});
|
||||
|
||||
// Starting our application
|
||||
map_err!(self.app.run())?;
|
||||
|
||||
|
|
Loading…
Reference in a new issue