main.rs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. mod constants;
  2. mod model;
  3. use gtk::glib;
  4. use gtk::prelude::*;
  5. fn main() -> glib::ExitCode {
  6. // Create a new application
  7. let app = gtk::Application::builder()
  8. .application_id(constants::APP_ID)
  9. .build();
  10. app.connect_activate(build_ui);
  11. // Run the application
  12. app.run()
  13. }
  14. pub struct App {
  15. pub window: gtk::Window,
  16. pub container: gtk::Paned,
  17. pub center: gtk::Button,
  18. pub toolbar: gtk::Button,
  19. pub header: Header,
  20. }
  21. impl App {
  22. fn new() -> App {
  23. let window = gtk::Window::new();
  24. let container = gtk::Paned::new(gtk::Orientation::Horizontal);
  25. let header = Header::new();
  26. let toolbar = gtk::Button::builder()
  27. .label("Press me!")
  28. .margin_top(12)
  29. .margin_bottom(12)
  30. .margin_start(12)
  31. .margin_end(12)
  32. .build();
  33. let center = gtk::Button::builder()
  34. .label("Press me!")
  35. .margin_top(12)
  36. .margin_bottom(12)
  37. .margin_start(12)
  38. .margin_end(12)
  39. .build();
  40. window.set_titlebar(Some(&header.container));
  41. window.set_title(Some(constants::NAME));
  42. container.set_start_child(Some(&toolbar));
  43. container.set_end_child(Some(&center));
  44. window.set_child(Some(&container));
  45. App {
  46. window,
  47. center,
  48. container,
  49. toolbar,
  50. header,
  51. }
  52. }
  53. }
  54. pub struct Header {
  55. pub container: gtk::HeaderBar,
  56. pub open_btn: gtk::Button,
  57. pub save_btn: gtk::Button,
  58. pub save_as_btn: gtk::Button,
  59. }
  60. impl Header {
  61. fn new() -> Header {
  62. let container = gtk::HeaderBar::new();
  63. let new_btn = gtk::Button::with_label(constants::NEW);
  64. let open_btn = gtk::Button::with_label(constants::OPEN);
  65. let save_btn = gtk::Button::with_label(constants::SAVE);
  66. let save_as_btn = gtk::Button::with_label(constants::SAVE_AS);
  67. open_btn.connect_clicked(Header::do_open);
  68. container.pack_start(&new_btn);
  69. container.pack_start(&open_btn);
  70. container.pack_end(&save_btn);
  71. container.pack_end(&save_as_btn);
  72. Header {
  73. container,
  74. open_btn,
  75. save_btn,
  76. save_as_btn,
  77. }
  78. }
  79. fn do_open(_: &gtk::Button) {
  80. let _open_dialog = gtk::FileChooserDialog::new(
  81. Some("Open"),
  82. Some(&gtk::Window::new()),
  83. gtk::FileChooserAction::Open,
  84. &[
  85. ("Cancel", gtk::ResponseType::Cancel),
  86. ("Open", gtk::ResponseType::Ok),
  87. ],
  88. );
  89. }
  90. }
  91. fn build_ui(app: &gtk::Application) {
  92. let thyme_app = App::new();
  93. thyme_app.window.set_application(Some(app));
  94. thyme_app.window.present();
  95. }