Skip to content
Snippets Groups Projects
window.blp 3.04 KiB
// SPDX-FileCopyrightText: 2022-2023 Bruce Cowan <bruce@bcowan.me.uk>
//
// SPDX-License-Identifier: GPL-3.0-or-later

using Gtk 4.0;
using Adw 1;

template $RugbyAppWindow : Adw.ApplicationWindow {
  title: "Rugby";

  Adw.ToolbarView {

    [top]
    Adw.HeaderBar {
      SpinButton scorespin {
        adjustment: Adjustment {
          step-increment: 1;
          upper: 200;
        };
        focusable: true;
        tooltip-text: "Score";
      }

      ToggleButton filter_toggle {
        action-name: "win.show-try-filter";
        icon-name: "funnel";
        tooltip-text: "Show Try Filter";
      }

      [end]
      MenuButton {
        direction: none;
        primary: true;
        menu-model: app_menu;
        tooltip-text: "Main Menu";
      }
    }

    content: Box {
      orientation: vertical;

      Revealer {
        halign: center;
        margin-top: 6;
        reveal-child: bind filter_toggle.active;
        transition-type: slide_down;

        SpinButton tryspin {
          adjustment: Adjustment {
            step-increment: 1;
            lower: 0;
            upper: 40;
          };
          focusable: true;
          tooltip-text: "Tries";

          value-changed => $try_spin_value_changed_cb();
        }
      }

      Stack stack {
        StackPage {
          name: "empty_page";

          child: Adw.StatusPage {
            icon-name: "list";
            title: "No possibilities";
          };
        }
        StackPage {
          name: "list_page";

          child: ScrolledWindow {
            vexpand: true;

            Adw.Clamp {
              maximum-size: 600;
              tightening-threshold: 400;

              ListView listview {
                styles ["rich-list", "card"]

                factory: BuilderListItemFactory {
                  template ListItem {
                    child: $RugbyPossibilityWidget {
                      possibility: bind template.item;
                      tooltip-text: bind $item_tooltip_cb(template.item) as <string>;
                    };
                  }
                };
                model: NoSelection {
                  model: FilterListModel {
                    filter: CustomFilter try_filter {};
                    model: $RugbyListStore list_store {
                      score: bind scorespin.value;
                    };

                    items-changed => $list_store_items_changed_cb();
                  };
                };
              }
            }
          };
        }
      }
    };
  }

  ShortcutController {
    scope: local;

    Shortcut {
      action: "action(win.score-changed)";
      arguments: "'up'";
      trigger: "<Ctrl>Up|<Ctrl>Right";
    }
    Shortcut {
      action: "action(win.score-changed)";
      arguments: "'down'";
      trigger: "<Ctrl>Down|<Ctrl>Left";
    }
    Shortcut {
      action: "action(win.show-try-filter)";
      trigger: "<Ctrl>F";
    }
  }
}

menu app_menu {
  section {
    item ("_Preferences", "app.prefs")
    item ("_Keyboard Shortcuts", "win.show-help-overlay")
    item ("_About Rugby", "app.about")
  }
}