Skip to content

Commit 4ca7aba

Browse files
committed
hide bottom bar on scroll
1 parent a70bcbe commit 4ca7aba

File tree

3 files changed

+62
-30
lines changed

3 files changed

+62
-30
lines changed

src/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ macro_rules! view {
6161
$obj.$member($($e),+);
6262
view!(@expand-build $obj $($tt)*);
6363
};
64-
(@expand-build $obj:ident bind $prop:literal $from_ty:ident $source:literal $($tt:tt)*) => {
65-
$from_ty.bind_property($obj, $source, $prop);
64+
(@expand-build $obj:ident bind $prop:literal $from_ty:ident $source:literal, $($tt:tt)*) => {
65+
$from_ty.bind_property($source, &$obj, $prop).build();
6666
}
6767
}

src/tab.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl Tab {
123123
.top_margin(MARGIN * 2)
124124
.left_margin(MARGIN)
125125
.right_margin(MARGIN)
126-
.bottom_margin(MARGIN)
126+
.bottom_margin(MARGIN * 4)
127127
.indent(2)
128128
.editable(false)
129129
.cursor_visible(false)

src/window.rs

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ pub mod imp {
2323
#[derive(Debug, Default, Properties)]
2424
pub struct Window {
2525
pub(crate) url_bar: gtk::SearchEntry,
26+
pub(crate) small_url_bar: gtk::SearchEntry,
2627
pub(crate) bottom_bar_revealer: gtk::Revealer,
27-
pub(crate) bottom_entry: gtk::SearchEntry,
2828
pub(crate) header_small: adw::HeaderBar,
2929
pub(crate) squeezer: adw::Squeezer,
3030
pub(crate) progress_bar: gtk::ProgressBar,
@@ -36,6 +36,7 @@ pub mod imp {
3636
pub(crate) url: RefCell<String>,
3737
#[prop(get = Self::progress_animated, set = Self::set_progress_animated)]
3838
pub(crate) progress: PhantomData<f64>,
39+
pub(crate) scroll_ctrl: gtk::EventControllerScroll,
3940
}
4041

4142
impl Window {
@@ -113,15 +114,21 @@ impl Window {
113114
let imp = this.imp();
114115
imp.config.replace(config);
115116

116-
imp.url_bar.set_width_request(360);
117-
imp.url_bar.set_hexpand(true);
118117
imp.progress_bar.add_css_class("osd");
119118
imp.progress_bar.set_valign(gtk::Align::Start);
120119

120+
let menu_model = Self::build_menu_common();
121121
view!(
122122
header_small = (imp.header_small.clone()) {
123-
set_title_widget: Some(&(w = adw::WindowTitle {
124-
set_title: "Geopard",
123+
set_show_end_title_buttons(false),
124+
set_title_widget: Some(&(se = (imp.small_url_bar.clone()) {
125+
set_hexpand: true,
126+
connect_activate: |url_bar| {
127+
url_bar
128+
.activate_action("win.open-omni", Some(&url_bar.text().to_variant()))
129+
.unwrap();
130+
},
131+
bind "text" this "url",
125132
})),
126133
}
127134
header_bar = adw::HeaderBar {
@@ -135,25 +142,23 @@ impl Window {
135142
}),
136143
pack_end: &(b = gtk::MenuButton {
137144
set_icon_name: "open-menu",
138-
set_menu_model: Some(&Self::build_menu_common()),
145+
set_menu_model: Some(&menu_model),
139146
}),
140147
set_title_widget: Some(&(c = adw::Clamp {
141148
set_child: Some(&(se = (imp.url_bar.clone()) {
142149
set_hexpand: true,
150+
set_width_request: 360,
143151
connect_activate: |url_bar| {
144152
url_bar
145153
.activate_action("win.open-omni", Some(&url_bar.text().to_variant()))
146154
.unwrap();
147155
},
156+
bind "text" this "url",
148157
})),
149158
set_maximum_size: 768,
150159
set_tightening_threshold: 720,
151160
})),
152161
}
153-
mobile_section = gio::Menu {
154-
append(Some("Back"), Some("win.back")),
155-
append(Some("New Tab"), Some("win.new-tab")),
156-
}
157162
bottom_bar = adw::HeaderBar {
158163
set_show_end_title_buttons: false,
159164
set_show_start_title_buttons: false,
@@ -165,6 +170,14 @@ impl Window {
165170
set_icon_name: "go-next-symbolic",
166171
set_action_name: Some("win.next"),
167172
}),
173+
set_title_widget: Some(&(b = gtk::Button {
174+
set_icon_name: "system-search-symbolic",
175+
set_action_name: Some("win.focus-url-bar"),
176+
})),
177+
pack_end: &(b = gtk::MenuButton {
178+
set_icon_name: "open-menu",
179+
set_menu_model: Some(&menu_model),
180+
}),
168181
pack_end: &(b = gtk::Button {
169182
set_icon_name: "tab-new-symbolic",
170183
set_action_name: Some("win.new-tab"),
@@ -177,6 +190,7 @@ impl Window {
177190
content = gtk::Box {
178191
set_orientation: gtk::Orientation::Vertical,
179192
append: &(squeezer = (imp.squeezer.clone()) {
193+
set_transition_type: adw::SqueezerTransitionType::Crossfade,
180194
add: &header_bar,
181195
add: &header_small,
182196
connect_visible_child_notify:
@@ -188,19 +202,20 @@ impl Window {
188202
append: &(overlay = gtk::Overlay {
189203
set_child: Some(&tab_view),
190204
add_overlay: &imp.progress_bar,
205+
add_overlay: &(b = (imp.bottom_bar_revealer.clone()) {
206+
set_transition_type: gtk::RevealerTransitionType::SlideUp,
207+
set_child: Some(&bottom_bar),
208+
set_valign: gtk::Align::End,
209+
}),
191210
}),
192-
append: &imp.bottom_bar_revealer,
193211
}
194212
);
195213

196-
imp.bottom_entry.set_hexpand(true);
197-
imp.bottom_bar_revealer.set_child(Some(&bottom_bar));
198-
199214
this.set_default_size(800, 600);
200215
this.set_content(Some(&content));
201216
this.squeezer_changed();
202217

203-
this.setup_actions();
218+
this.setup_actions_signals();
204219
this.open_in_new_tab(bookmarks_url().as_str());
205220
this
206221
}
@@ -223,7 +238,9 @@ impl Window {
223238
);
224239
menu_model
225240
}
226-
fn setup_actions(&self) {
241+
fn setup_actions_signals(&self) {
242+
let imp = self.imp();
243+
227244
self_action!(self, "back", back);
228245
self_action!(self, "new-tab", add_tab_focused);
229246
self_action!(self, "show-bookmarks", add_tab_focused);
@@ -258,6 +275,18 @@ impl Window {
258275
clone!(@weak self as this => move |_,v| this.set_clipboard(v.unwrap().get::<String>().unwrap().as_str())),
259276
);
260277
self.add_action(&act_set_clipboard);
278+
279+
self.add_controller(&imp.scroll_ctrl);
280+
imp.scroll_ctrl
281+
.set_propagation_phase(gtk::PropagationPhase::Capture);
282+
imp.scroll_ctrl
283+
.set_flags(gtk::EventControllerScrollFlags::VERTICAL);
284+
imp.scroll_ctrl.connect_scroll(
285+
clone!(@weak self as this => @default-panic, move |_, _, y| {
286+
this.imp().bottom_bar_revealer.set_reveal_child(y < 0.0 && this.is_small_screen());
287+
return gtk::Inhibit(false);
288+
}),
289+
);
261290
}
262291
fn add_tab(&self) -> adw::TabPage {
263292
let imp = self.imp();
@@ -273,10 +302,7 @@ impl Window {
273302
let tab = self.inner_tab(&page);
274303
btp.drain(0..).for_each(|binding| binding.unbind());
275304
btp.extend([
276-
tab.bind_property("url", &imp.url_bar, "text")
277-
.flags(glib::BindingFlags::SYNC_CREATE)
278-
.build(),
279-
tab.bind_property("url", &imp.bottom_entry, "text")
305+
tab.bind_property("url", self, "url")
280306
.flags(glib::BindingFlags::SYNC_CREATE)
281307
.build(),
282308
tab.bind_property("progress", self, "progress")
@@ -298,7 +324,11 @@ impl Window {
298324
}
299325
fn focus_url_bar(&self) {
300326
let imp = self.imp();
301-
imp.url_bar.grab_focus();
327+
if self.is_small_screen() {
328+
imp.small_url_bar.grab_focus();
329+
} else {
330+
imp.url_bar.grab_focus();
331+
}
302332
}
303333

304334
async fn append_bookmark(url: &str) -> anyhow::Result<()> {
@@ -419,17 +449,19 @@ impl Window {
419449
// );
420450
//}
421451

422-
fn squeezer_changed(&self) {
452+
fn is_small_screen(&self) -> bool {
423453
let imp = self.imp();
424-
let title_visible = imp
425-
.squeezer
454+
imp.squeezer
426455
.visible_child()
427456
.map(|child| child.downcast().ok())
428457
.flatten()
429458
.map(|w: adw::HeaderBar| w == self.imp().header_small)
430-
.unwrap_or(false);
431-
432-
imp.bottom_bar_revealer.set_reveal_child(title_visible);
459+
.unwrap_or(false)
460+
}
461+
fn squeezer_changed(&self) {
462+
let imp = self.imp();
463+
imp.bottom_bar_revealer
464+
.set_reveal_child(self.is_small_screen());
433465
}
434466
fn present_shortcuts(&self) {
435467
let builder = gtk::Builder::from_string(

0 commit comments

Comments
 (0)