This repository has been archived by the owner on Mar 4, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #774 from ski0090/headerbar
Add example: custom title bar
- Loading branch information
Showing
5 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# HeaderBar example | ||
|
||
This example demonstrates how to use HeaderBar in windows. | ||
|
||
Run it by executing: | ||
|
||
```bash | ||
cargo run --bin header_bar | ||
``` | ||
|
||
![screenshot](screenshot.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
mod title_bar; | ||
|
||
use gtk::prelude::*; | ||
use gtk::{ApplicationWindow, CheckButton, Label, Stack, WindowPosition}; | ||
use title_bar::TitleBar; | ||
|
||
fn build_ui(application: >k::Application) { | ||
let window = ApplicationWindow::builder() | ||
.application(application) | ||
.title("HeaderBar example") | ||
.window_position(WindowPosition::Center) | ||
.build(); | ||
|
||
let stack = Stack::builder().expand(true).build(); | ||
window.add(&stack); | ||
|
||
let check_button = CheckButton::builder() | ||
.expand(true) | ||
.label("check button") | ||
.build(); | ||
stack.add_titled(&check_button, "check_button", "check button"); | ||
let label = Label::builder().label("Hello world").build(); | ||
stack.add_titled(&label, "label", "label"); | ||
|
||
let title_bar = TitleBar::new(); | ||
window.set_titlebar(Some(title_bar.header())); | ||
title_bar.set_stack(&stack); | ||
|
||
window.show_all(); | ||
} | ||
|
||
fn main() { | ||
let application = gtk::Application::new( | ||
Some("com.github.gtk-rs.examples.menu_bar"), | ||
Default::default(), | ||
); | ||
|
||
application.connect_activate(build_ui); | ||
|
||
application.run(); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use gtk::prelude::*; | ||
use gtk::{HeaderBar, Label, Stack, StackSwitcher}; | ||
|
||
pub struct TitleBar { | ||
header: HeaderBar, | ||
menu: StackSwitcher, | ||
} | ||
|
||
impl TitleBar { | ||
pub fn new() -> Self { | ||
let menu = StackSwitcher::new(); | ||
let header = HeaderBar::builder() | ||
.custom_title(&menu) | ||
.show_close_button(true) | ||
.build(); | ||
header.add(&Label::new(Some("Custom title"))); | ||
Self { header, menu } | ||
} | ||
|
||
pub fn set_stack(&self, stack: &Stack) { | ||
self.menu.set_stack(Some(stack)); | ||
} | ||
|
||
pub fn header(&self) -> &HeaderBar { | ||
&self.header | ||
} | ||
} |