generated from OBJNULL/Dockerized-Rust
Compare commits
No commits in common. "d4b7b500c8bdc0d12cf6bbff3294bf913380146b" and "78b3460019d85d39d6c09517c3e112c3a92de0ad" have entirely different histories.
d4b7b500c8
...
78b3460019
4 changed files with 5 additions and 169 deletions
|
@ -1,10 +1,6 @@
|
|||
// 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 {
|
||||
|
@ -15,8 +11,7 @@ macro_rules! map_err {
|
|||
|
||||
// Structures
|
||||
pub struct App {
|
||||
app: Rc<Prorater>,
|
||||
backend: Rc<Backend>,
|
||||
app: Prorater,
|
||||
}
|
||||
|
||||
// Implementations
|
||||
|
@ -28,28 +23,12 @@ impl App {
|
|||
/// ```rs
|
||||
/// let app = App::new()?;
|
||||
/// ```
|
||||
pub fn new(backend: Rc<Backend>) -> Result<Self> {
|
||||
pub fn new() -> 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, backend })
|
||||
Ok(Self { app })
|
||||
}
|
||||
|
||||
// Functions
|
||||
|
@ -60,20 +39,6 @@ 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())?;
|
||||
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
// Libraries
|
||||
use std::io::Result;
|
||||
|
||||
// Structures
|
||||
pub struct Backend {
|
||||
memberships: Vec<String>,
|
||||
}
|
||||
|
||||
// Implementations
|
||||
impl Backend {
|
||||
// Constructors
|
||||
/// Creates a new Backend
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `fetch` - Uses the **Internet** to fetch the latest prices for memberships.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```rs
|
||||
/// let backend = Backend::new(true)?;
|
||||
/// ```
|
||||
pub fn new(fetch: bool) -> Result<Self> {
|
||||
// Did we want to fetch our prices?
|
||||
let memberships: Vec<String> = if fetch {
|
||||
// Use Internet to get prices
|
||||
unimplemented!("TODO: Implement online Membership Price Fetching");
|
||||
} else {
|
||||
// Manually creating our prices
|
||||
vec![
|
||||
"Super ($41.99)".to_string(),
|
||||
"Deluxe ($36.99)".to_string(),
|
||||
"Standard ($31.99)".to_string(),
|
||||
"Basic ($26.99)".to_string(),
|
||||
]
|
||||
};
|
||||
|
||||
// Return Self
|
||||
Ok(Self { memberships })
|
||||
}
|
||||
|
||||
// Functions
|
||||
/// Gets the list of current memberships
|
||||
///
|
||||
/// # Examples
|
||||
/// ```rs
|
||||
/// app.set_membership_names(backend.get_memberships());
|
||||
/// ```
|
||||
pub fn get_memberships(&self) -> Vec<String> {
|
||||
self.memberships.clone()
|
||||
}
|
||||
}
|
|
@ -2,17 +2,12 @@
|
|||
mod app;
|
||||
use app::App;
|
||||
mod backend;
|
||||
use backend::Backend;
|
||||
use std::io::Result;
|
||||
use std::rc::Rc;
|
||||
|
||||
// Entry Point
|
||||
fn main() -> Result<()> {
|
||||
// Creating a Backend
|
||||
let backend = Rc::new(Backend::new(false)?);
|
||||
|
||||
// Creating a new App
|
||||
let app = App::new(Rc::clone(&backend))?;
|
||||
let app = App::new()?;
|
||||
|
||||
// Starting our App
|
||||
app.start()?;
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
import { DatePickerPopup, Button, VerticalBox, HorizontalBox, ComboBox } from "std-widgets.slint";
|
||||
import { Button, VerticalBox, HorizontalBox } from "std-widgets.slint";
|
||||
|
||||
export component Prorater inherits Window {
|
||||
title: "Auto Spa Express - Prorater";
|
||||
width: 1024px;
|
||||
height: 720px;
|
||||
|
||||
in property <[string]> membership_names: ["Select One..."];
|
||||
out property <string> current_membership;
|
||||
out property <string> new_membership;
|
||||
callback on_calculate();
|
||||
|
||||
VerticalBox {
|
||||
Image {
|
||||
source: @image-url("../data/logo.png");
|
||||
|
@ -22,74 +17,5 @@ export component Prorater inherits Window {
|
|||
font-size: 4rem;
|
||||
horizontal-alignment: center;
|
||||
}
|
||||
|
||||
VerticalBox {
|
||||
HorizontalBox {
|
||||
VerticalBox {
|
||||
Text {
|
||||
text: "Current Membership";
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
current_membership := ComboBox {
|
||||
model: root.membership_names;
|
||||
current-index: 0;
|
||||
selected(current-value) => {
|
||||
root.current_membership = current-value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VerticalBox {
|
||||
Text {
|
||||
text: "New Membership";
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
new_membership := ComboBox {
|
||||
model: root.membership_names;
|
||||
current-index: 0;
|
||||
selected(current-value) => {
|
||||
root.new_membership = current-value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VerticalBox {
|
||||
HorizontalBox {
|
||||
last_billing_date := Button {
|
||||
text: "Last Billing Date";
|
||||
clicked => {
|
||||
date-picker.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VerticalBox {
|
||||
Button {
|
||||
text: "Calculate";
|
||||
clicked => {
|
||||
on_calculate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
date_picker := DatePickerPopup {
|
||||
x: (root.width - self.width) / 2;
|
||||
y: (root.height - self.height) / 2;
|
||||
close-policy: PopupClosePolicy.no-auto-close;
|
||||
|
||||
accepted(date) => {
|
||||
date_picker.close();
|
||||
last-billing-date.text = date.month + "/" + date.day + "/" + date.year;
|
||||
}
|
||||
|
||||
canceled => {
|
||||
date-picker.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue