Skip to content

Commit

Permalink
Add all buttons/labels, introduce GUI state
Browse files Browse the repository at this point in the history
  • Loading branch information
devyntk committed Jun 12, 2020
1 parent 467d97e commit 40777d0
Showing 1 changed file with 35 additions and 50 deletions.
85 changes: 35 additions & 50 deletions src/gui.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use druid::{WindowDesc, AppLauncher, Widget, WidgetExt};
use druid::widget::{Flex, Button};
use druid::{WindowDesc, AppLauncher, Widget, WidgetExt, Data, Lens};
use druid::widget::{Flex, Button, Label};

use webbrowser;

Expand All @@ -8,65 +8,50 @@ use crate::update::{fetch_is_new, UpdateStatus};
pub fn run_ui () {
let main_window = WindowDesc::new(ui_builder)
.title("Streamline Server Control");
let data = 0_u32;

let inital_state = GUIState {
status: "Server Not Running".into(),
feedback: "".into()
};

AppLauncher::with_window(main_window)
.use_simple_logger()
.launch(data)
.launch(inital_state)
.expect("Launch failed");
}

fn ui_builder() -> impl Widget<u32> {
#[derive(Clone, Data, Lens)]
struct GUIState {
status: String,
feedback: String
}

fn ui_builder() -> impl Widget<GUIState> {
let mut status_label = Label::new("Server Status : Not Running").padding(5.0);

let mut feedback_label = Label::new("");

let quit_button = Button::new("Quit").padding(5.0);

let check_button = Button::new("Check for Updates").padding(5.0);

let open_button = Button::new("Open Browser")
.on_click(move |_ctx, data: &mut GUIState, _env| {
if webbrowser::open("http://localhost").is_err() == true {
// feedback_label.set_text("Unable to Open Browser");
}
})
.padding(5.0);

Flex::column()
.with_child(status_label)
.with_child(feedback_label)
.with_spacer(10.0)
.with_child(open_button)
.with_child(check_button)
.with_child(quit_button)
}

// pub fn build_ui(ui: &UI) {
//
// let mut window = Window::new(&ui, "Streamline Server Control", 200, 200, WindowType::NoMenubar);
//
// // Create a vertical layout to hold the controls
// let mut vbox = VerticalBox::new(&ui);
// vbox.set_padded(&ui, true);
//
// let mut update_button = Button::new(&ui, "Check For Updates");
// update_button.on_clicked(&ui, check_updates);
//
// let mut open_button = Button::new(&ui, "Open Browser");
//
// let mut quit_button = Button::new(&ui, "Quit");
// quit_button.on_clicked(&ui, {
// let ui = ui.clone();
// move |_| {
// ui.quit();
// }
// });
//
// // Create a new label. Note that labels don't auto-wrap!
// let mut label_text = String::from("Server is not Running");
// let label = Label::new(&ui, &label_text);
//
// vbox.append(&ui, label, LayoutStrategy::Stretchy);
// vbox.append(&ui, open_button.clone(), LayoutStrategy::Stretchy);
// vbox.append(&ui, update_button, LayoutStrategy::Stretchy);
// vbox.append(&ui, quit_button, LayoutStrategy::Stretchy);
//
// // Actually put the button in the window
// window.set_child(&ui, vbox);
// // Show the window
// window.show(&ui);
//
// open_button.on_clicked(&ui, {
// let ui = ui.clone();
// move |_| {
// if webbrowser::open("http://localhost").is_err() == true {
// window.modal_err(&ui, "Error opening browser", "")
// }
// }
// });
// }

fn check_updates(){
let up_to_date = fetch_is_new();
match up_to_date {
Expand Down

0 comments on commit 40777d0

Please sign in to comment.