This repository has been archived by the owner on Apr 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Externalized UI: Implement Oni split mode (#1682)
* Add split bindings * Get tests green again * Get split tests green * Add layout logic plus testc ases * Fix lint issues * Get oni-splits working end-to-end * Tweak positioning of splits * Add basic window layout algorithm * Fix lint issue * Fix test issues * Fix window click behavior * Fix compilation issue * Fix split direction issue * Fix lint issue * Hook up <C-w>s/<C-w>v bindings for oni.tabs.mode * Fall back to native splits if editor.split.mode isn't set to oni * Remove todo * Fix class name for editor
- Loading branch information
Showing
11 changed files
with
554 additions
and
109 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
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
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,69 @@ | ||
/** | ||
* layoutFromSplitInfo.ts | ||
* | ||
* Function to layout splits into a particular window | ||
*/ | ||
|
||
import * as Oni from "oni-api" | ||
|
||
import { IAugmentedSplitInfo, ISplitInfo, SplitOrLeaf } from "./WindowManagerStore" | ||
|
||
export interface LayoutResultInfo { | ||
rectangle: Oni.Shapes.Rectangle | ||
split: IAugmentedSplitInfo | ||
} | ||
|
||
export interface LayoutResult { | ||
[windowId: string]: LayoutResultInfo | ||
} | ||
|
||
export const layoutFromSplitInfo = ( | ||
splits: ISplitInfo<IAugmentedSplitInfo>, | ||
width: number, | ||
height: number, | ||
): LayoutResult => { | ||
return layoutFromSplitInfoHelper(splits, Oni.Shapes.Rectangle.create(0, 0, width, height)) | ||
} | ||
|
||
const layoutFromSplitInfoHelper = ( | ||
split: SplitOrLeaf<IAugmentedSplitInfo>, | ||
rectangle: Oni.Shapes.Rectangle, | ||
): LayoutResult => { | ||
// Base case.. | ||
if (split.type === "Leaf") { | ||
return { | ||
[split.contents.id]: { | ||
rectangle, | ||
split: split.contents, | ||
}, | ||
} | ||
} | ||
|
||
if (split.splits.length === 0) { | ||
return {} | ||
} | ||
|
||
// Recursive case | ||
// | ||
// TODO: Handle specified sizes for the windows. We're just distributing the space evenly, currently. | ||
const splitWidth = | ||
split.direction === "horizontal" ? rectangle.width / split.splits.length : rectangle.width | ||
const splitHeight = | ||
split.direction === "vertical" ? rectangle.height / split.splits.length : rectangle.height | ||
|
||
let ret = {} | ||
|
||
for (let i = 0; i < split.splits.length; i++) { | ||
const x = split.direction === "horizontal" ? rectangle.x + splitWidth * i : rectangle.x | ||
const y = split.direction === "vertical" ? rectangle.y + splitHeight * i : rectangle.y | ||
|
||
const rect = Oni.Shapes.Rectangle.create(x, y, splitWidth, splitHeight) | ||
|
||
ret = { | ||
...ret, | ||
...layoutFromSplitInfoHelper(split.splits[i], rect), | ||
} | ||
} | ||
|
||
return ret | ||
} |
Oops, something went wrong.