Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pane grid widget #224

Merged
merged 56 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
012b4ad
Draft `Panes` widget and `panes` example
hecrj Mar 4, 2020
b6926d9
Improve `Debug` implementation of `cache::State`
hecrj Mar 4, 2020
d7f32d4
Compute `panes` regions and focus on click
hecrj Mar 4, 2020
58adfcd
Fix `Split::apply` on vertical splits
hecrj Mar 4, 2020
cc310f7
Add split hotkeys to `panes` example
hecrj Mar 4, 2020
85ee2fc
Merge branch 'master' into feature/panes-widget
hecrj Mar 5, 2020
a6531c8
Implement `Subscription::with`
hecrj Mar 5, 2020
15fad17
Implement `panes::State::close`
hecrj Mar 5, 2020
6151c52
Rename `Panes` widget to `PaneGrid`
hecrj Mar 10, 2020
e4fbca5
Merge branch 'master' into feature/panes-widget
hecrj Mar 10, 2020
4e0e50a
Fix `Debug` implementation of `layer::cache::State`
hecrj Mar 10, 2020
ed7c327
Implement `Default` for `keyboard::ModifiersState`
hecrj Mar 10, 2020
eb070b9
Draft drag and drop support for `PaneGrid`
hecrj Mar 10, 2020
f11397c
Clip `scrollable` primitives only when necessary
hecrj Mar 10, 2020
df6e3f8
Expose `pane_grid::Focus` for state-based styling
hecrj Mar 11, 2020
f09b4bd
Round region dimensions of panes to avoid overlaps
hecrj Mar 11, 2020
2d8d420
Replace `Panes` with `PaneGrid` in documentation
hecrj Mar 11, 2020
c2ced4c
Improve `PaneGrid` API by introducing `DragEvent`
hecrj Mar 13, 2020
29bf51d
Implement `spacing` support for `PaneGrid`
hecrj Mar 13, 2020
0b12d70
Unfocus pane in `PaneGrid` on out-of-bounds click
hecrj Mar 13, 2020
b9f184f
Draft `PaneGrid::focus_adjacent`
hecrj Mar 13, 2020
26b9541
Improve `PaneGrid::focus_adjacent` intuitiveness
hecrj Mar 13, 2020
858c086
Remove `pane_grid` example for now
hecrj Mar 14, 2020
6e8585e
Expose `adjacent_pane` instead of `focus_adjacent`
hecrj Mar 14, 2020
2459648
Simplify `iter` and `iter_mut` in `pane_grid`
hecrj Mar 14, 2020
4605650
Reuse `PaneGrid::focus` to remove some duplication
hecrj Mar 14, 2020
5c8ec45
Create module boundaries for `pane_grid` logic
hecrj Mar 14, 2020
00c2b55
Replace `FocusedPane` with `Action` in `pane_grid`
hecrj Mar 14, 2020
a79603e
Rename `Split` to `Axis`
hecrj Mar 14, 2020
b55746b
Remove `PaneGrid::split_*` helpers
hecrj Mar 14, 2020
db441a6
Reintroduce `pane_grid::Split` as an identifier
hecrj Mar 14, 2020
f08cb4a
Implement mouse-based pane resizing for `PaneGrid`
hecrj Mar 14, 2020
eb5e225
Trigger `PaneGrid` resize on click
hecrj Mar 14, 2020
ec334bd
Improve pane selection when resizing a `PaneGrid`
hecrj Mar 14, 2020
a373682
Fix ratio calculation on resize in `PaneGrid`
hecrj Mar 14, 2020
c7583f1
Merge branch 'master' into feature/panes-widget
hecrj Mar 17, 2020
21a4095
Fix spacing calculation in `Axis::split`
hecrj Mar 17, 2020
56ba621
Add simple `pane_grid` example
hecrj Mar 17, 2020
a280dcd
Add `PaneGrid::on_key_press` for hotkey logic
hecrj Mar 17, 2020
6f9cf6c
Implement hotkey logic in `pane_grid` example
hecrj Mar 17, 2020
1cd1582
Add `modifiers` to `KeyPressEvent` in `pane_grid`
hecrj Mar 17, 2020
05beb87
Move common keyboard types to `iced_core`
hecrj Mar 17, 2020
20b142e
Make cursor unavailable when dragging panes
hecrj Mar 18, 2020
b8a035d
Add some styling to `pane_grid` buttons
hecrj Mar 18, 2020
36abf74
Improve styling of `pane_grid` example
hecrj Mar 18, 2020
eba2ded
Update `README` of examples
hecrj Mar 18, 2020
50b02d4
Check only for partial match of modifier keys
hecrj Mar 18, 2020
a820b8c
Rename `PaneGrid::modifiers` to `pressed_modifiers`
hecrj Mar 19, 2020
bd74c4e
Write documentation for `pane_grid`
hecrj Mar 19, 2020
bb898fa
Create `PaneGrid` alias in `iced_wgpu`
hecrj Mar 19, 2020
4202757
Fix minor documentation issues in `pane_grid`
hecrj Mar 19, 2020
18f016c
Use `f32::hypot` in `Point::distance`
hecrj Mar 20, 2020
31aaf20
Remove redundant check in `ModifiersState::matches`
hecrj Mar 20, 2020
33f33ed
Check cursor is in-bounds before resizing panes
hecrj Mar 20, 2020
cfc2b55
Rename `Internal::idle_pane` to `active_pane`
hecrj Mar 20, 2020
fb744a3
Fix links in `pane_grid` documentation
hecrj Mar 20, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ members = [
"examples/geometry",
"examples/integration",
"examples/pokedex",
"examples/pane_grid",
"examples/progress_bar",
"examples/solar_system",
"examples/stopwatch",
Expand Down
6 changes: 6 additions & 0 deletions core/src/keyboard.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! Reuse basic keyboard types.
mod key_code;
mod modifiers_state;

pub use key_code::KeyCode;
pub use modifiers_state::ModifiersState;
File renamed without changes.
30 changes: 30 additions & 0 deletions core/src/keyboard/modifiers_state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/// The current state of the keyboard modifiers.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct ModifiersState {
/// Whether a shift key is pressed
pub shift: bool,

/// Whether a control key is pressed
pub control: bool,

/// Whether an alt key is pressed
pub alt: bool,

/// Whether a logo key is pressed (e.g. windows key, command key...)
pub logo: bool,
}

