|
| 1 | +/* |
| 2 | + * Copyright (c) 2017 Boucher, Antoni <bouanto@zoho.com> |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 5 | + * this software and associated documentation files (the "Software"), to deal in |
| 6 | + * the Software without restriction, including without limitation the rights to |
| 7 | + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
| 8 | + * the Software, and to permit persons to whom the Software is furnished to do so, |
| 9 | + * subject to the following conditions: |
| 10 | + * |
| 11 | + * The above copyright notice and this permission notice shall be included in all |
| 12 | + * copies or substantial portions of the Software. |
| 13 | + * |
| 14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
| 16 | + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
| 17 | + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
| 18 | + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 19 | + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 | + */ |
| 21 | + |
| 22 | +#![feature(proc_macro)] |
| 23 | + |
| 24 | +extern crate gtk; |
| 25 | +#[macro_use] |
| 26 | +extern crate relm; |
| 27 | +extern crate relm_attributes; |
| 28 | +#[macro_use] |
| 29 | +extern crate relm_derive; |
| 30 | + |
| 31 | +use gtk::{ |
| 32 | + ButtonExt, |
| 33 | + GridExt, |
| 34 | + Inhibit, |
| 35 | + LabelExt, |
| 36 | + WidgetExt, |
| 37 | +}; |
| 38 | +use relm::Widget; |
| 39 | +use relm_attributes::widget; |
| 40 | + |
| 41 | +use self::Msg::*; |
| 42 | + |
| 43 | +#[derive(Msg)] |
| 44 | +pub enum Msg { |
| 45 | + Quit, |
| 46 | +} |
| 47 | + |
| 48 | +#[widget] |
| 49 | +impl Widget for Win { |
| 50 | + fn model() -> () { |
| 51 | + } |
| 52 | + |
| 53 | + fn update(&mut self, event: Msg) { |
| 54 | + match event { |
| 55 | + Quit => gtk::main_quit(), |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + view! { |
| 60 | + gtk::Window { |
| 61 | + gtk::Grid { |
| 62 | + gtk::Button { |
| 63 | + label: "7", |
| 64 | + cell: { |
| 65 | + left_attach: 0, |
| 66 | + top_attach: 0, |
| 67 | + }, |
| 68 | + }, |
| 69 | + gtk::Button { |
| 70 | + label: "8", |
| 71 | + cell: { |
| 72 | + left_attach: 1, |
| 73 | + top_attach: 0, |
| 74 | + }, |
| 75 | + }, |
| 76 | + gtk::Button { |
| 77 | + label: "9", |
| 78 | + cell: { |
| 79 | + left_attach: 2, |
| 80 | + top_attach: 0, |
| 81 | + }, |
| 82 | + }, |
| 83 | + gtk::Button { |
| 84 | + label: "4", |
| 85 | + cell: { |
| 86 | + left_attach: 0, |
| 87 | + top_attach: 1, |
| 88 | + }, |
| 89 | + }, |
| 90 | + gtk::Button { |
| 91 | + label: "5", |
| 92 | + cell: { |
| 93 | + left_attach: 1, |
| 94 | + top_attach: 1, |
| 95 | + }, |
| 96 | + }, |
| 97 | + gtk::Button { |
| 98 | + label: "6", |
| 99 | + cell: { |
| 100 | + left_attach: 2, |
| 101 | + top_attach: 1, |
| 102 | + }, |
| 103 | + }, |
| 104 | + gtk::Button { |
| 105 | + label: "1", |
| 106 | + cell: { |
| 107 | + left_attach: 0, |
| 108 | + top_attach: 2, |
| 109 | + }, |
| 110 | + }, |
| 111 | + gtk::Button { |
| 112 | + label: "2", |
| 113 | + cell: { |
| 114 | + left_attach: 1, |
| 115 | + top_attach: 2, |
| 116 | + }, |
| 117 | + }, |
| 118 | + gtk::Button { |
| 119 | + label: "3", |
| 120 | + cell: { |
| 121 | + left_attach: 2, |
| 122 | + top_attach: 2, |
| 123 | + }, |
| 124 | + }, |
| 125 | + gtk::Button { |
| 126 | + label: "+/-", |
| 127 | + cell: { |
| 128 | + left_attach: 0, |
| 129 | + top_attach: 3, |
| 130 | + }, |
| 131 | + }, |
| 132 | + gtk::Button { |
| 133 | + label: "0", |
| 134 | + cell: { |
| 135 | + left_attach: 1, |
| 136 | + top_attach: 3, |
| 137 | + }, |
| 138 | + }, |
| 139 | + gtk::Button { |
| 140 | + label: ".", |
| 141 | + cell: { |
| 142 | + left_attach: 2, |
| 143 | + top_attach: 3, |
| 144 | + }, |
| 145 | + } |
| 146 | + }, |
| 147 | + delete_event(_, _) => (Quit, Inhibit(false)) |
| 148 | + } |
| 149 | + } |
| 150 | +} |
| 151 | + |
| 152 | +fn main() { |
| 153 | + Win::run(()).unwrap(); |
| 154 | +} |
0 commit comments