From d294009f26187ee92017aded52e9d021684dcc57 Mon Sep 17 00:00:00 2001 From: Shalom Date: Fri, 30 Sep 2022 14:12:11 +0900 Subject: [PATCH 1/2] Add example: custom title bar --- examples/Cargo.toml | 4 +++ examples/header_bar/README.md | 11 ++++++++ examples/header_bar/main.rs | 41 +++++++++++++++++++++++++++++ examples/header_bar/screenshot.png | Bin 0 -> 5210 bytes examples/header_bar/title_bar.rs | 27 +++++++++++++++++++ 5 files changed, 83 insertions(+) create mode 100644 examples/header_bar/README.md create mode 100644 examples/header_bar/main.rs create mode 100644 examples/header_bar/screenshot.png create mode 100644 examples/header_bar/title_bar.rs diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 5364ec77f571..9740aa44b204 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -130,6 +130,10 @@ path = "list_box_model/main.rs" name = "list_store" path = "list_store/main.rs" +[[bin]] +name = "header_bar" +path = "header_bar/main.rs" + [[bin]] name = "menu_bar" path = "menu_bar/main.rs" diff --git a/examples/header_bar/README.md b/examples/header_bar/README.md new file mode 100644 index 000000000000..c1d13225d35e --- /dev/null +++ b/examples/header_bar/README.md @@ -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) \ No newline at end of file diff --git a/examples/header_bar/main.rs b/examples/header_bar/main.rs new file mode 100644 index 000000000000..884dc242cc43 --- /dev/null +++ b/examples/header_bar/main.rs @@ -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(); +} diff --git a/examples/header_bar/screenshot.png b/examples/header_bar/screenshot.png new file mode 100644 index 0000000000000000000000000000000000000000..5b7a5700317ba7f282914fbf1353c204d122acbc GIT binary patch literal 5210 zcmV-g6s7BlP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D6YohxK~#8N?cED> z6jhoB@PErq?@ikOGOf}(izED7W#=!_Bwd3Lh*)}vEhxz*`z(g~^l|LT0F z>)u=U_AA|A->T|#LRMB*Cxp&U?IJ9ZY)eE$G!P^tBp7QwGq+8Y2{D|cXl};@N<>6% z6iJ>lw@b*(%nZ48ID<*yZbw8!)ZfCLb@sGfqH)=cnPpYXHfsY9k^dIvItUWjeLl>w}W0Dj9}b7Y-&{A|i^laCg<(srvO)7ucN}PO_9`r|rTC zA|j$#Q{^93*s1EBwlirn(VjZVaz{sp7INKew{J&8L^RNtGfR0X!{hM;)~!_K1fS0r zlnJeg(M*`_?d|x*tn0C0!2)D>y+}?T)NL>#BBFsx=DN1FR@BwjqNu0{>tFj%WisuS zNUcd!l|WNcQtBj^XlZVS-`^gzEfEpXKqix;$CHG?Lxvz_=rEB?YcTDq ze@0VNQ^-UbNTN;&w4%HWogIE0Z#-tS5)l!(+t6XBAR*C%+`RmdiL_f1H80!R+VJ5A z+i}XUp=fDo*6N6eh~mZI!9#Ggu@Ms{UX0}AWUVfcJdI1wX{VjG%$`8y2}D1?{yI#X zHWkfH$F(}@UFKs=?qL0dN<{7;4_%&m>S_4q@HhB;-@a}MR9+@{z23mPx%tK}Pb8AZ zLC-w>G_6d%!~S7KVlo}rtjSY*L0QT~zjFNYb*YD zX9fHsnNshNkFSij))usg*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jvIJP zl*oZ9KPF^kWCVUs)cj3R`Fo-@)d#h8A|j%A=gZ8}eos`A$<$1!Jh6y~h$u=yNtC;C ziHL}t+4Cf4qC`YQQ40JNn)Q-1QX(RvF4o*=z2r=kh=?dk30|)^aCWYFDbLO|*G<-S z$zCQRA{waddtj|)b6uXDYn_E^m-Zwond?2(nN)Q|L_{Yud*YPrNm2?`7ucN}ZU=d3 zhRIr|3L+w+zNX4Y)-c)Y>}}RdDQMm2^NERM_Zg>TuG?pt_Oi*To`{I(WMNH$R`&WH z6R23%lBg`GlBeXfZerpjBBFuHo;amYNz-JmE0d@cDtR(-5)qNx*b}N#0+r0N@|dV( z@2o1@>xqbn1`4NKrYc(nwV5+ft8izYoRJa{(LiTUlBQ6}(-ioRMOLbgPTTbqL_|dW zMU|KAVW+Bh+%7XSQ=3jkGuz}$l!%B1I#q%+IklPffg~#RloXjXiHOMULM2tn+TQJ_ z&_Z=K+k4uMh=^#Q2sgK>+Jk1IcAR+<5mCGgl~_amii??bLk&PgMC3N% 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 + } +} From 2b218927dbaf5b7edfc33228f820ecf3c58cb9a1 Mon Sep 17 00:00:00 2001 From: shalom <45457350+ski0090@users.noreply.github.com> Date: Tue, 5 Dec 2023 18:46:01 +0900 Subject: [PATCH 2/2] Update examples/header_bar/README.md Co-authored-by: Guillaume Gomez --- examples/header_bar/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/header_bar/README.md b/examples/header_bar/README.md index c1d13225d35e..0195a86b1254 100644 --- a/examples/header_bar/README.md +++ b/examples/header_bar/README.md @@ -1,6 +1,6 @@ # HeaderBar example -This example demonstrates how to use HeaderBar in Windows. +This example demonstrates how to use HeaderBar in windows. Run it by executing: