Skip to content

Commit

Permalink
Fix sidebar resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfactotum committed Sep 21, 2023
1 parent 1f68763 commit 93c717a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
24 changes: 20 additions & 4 deletions src/book-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,8 @@ export const BookViewer = GObject.registerClass({
// sidebar
let breakpointApplied
this._breakpoint_bin.add_breakpoint(utils.connect(new Adw.Breakpoint({
condition: Adw.BreakpointCondition.parse('max-width: 720px'),
// min sidebar width (defaults to 180) + min page width (360) = 540
condition: Adw.BreakpointCondition.parse('max-width: 540px'),
}), {
'apply': () => {
breakpointApplied = true
Expand All @@ -666,10 +667,25 @@ export const BookViewer = GObject.registerClass({
setFoldSidebar()
this._resize_handle.cursor = Gdk.Cursor.new_from_name('col-resize', null)
this._resize_handle.add_controller(utils.connect(new Gtk.GestureDrag(), {
'drag-update': (_, x) => this._sidebar.width_request += x,
'drag-update': (_, x) => {
if (this._flap.collapsed) {
this._flap.max_sidebar_width += x
} else {
const sidebarWidth = this._sidebar.get_width() + x
const totalWidth = this.get_width()
this._flap.sidebar_width_fraction =
Math.max(0, Math.min(1, sidebarWidth / totalWidth))
}
},
}))
this._flap.connect('notify::show-sidebar', flap =>
(flap.show_sidebar ? this._library_button : this._view).grab_focus())
const onSidebarCollapsedChanged = flap =>
flap.max_sidebar_width = flap.collapsed ? 300 : 360
onSidebarCollapsedChanged(this._flap)
utils.connect(this._flap, {
'notify::collapsed': onSidebarCollapsedChanged,
'notify::show-sidebar': flap =>
(flap.show_sidebar ? this._library_button : this._view).grab_focus(),
})

// revealers
const autohideHeaderbar = autohide(this._headerbar_revealer,
Expand Down
2 changes: 1 addition & 1 deletion src/ui/book-viewer.ui
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@

<object class="AdwOverlaySplitView" id="flap">
<property name="enable-show-gesture">False</property>
<property name="sidebar-width-unit">px</property>
<child type="sidebar">
<object class="GtkOverlay" id="sidebar">
<property name="width-request">300</property>
<child type="overlay">
<object class="GtkBox" id="resize-handle">
<property name="width-request">4</property>
Expand Down

0 comments on commit 93c717a

Please sign in to comment.