Skip to content

Commit

Permalink
Support horizontal/vertical fraction for auto_zoom_on_focus (#173)
Browse files Browse the repository at this point in the history
Co-authored-by: Rafał Chłodnicki <[email protected]>
  • Loading branch information
Jeangowhy and rchl authored Sep 19, 2023
1 parent d0cd911 commit 0e32b72
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
*.pyc
*.cache
*.sublime-project
*.sublime-workspace
*.hgignore
*.hgtags
*.DS_Store
pyrightconfig.json
package-metadata.json
3 changes: 2 additions & 1 deletion Origami.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

// Automatically zoom the active pane.
// Set it to `true` for the default zoom, or to a user-definable
// fraction of the screen, such as "0.75".
// fraction of the screen, such as "0.75", or "[0.5, 0.6]" for
// horizontal and vertical correspondingly.
"auto_zoom_on_focus": false,

// Automatically close a pane once you've closed the last file in it.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ In the keybindings you can change a `mode` which specifies which separation line
Automation
----------

You can have Origami automatically zoom the active pane by setting `auto_zoom_on_focus` in your Origami user preferences. Set it to `true` for the default zoom, or set it to a user-definable fraction of the screen, such as `0.75`.
You can have Origami automatically zoom the active pane by setting `auto_zoom_on_focus` in your Origami user preferences. Set it to `true` for the default zoom, or set it to a user-definable fraction of the screen, such as `0.75`, or `[0.5, 0.6]` for horizontal and vertical correspondingly.

Origami can also automatically close a pane for you once you've closed the last file in it. Just set `auto_close_empty_panes` to true in the Origami preferences.

Expand Down
18 changes: 13 additions & 5 deletions origami.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,18 @@ def _on_resize_panes(self, orientation, cells, relevant_index, orig_data, text):
self.window.set_layout(layout)

def zoom_pane(self, fraction):
if fraction is None:
fraction = .9
fraction_horizontal = fraction_vertical = .9

if isinstance(fraction, float) or isinstance(fraction, int):
fraction_horizontal = fraction_vertical = fraction
elif isinstance(fraction, list) and len(fraction) == 2:
if isinstance(fraction[0], float) or isinstance(fraction[0], int):
fraction_horizontal = fraction[0]
if isinstance(fraction[1], float) or isinstance(fraction[1], int):
fraction_vertical = fraction[1]

fraction = min(1, max(0, fraction))
fraction_horizontal = min(1, max(0, fraction_horizontal))
fraction_vertical = min(1, max(0, fraction_vertical))

window = self.window
rows, cols, cells = self.get_layout()
Expand All @@ -324,7 +332,7 @@ def zoom_pane(self, fraction):

# TODO: the sizes of the unzoomed panes are calculated incorrectly if the
# unzoomed panes have a split that overlaps the zoomed pane.
current_col_width = 1 if num_cols == 1 else fraction
current_col_width = 1 if num_cols == 1 else fraction_horizontal
other_col_width = 0 if num_cols == 1 else (1 - current_col_width) / (num_cols - 1)

cols = [0.0]
Expand All @@ -334,7 +342,7 @@ def zoom_pane(self, fraction):
current_row = current_cell[1]
num_rows = len(rows) - 1

current_row_height = 1 if num_rows == 1 else fraction
current_row_height = 1 if num_rows == 1 else fraction_vertical
other_row_height = 0 if num_rows == 1 else (1 - current_row_height) / (num_rows - 1)
rows = [0.0]
for i in range(num_rows):
Expand Down

0 comments on commit 0e32b72

Please sign in to comment.