Draft first-class TitleBar
in pane_grid
This commit is contained in:
parent
4c494c7244
commit
a11bcf5af0
@ -97,7 +97,7 @@ impl Sandbox for Example {
|
|||||||
|
|
||||||
let pane_grid =
|
let pane_grid =
|
||||||
PaneGrid::new(&mut self.panes, |pane, content, focus| {
|
PaneGrid::new(&mut self.panes, |pane, content, focus| {
|
||||||
content.view(pane, focus, total_panes)
|
pane_grid::Content::new(content.view(pane, focus, total_panes))
|
||||||
})
|
})
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.height(Length::Fill)
|
.height(Length::Fill)
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
use crate::Renderer;
|
use crate::Renderer;
|
||||||
|
|
||||||
pub use iced_native::pane_grid::{
|
pub use iced_native::pane_grid::{
|
||||||
Axis, Content, Direction, DragEvent, Focus, KeyPressEvent, Node, Pane,
|
Axis, Configuration, Content, Direction, DragEvent, Focus, KeyPressEvent,
|
||||||
ResizeEvent, Split, State,
|
Node, Pane, ResizeEvent, Split, State,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A collection of panes distributed using either vertical or horizontal splits
|
/// A collection of panes distributed using either vertical or horizontal splits
|
||||||
|
@ -14,8 +14,8 @@ use iced_native::pane_grid;
|
|||||||
use iced_native::{Element, Layout, Point, Rectangle, Vector};
|
use iced_native::{Element, Layout, Point, Rectangle, Vector};
|
||||||
|
|
||||||
pub use iced_native::pane_grid::{
|
pub use iced_native::pane_grid::{
|
||||||
Axis, Direction, DragEvent, Focus, KeyPressEvent, Pane, ResizeEvent, Split,
|
Axis, Configuration, Content, Direction, DragEvent, Focus, KeyPressEvent,
|
||||||
State,
|
Pane, ResizeEvent, Split, State, TitleBar,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A collection of panes distributed using either vertical or horizontal splits
|
/// A collection of panes distributed using either vertical or horizontal splits
|
||||||
@ -34,7 +34,7 @@ where
|
|||||||
fn draw<Message>(
|
fn draw<Message>(
|
||||||
&mut self,
|
&mut self,
|
||||||
defaults: &Self::Defaults,
|
defaults: &Self::Defaults,
|
||||||
content: &[(Pane, Element<'_, Message, Self>)],
|
content: &[(Pane, Content<'_, Message, Self>)],
|
||||||
dragging: Option<Pane>,
|
dragging: Option<Pane>,
|
||||||
resizing: Option<Axis>,
|
resizing: Option<Axis>,
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
@ -115,4 +115,15 @@ where
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw_pane<Message>(
|
||||||
|
&mut self,
|
||||||
|
defaults: &Self::Defaults,
|
||||||
|
_title_bar: Option<&TitleBar<'_, Message, Self>>,
|
||||||
|
body: &Element<'_, Message, Self>,
|
||||||
|
layout: Layout<'_>,
|
||||||
|
cursor_position: Point,
|
||||||
|
) -> Self::Output {
|
||||||
|
body.draw(self, defaults, layout, cursor_position)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,8 @@
|
|||||||
//! [`Widget`]: widget/trait.Widget.html
|
//! [`Widget`]: widget/trait.Widget.html
|
||||||
//! [`UserInterface`]: struct.UserInterface.html
|
//! [`UserInterface`]: struct.UserInterface.html
|
||||||
//! [renderer]: renderer/index.html
|
//! [renderer]: renderer/index.html
|
||||||
#![deny(missing_docs)]
|
//#![deny(missing_docs)]
|
||||||
#![deny(missing_debug_implementations)]
|
//#![deny(missing_debug_implementations)]
|
||||||
#![deny(unused_results)]
|
#![deny(unused_results)]
|
||||||
#![forbid(unsafe_code)]
|
#![forbid(unsafe_code)]
|
||||||
#![forbid(rust_2018_idioms)]
|
#![forbid(rust_2018_idioms)]
|
||||||
|
@ -9,20 +9,24 @@
|
|||||||
//! [`pane_grid` example]: https://github.com/hecrj/iced/tree/0.1/examples/pane_grid
|
//! [`pane_grid` example]: https://github.com/hecrj/iced/tree/0.1/examples/pane_grid
|
||||||
//! [`PaneGrid`]: struct.PaneGrid.html
|
//! [`PaneGrid`]: struct.PaneGrid.html
|
||||||
mod axis;
|
mod axis;
|
||||||
|
mod configuration;
|
||||||
mod content;
|
mod content;
|
||||||
mod direction;
|
mod direction;
|
||||||
mod node;
|
mod node;
|
||||||
mod pane;
|
mod pane;
|
||||||
mod split;
|
mod split;
|
||||||
mod state;
|
mod state;
|
||||||
|
mod title_bar;
|
||||||
|
|
||||||
pub use axis::Axis;
|
pub use axis::Axis;
|
||||||
|
pub use configuration::Configuration;
|
||||||
pub use content::Content;
|
pub use content::Content;
|
||||||
pub use direction::Direction;
|
pub use direction::Direction;
|
||||||
pub use node::Node;
|
pub use node::Node;
|
||||||
pub use pane::Pane;
|
pub use pane::Pane;
|
||||||
pub use split::Split;
|
pub use split::Split;
|
||||||
pub use state::{Focus, State};
|
pub use state::{Focus, State};
|
||||||
|
pub use title_bar::TitleBar;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
keyboard, layout, mouse, Clipboard, Element, Event, Hasher, Layout, Length,
|
keyboard, layout, mouse, Clipboard, Element, Event, Hasher, Layout, Length,
|
||||||
@ -70,10 +74,10 @@ use crate::{
|
|||||||
///
|
///
|
||||||
/// let pane_grid =
|
/// let pane_grid =
|
||||||
/// PaneGrid::new(&mut state, |pane, state, focus| {
|
/// PaneGrid::new(&mut state, |pane, state, focus| {
|
||||||
/// match state {
|
/// pane_grid::Content::new(match state {
|
||||||
/// PaneState::SomePane => Text::new("This is some pane"),
|
/// PaneState::SomePane => Text::new("This is some pane"),
|
||||||
/// PaneState::AnotherKindOfPane => Text::new("This is another kind of pane"),
|
/// PaneState::AnotherKindOfPane => Text::new("This is another kind of pane"),
|
||||||
/// }.into()
|
/// })
|
||||||
/// })
|
/// })
|
||||||
/// .on_drag(Message::PaneDragged)
|
/// .on_drag(Message::PaneDragged)
|
||||||
/// .on_resize(Message::PaneResized);
|
/// .on_resize(Message::PaneResized);
|
||||||
@ -85,7 +89,7 @@ use crate::{
|
|||||||
pub struct PaneGrid<'a, Message, Renderer> {
|
pub struct PaneGrid<'a, Message, Renderer> {
|
||||||
state: &'a mut state::Internal,
|
state: &'a mut state::Internal,
|
||||||
pressed_modifiers: &'a mut keyboard::ModifiersState,
|
pressed_modifiers: &'a mut keyboard::ModifiersState,
|
||||||
elements: Vec<(Pane, Element<'a, Message, Renderer>)>,
|
elements: Vec<(Pane, Content<'a, Message, Renderer>)>,
|
||||||
width: Length,
|
width: Length,
|
||||||
height: Length,
|
height: Length,
|
||||||
spacing: u16,
|
spacing: u16,
|
||||||
@ -110,7 +114,7 @@ impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> {
|
|||||||
Pane,
|
Pane,
|
||||||
&'a mut T,
|
&'a mut T,
|
||||||
Option<Focus>,
|
Option<Focus>,
|
||||||
) -> Element<'a, Message, Renderer>,
|
) -> Content<'a, Message, Renderer>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let elements = {
|
let elements = {
|
||||||
let action = state.internal.action();
|
let action = state.internal.action();
|
||||||
@ -416,12 +420,15 @@ where
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(((pane, _), _)) = clicked_region.next() {
|
if let Some(((pane, content), layout)) =
|
||||||
|
clicked_region.next()
|
||||||
|
{
|
||||||
match &self.on_drag {
|
match &self.on_drag {
|
||||||
Some(on_drag)
|
Some(on_drag)
|
||||||
if self
|
if content.is_over_drag_target(
|
||||||
.pressed_modifiers
|
layout,
|
||||||
.matches(self.modifier_keys) =>
|
cursor_position,
|
||||||
|
) =>
|
||||||
{
|
{
|
||||||
self.state.pick_pane(pane);
|
self.state.pick_pane(pane);
|
||||||
|
|
||||||
@ -576,7 +583,7 @@ where
|
|||||||
{
|
{
|
||||||
self.elements.iter_mut().zip(layout.children()).for_each(
|
self.elements.iter_mut().zip(layout.children()).for_each(
|
||||||
|((_, pane), layout)| {
|
|((_, pane), layout)| {
|
||||||
pane.widget.on_event(
|
pane.on_event(
|
||||||
event.clone(),
|
event.clone(),
|
||||||
layout,
|
layout,
|
||||||
cursor_position,
|
cursor_position,
|
||||||
@ -645,12 +652,31 @@ pub trait Renderer: crate::Renderer + Sized {
|
|||||||
fn draw<Message>(
|
fn draw<Message>(
|
||||||
&mut self,
|
&mut self,
|
||||||
defaults: &Self::Defaults,
|
defaults: &Self::Defaults,
|
||||||
content: &[(Pane, Element<'_, Message, Self>)],
|
content: &[(Pane, Content<'_, Message, Self>)],
|
||||||
dragging: Option<Pane>,
|
dragging: Option<Pane>,
|
||||||
resizing: Option<Axis>,
|
resizing: Option<Axis>,
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
cursor_position: Point,
|
cursor_position: Point,
|
||||||
) -> Self::Output;
|
) -> Self::Output;
|
||||||
|
|
||||||
|
/// Draws a [`Pane`].
|
||||||
|
///
|
||||||
|
/// It receives:
|
||||||
|
/// - the [`TitleBar`] of the [`Pane`], if any
|
||||||
|
/// - the [`Content`] of the [`Pane`]
|
||||||
|
/// - the [`Layout`] of the [`Pane`] and its elements
|
||||||
|
/// - the cursor position
|
||||||
|
///
|
||||||
|
/// [`Pane`]: struct.Pane.html
|
||||||
|
/// [`Layout`]: ../layout/struct.Layout.html
|
||||||
|
fn draw_pane<Message>(
|
||||||
|
&mut self,
|
||||||
|
defaults: &Self::Defaults,
|
||||||
|
title_bar: Option<&TitleBar<'_, Message, Self>>,
|
||||||
|
body: &Element<'_, Message, Self>,
|
||||||
|
layout: Layout<'_>,
|
||||||
|
cursor_position: Point,
|
||||||
|
) -> Self::Output;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Message, Renderer> From<PaneGrid<'a, Message, Renderer>>
|
impl<'a, Message, Renderer> From<PaneGrid<'a, Message, Renderer>>
|
||||||
|
30
native/src/widget/pane_grid/configuration.rs
Normal file
30
native/src/widget/pane_grid/configuration.rs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
use crate::pane_grid::Axis;
|
||||||
|
|
||||||
|
/// The arrangement of a [`PaneGrid`].
|
||||||
|
///
|
||||||
|
/// [`PaneGrid`]: struct.PaneGrid.html
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum Configuration<T> {
|
||||||
|
/// A split of the available space.
|
||||||
|
Split {
|
||||||
|
/// The direction of the split.
|
||||||
|
axis: Axis,
|
||||||
|
|
||||||
|
/// The ratio of the split in [0.0, 1.0].
|
||||||
|
ratio: f32,
|
||||||
|
|
||||||
|
/// The left/top [`Content`] of the split.
|
||||||
|
///
|
||||||
|
/// [`Configuration`]: enum.Node.html
|
||||||
|
a: Box<Configuration<T>>,
|
||||||
|
|
||||||
|
/// The right/bottom [`Content`] of the split.
|
||||||
|
///
|
||||||
|
/// [`Configuration`]: enum.Node.html
|
||||||
|
b: Box<Configuration<T>>,
|
||||||
|
},
|
||||||
|
/// A [`Pane`].
|
||||||
|
///
|
||||||
|
/// [`Pane`]: struct.Pane.html
|
||||||
|
Pane(T),
|
||||||
|
}
|
@ -1,30 +1,88 @@
|
|||||||
use crate::pane_grid::Axis;
|
use crate::layout;
|
||||||
|
use crate::pane_grid::{self, TitleBar};
|
||||||
|
use crate::{Clipboard, Element, Event, Hasher, Layout, Point};
|
||||||
|
|
||||||
/// The content of a [`PaneGrid`].
|
/// The content of a [`Pane`].
|
||||||
///
|
///
|
||||||
/// [`PaneGrid`]: struct.PaneGrid.html
|
/// [`Pane`]: struct.Pane.html
|
||||||
#[derive(Debug, Clone)]
|
pub struct Content<'a, Message, Renderer> {
|
||||||
pub enum Content<T> {
|
title_bar: Option<TitleBar<'a, Message, Renderer>>,
|
||||||
/// A split of the available space.
|
body: Element<'a, Message, Renderer>,
|
||||||
Split {
|
}
|
||||||
/// The direction of the split.
|
|
||||||
axis: Axis,
|
impl<'a, Message, Renderer> Content<'a, Message, Renderer> {
|
||||||
|
pub fn new(body: impl Into<Element<'a, Message, Renderer>>) -> Self {
|
||||||
/// The ratio of the split in [0.0, 1.0].
|
Self {
|
||||||
ratio: f32,
|
title_bar: None,
|
||||||
|
body: body.into(),
|
||||||
/// The left/top [`Content`] of the split.
|
}
|
||||||
///
|
}
|
||||||
/// [`Content`]: enum.Node.html
|
|
||||||
a: Box<Content<T>>,
|
pub fn title_bar(
|
||||||
|
mut self,
|
||||||
/// The right/bottom [`Content`] of the split.
|
title_bar: TitleBar<'a, Message, Renderer>,
|
||||||
///
|
) -> Self {
|
||||||
/// [`Content`]: enum.Node.html
|
self.title_bar = Some(title_bar);
|
||||||
b: Box<Content<T>>,
|
self
|
||||||
},
|
}
|
||||||
/// A [`Pane`].
|
}
|
||||||
///
|
|
||||||
/// [`Pane`]: struct.Pane.html
|
impl<'a, Message, Renderer> Content<'a, Message, Renderer>
|
||||||
Pane(T),
|
where
|
||||||
|
Renderer: pane_grid::Renderer,
|
||||||
|
{
|
||||||
|
pub fn draw(
|
||||||
|
&self,
|
||||||
|
renderer: &mut Renderer,
|
||||||
|
defaults: &Renderer::Defaults,
|
||||||
|
layout: Layout<'_>,
|
||||||
|
cursor_position: Point,
|
||||||
|
) -> Renderer::Output {
|
||||||
|
renderer.draw_pane(
|
||||||
|
defaults,
|
||||||
|
self.title_bar.as_ref(),
|
||||||
|
&self.body,
|
||||||
|
layout,
|
||||||
|
cursor_position,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn is_over_drag_target(
|
||||||
|
&self,
|
||||||
|
_layout: Layout<'_>,
|
||||||
|
_cursor_position: Point,
|
||||||
|
) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn layout(
|
||||||
|
&self,
|
||||||
|
renderer: &Renderer,
|
||||||
|
limits: &layout::Limits,
|
||||||
|
) -> layout::Node {
|
||||||
|
self.body.layout(renderer, limits)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn on_event(
|
||||||
|
&mut self,
|
||||||
|
event: Event,
|
||||||
|
layout: Layout<'_>,
|
||||||
|
cursor_position: Point,
|
||||||
|
messages: &mut Vec<Message>,
|
||||||
|
renderer: &Renderer,
|
||||||
|
clipboard: Option<&dyn Clipboard>,
|
||||||
|
) {
|
||||||
|
self.body.on_event(
|
||||||
|
event,
|
||||||
|
layout,
|
||||||
|
cursor_position,
|
||||||
|
messages,
|
||||||
|
renderer,
|
||||||
|
clipboard,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn hash_layout(&self, state: &mut Hasher) {
|
||||||
|
self.body.hash_layout(state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
keyboard,
|
keyboard,
|
||||||
pane_grid::{Axis, Content, Direction, Node, Pane, Split},
|
pane_grid::{Axis, Configuration, Direction, Node, Pane, Split},
|
||||||
Hasher, Point, Rectangle, Size,
|
Hasher, Point, Rectangle, Size,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -53,18 +53,21 @@ impl<T> State<T> {
|
|||||||
/// [`State`]: struct.State.html
|
/// [`State`]: struct.State.html
|
||||||
/// [`Pane`]: struct.Pane.html
|
/// [`Pane`]: struct.Pane.html
|
||||||
pub fn new(first_pane_state: T) -> (Self, Pane) {
|
pub fn new(first_pane_state: T) -> (Self, Pane) {
|
||||||
(Self::with_content(Content::Pane(first_pane_state)), Pane(0))
|
(
|
||||||
|
Self::with_configuration(Configuration::Pane(first_pane_state)),
|
||||||
|
Pane(0),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new [`State`] with the given [`Content`].
|
/// Creates a new [`State`] with the given [`Configuration`].
|
||||||
///
|
///
|
||||||
/// [`State`]: struct.State.html
|
/// [`State`]: struct.State.html
|
||||||
/// [`Content`]: enum.Content.html
|
/// [`Configuration`]: enum.Configuration.html
|
||||||
pub fn with_content(content: impl Into<Content<T>>) -> Self {
|
pub fn with_configuration(config: impl Into<Configuration<T>>) -> Self {
|
||||||
let mut panes = HashMap::new();
|
let mut panes = HashMap::new();
|
||||||
|
|
||||||
let (layout, last_id) =
|
let (layout, last_id) =
|
||||||
Self::distribute_content(&mut panes, content.into(), 0);
|
Self::distribute_content(&mut panes, config.into(), 0);
|
||||||
|
|
||||||
State {
|
State {
|
||||||
panes,
|
panes,
|
||||||
@ -274,11 +277,11 @@ impl<T> State<T> {
|
|||||||
|
|
||||||
fn distribute_content(
|
fn distribute_content(
|
||||||
panes: &mut HashMap<Pane, T>,
|
panes: &mut HashMap<Pane, T>,
|
||||||
content: Content<T>,
|
content: Configuration<T>,
|
||||||
next_id: usize,
|
next_id: usize,
|
||||||
) -> (Node, usize) {
|
) -> (Node, usize) {
|
||||||
match content {
|
match content {
|
||||||
Content::Split { axis, ratio, a, b } => {
|
Configuration::Split { axis, ratio, a, b } => {
|
||||||
let (a, next_id) = Self::distribute_content(panes, *a, next_id);
|
let (a, next_id) = Self::distribute_content(panes, *a, next_id);
|
||||||
let (b, next_id) = Self::distribute_content(panes, *b, next_id);
|
let (b, next_id) = Self::distribute_content(panes, *b, next_id);
|
||||||
|
|
||||||
@ -293,7 +296,7 @@ impl<T> State<T> {
|
|||||||
next_id + 1,
|
next_id + 1,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Content::Pane(state) => {
|
Configuration::Pane(state) => {
|
||||||
let id = Pane(next_id);
|
let id = Pane(next_id);
|
||||||
let _ = panes.insert(id, state);
|
let _ = panes.insert(id, state);
|
||||||
|
|
||||||
|
6
native/src/widget/pane_grid/title_bar.rs
Normal file
6
native/src/widget/pane_grid/title_bar.rs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
use crate::Element;
|
||||||
|
|
||||||
|
pub struct TitleBar<'a, Message, Renderer> {
|
||||||
|
title: String,
|
||||||
|
buttons: Option<Element<'a, Message, Renderer>>,
|
||||||
|
}
|
@ -11,8 +11,8 @@
|
|||||||
use crate::Renderer;
|
use crate::Renderer;
|
||||||
|
|
||||||
pub use iced_native::pane_grid::{
|
pub use iced_native::pane_grid::{
|
||||||
Axis, Content, Direction, DragEvent, Focus, KeyPressEvent, Node, Pane,
|
Axis, Configuration, Content, Direction, DragEvent, Focus, KeyPressEvent,
|
||||||
ResizeEvent, Split, State,
|
Node, Pane, ResizeEvent, Split, State,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A collection of panes distributed using either vertical or horizontal splits
|
/// A collection of panes distributed using either vertical or horizontal splits
|
||||||
|
Loading…
x
Reference in New Issue
Block a user