impl ModifiersState {
/// Returns true if the current [`ModifiersState`] has at least the same
/// modifiers enabled as the given value, and false otherwise.
///
/// [`ModifiersState`]: struct.ModifiersState.html
pub fn matches(&self, modifiers: ModifiersState) -> bool {
let shift = !modifiers.shift || self.shift;
let control = !modifiers.control || self.control;
let alt = !modifiers.alt || self.alt;
let logo = !modifiers.logo || self.logo;

shift && control && alt && logo
}
}
1 change: 1 addition & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#![deny(unused_results)]
#![forbid(unsafe_code)]
#![forbid(rust_2018_idioms)]
pub mod keyboard;

mod align;
mod background;
Expand Down
10 changes: 10 additions & 0 deletions core/src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ impl Point {
pub const fn new(x: f32, y: f32) -> Self {
Self { x, y }
}

/// Computes the distance to another [`Point`].
///
/// [`Point`]: struct.Point.html
pub fn distance(&self, to: Point) -> f32 {
let a = self.x - to.x;
let b = self.y - to.y;

a.hypot(b)
}
}

impl From<[f32; 2]> for Point {
Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ A bunch of simpler examples exist:
- [`events`](events), a log of native events displayed using a conditional `Subscription`.
- [`geometry`](geometry), a custom widget showcasing how to draw geometry with the `Mesh2D` primitive in [`iced_wgpu`](../wgpu).
- [`integration`](integration), a demonstration of how to integrate Iced in an existing graphical application.
- [`pane_grid`](pane_grid), a grid of panes that can be split, resized, and reorganized.
- [`pokedex`](pokedex), an application that displays a random Pokédex entry (sprite included!) by using the [PokéAPI].
- [`progress_bar`](progress_bar), a simple progress bar that can be filled by using a slider.
- [`solar_system`](solar_system), an animated solar system drawn using the `Canvas` widget and showcasing how to compose different transforms.
Expand Down
9 changes: 9 additions & 0 deletions examples/pane_grid/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "pane_grid"
version = "0.1.0"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2018"
publish = false

[dependencies]
iced = { path = "../.." }
28 changes: 28 additions & 0 deletions examples/pane_grid/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Pane grid

A grid of panes that can be split, resized, and reorganized.

This example showcases the `PaneGrid` widget, which features:

* Vertical and horizontal splits
* Tracking of the last active pane
* Mouse-based resizing
* Drag and drop to reorganize panes
* Hotkey support
* Configurable modifier keys
* API to perform actions programmatically (`split`, `swap`, `resize`, etc.)

The __[`main`]__ file contains all the code of the example.

<div align="center">
<a href="https://gfycat.com/mixedflatjellyfish">
<img src="https://thumbs.gfycat.com/MixedFlatJellyfish-small.gif">
</a>
</div>

You can run it with `cargo run`:
```
cargo run --package pane_grid
```

[`main`]: src/main.rs
Loading