Created
September 30, 2018 14:20
-
-
Save loloof64/c048a4e2631036ed438a9283c38086ff to your computer and use it in GitHub Desktop.
Ridiculous simple calculator in GTK-RS
This file contains hidden or 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
[package] | |
name = "ridiculous_calculator" | |
version = "0.1.0" | |
authors = ["Laurent Bernabe <[email protected]>"] | |
license = "MIT" | |
[dependencies] | |
[dependencies.gtk] | |
version = "0.5.0" |
This file contains hidden or 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
extern crate gtk; | |
use gtk::prelude::*; | |
use gtk::{Window, WindowType}; | |
use gtk::{Box, Orientation}; | |
use gtk::{ComboBoxText}; | |
use gtk::{Button}; | |
fn main() { | |
if gtk::init().is_err() { | |
println!("Failed to intialize GTK !"); | |
return; | |
} | |
let left_operand_values = ComboBoxText::new(); | |
let right_operand_values = ComboBoxText::new(); | |
let operator_values = ComboBoxText::new(); | |
let operands_possibilities = [ | |
"2", "3", "4", "5", "6", "7", "8", "9" | |
]; | |
let operators_possibilities = [ | |
"+", "-", "*" | |
]; | |
for elem in operands_possibilities.iter() { | |
left_operand_values.append_text(elem); | |
right_operand_values.append_text(elem); | |
} | |
for elem in operators_possibilities.iter() { | |
operator_values.append_text(elem); | |
} | |
left_operand_values.set_active(0); | |
right_operand_values.set_active(0); | |
operator_values.set_active(0); | |
let validate_button = Button::new_with_label("Validate"); | |
let combo_boxes_box = Box::new(Orientation::Horizontal, 10); | |
combo_boxes_box.pack_start(&left_operand_values, true, false, 10); | |
combo_boxes_box.pack_start(&operator_values, true, false, 10); | |
combo_boxes_box.pack_start(&right_operand_values, true, false, 10); | |
let button_box = Box::new(Orientation::Horizontal, 10); | |
button_box.pack_start(&validate_button, true, false, 10); | |
let main_vertical_box = Box::new(Orientation::Vertical, 3); | |
main_vertical_box.pack_start(&combo_boxes_box, true, false, 3); | |
main_vertical_box.pack_start(&button_box, true, false, 3); | |
let window = Window::new(WindowType::Toplevel); | |
window.set_title("Simple ridiculous calculator"); | |
window.set_default_size(480, 220); | |
window.connect_delete_event(|_, _| { | |
gtk::main_quit(); | |
Inhibit(false) | |
}); | |
window.add(&main_vertical_box); | |
window.show_all(); | |
gtk::main(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First version : not interactive at all (revision 1)