Skip to content

Commit

Permalink
Merge pull request #224 from hecrj/feature/panes-widget
Browse files Browse the repository at this point in the history
Pane grid widget
  • Loading branch information
hecrj authored Mar 20, 2020
2 parents 93f5640 + fb744a3 commit f7ec679
Show file tree
Hide file tree
Showing 36 changed files with 1,915 additions and 35 deletions.
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

0 comments on commit f7ec679

Please sign in to comment.