feat: hamburger menu with popover
This commit is contained in:
@@ -3,7 +3,10 @@ mod font;
|
|||||||
use crate::font::Font; // this brings in the struct Font
|
use crate::font::Font; // this brings in the struct Font
|
||||||
use gtk::cairo::Context;
|
use gtk::cairo::Context;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::{Application, ApplicationWindow, DrawingArea};
|
use gtk::{
|
||||||
|
Application, ApplicationWindow, DrawingArea, HeaderBar, Label, ListBox, ListBoxRow, MenuButton,
|
||||||
|
Popover,
|
||||||
|
};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let app = Application::builder()
|
let app = Application::builder()
|
||||||
@@ -22,6 +25,42 @@ fn build_ui(app: >k::Application) {
|
|||||||
.default_height(800)
|
.default_height(800)
|
||||||
.build();
|
.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 drawing_area = DrawingArea::new();
|
||||||
|
|
||||||
let rows = 100 as u8;
|
let rows = 100 as u8;
|
||||||
|
|||||||
Reference in New Issue
Block a user