feat: hamburger menu with popover

This commit is contained in:
Nathan
2025-06-06 13:57:33 -06:00
parent f504f3c09a
commit 045a9d823d

View File

@@ -3,7 +3,10 @@ mod font;
use crate::font::Font; // this brings in the struct Font
use gtk::cairo::Context;
use gtk::prelude::*;
use gtk::{Application, ApplicationWindow, DrawingArea};
use gtk::{
Application, ApplicationWindow, DrawingArea, HeaderBar, Label, ListBox, ListBoxRow, MenuButton,
Popover,
};
fn main() {
let app = Application::builder()
@@ -22,6 +25,42 @@ fn build_ui(app: &gtk::Application) {
.default_height(800)
.build();
// HeaderBar
let header_bar = HeaderBar::new();
window.set_titlebar(Some(&header_bar));
// MenuButton
let menu_button = MenuButton::new();
menu_button.set_icon_name("open-menu-symbolic");
header_bar.pack_start(&menu_button);
// Popover
let popover = Popover::new();
popover.set_parent(&menu_button);
menu_button.set_popover(Some(&popover));
// ListBox in popover
let list_box = ListBox::new();
list_box.set_selection_mode(gtk::SelectionMode::None); // No selection on menu items
// Add menu items (ListBoxRows with Labels)
let item1_row = ListBoxRow::new();
let item1_label = Label::new(Some("Settings"));
item1_row.set_child(Some(&item1_label));
list_box.append(&item1_row);
let item2_row = ListBoxRow::new();
let item2_label = Label::new(Some("Help"));
item2_row.set_child(Some(&item2_label));
list_box.append(&item2_row);
let item3_row = ListBoxRow::new();
let item3_label = Label::new(Some("About"));
item3_row.set_child(Some(&item3_label));
list_box.append(&item3_row);
popover.set_child(Some(&list_box)); // Set the ListBox as the child of the Popover
let drawing_area = DrawingArea::new();
let rows = 100 as u8;