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

Clipboard access #132

Merged
merged 5 commits into from
Dec 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Iced
[![Build Status](https://travis-ci.org/hecrj/iced.svg?branch=master)](https://travis-ci.org/hecrj/iced)
[![Test Status](https://github.com/hecrj/iced/workflows/Test/badge.svg)](https://github.com/hecrj/iced/actions)
[![Documentation](https://docs.rs/iced/badge.svg)][documentation]
[![Crates.io](https://img.shields.io/crates/v/iced.svg)](https://crates.io/crates/iced)
[![License](https://img.shields.io/crates/l/iced.svg)](https://github.com/hecrj/iced/blob/master/LICENSE)
Expand Down
8 changes: 8 additions & 0 deletions native/src/clipboard.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// A buffer for short-term storage and transfer within and between
/// applications.
pub trait Clipboard {
/// Returns the current content of the [`Clipboard`] as text.
///
/// [`Clipboard`]: trait.Clipboard.html
fn content(&self) -> Option<String>;
}
7 changes: 6 additions & 1 deletion native/src/element.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{
layout, renderer, Color, Event, Hasher, Layout, Length, Point, Widget,
layout, renderer, Clipboard, Color, Event, Hasher, Layout, Length, Point,
Widget,
};

/// A generic [`Widget`].
Expand Down Expand Up @@ -293,6 +294,7 @@ where
cursor_position: Point,
messages: &mut Vec<B>,
renderer: &Renderer,
clipboard: Option<&dyn Clipboard>,
) {
let mut original_messages = Vec::new();

Expand All @@ -302,6 +304,7 @@ where
cursor_position,
&mut original_messages,
renderer,
clipboard,
);

original_messages
Expand Down Expand Up @@ -366,13 +369,15 @@ where
cursor_position: Point,
messages: &mut Vec<Message>,
renderer: &Renderer,
clipboard: Option<&dyn Clipboard>,
) {
self.element.widget.on_event(
event,
layout,
cursor_position,
messages,
renderer,
clipboard,
)
}

Expand Down
2 changes: 2 additions & 0 deletions native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub mod renderer;
pub mod subscription;
pub mod widget;

mod clipboard;
mod element;
mod event;
mod hasher;
Expand All @@ -57,6 +58,7 @@ pub use iced_core::{
Point, Rectangle, Vector, VerticalAlignment,
};

pub use clipboard::Clipboard;
pub use element::Element;
pub use event::Event;
pub use hasher::Hasher;
Expand Down
10 changes: 7 additions & 3 deletions native/src/user_interface.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{input::mouse, layout, Element, Event, Layout, Point, Size};
use crate::{
input::mouse, layout, Clipboard, Element, Event, Layout, Point, Size,
};

use std::hash::Hasher;

Expand Down Expand Up @@ -185,7 +187,7 @@ where
/// );
///
/// // Update the user interface
/// let messages = user_interface.update(&renderer, events.drain(..));
/// let messages = user_interface.update(&renderer, None, events.drain(..));
///
/// cache = user_interface.into_cache();
///
Expand All @@ -198,6 +200,7 @@ where
pub fn update(
&mut self,
renderer: &Renderer,
clipboard: Option<&dyn Clipboard>,
events: impl Iterator<Item = Event>,
) -> Vec<Message> {
let mut messages = Vec::new();
Expand All @@ -213,6 +216,7 @@ where
self.cursor_position,
&mut messages,
renderer,
clipboard,
);
}

Expand Down Expand Up @@ -282,7 +286,7 @@ where
/// &mut renderer,
/// );
///
/// let messages = user_interface.update(&renderer, events.drain(..));
/// let messages = user_interface.update(&renderer, None, events.drain(..));
///
/// // Draw the user interface
/// let mouse_cursor = user_interface.draw(&mut renderer);
Expand Down
5 changes: 3 additions & 2 deletions native/src/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ pub mod button;
pub mod checkbox;
pub mod column;
pub mod container;
pub mod svg;
pub mod image;
pub mod radio;
pub mod row;
pub mod scrollable;
pub mod slider;
pub mod svg;
pub mod text;
pub mod text_input;

Expand Down Expand Up @@ -58,7 +58,7 @@ pub use text::Text;
#[doc(no_inline)]
pub use text_input::TextInput;

use crate::{layout, Event, Hasher, Layout, Length, Point};
use crate::{layout, Clipboard, Event, Hasher, Layout, Length, Point};

/// A component that displays information and allows interaction.
///
Expand Down Expand Up @@ -142,6 +142,7 @@ where
_cursor_position: Point,
_messages: &mut Vec<Message>,
_renderer: &Renderer,
_clipboard: Option<&dyn Clipboard>,
) {
}
}
5 changes: 3 additions & 2 deletions native/src/widget/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//! [`State`]: struct.State.html
use crate::{
input::{mouse, ButtonState},
layout, Background, Element, Event, Hasher, Layout, Length, Point,
Rectangle, Widget,
layout, Background, Clipboard, Element, Event, Hasher, Layout, Length,
Point, Rectangle, Widget,
};
use std::hash::Hash;

Expand Down Expand Up @@ -192,6 +192,7 @@ where
cursor_position: Point,
messages: &mut Vec<Message>,
_renderer: &Renderer,
_clipboard: Option<&dyn Clipboard>,
) {
match event {
Event::Mouse(mouse::Event::Input {
Expand Down
3 changes: 2 additions & 1 deletion native/src/widget/checkbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::hash::Hash;

use crate::{
input::{mouse, ButtonState},
layout, row, text, Align, Color, Element, Event, Font, Hasher,
layout, row, text, Align, Clipboard, Color, Element, Event, Font, Hasher,
HorizontalAlignment, Layout, Length, Point, Rectangle, Row, Text,
VerticalAlignment, Widget,
};
Expand Down Expand Up @@ -114,6 +114,7 @@ where
cursor_position: Point,
messages: &mut Vec<Message>,
_renderer: &Renderer,
_clipboard: Option<&dyn Clipboard>,
) {
match event {
Event::Mouse(mouse::Event::Input {
Expand Down
5 changes: 4 additions & 1 deletion native/src/widget/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
use std::hash::Hash;

use crate::{
layout, Align, Element, Event, Hasher, Layout, Length, Point, Widget,
layout, Align, Clipboard, Element, Event, Hasher, Layout, Length, Point,
Widget,
};

use std::u32;
Expand Down Expand Up @@ -153,6 +154,7 @@ where
cursor_position: Point,
messages: &mut Vec<Message>,
renderer: &Renderer,
clipboard: Option<&dyn Clipboard>,
) {
self.children.iter_mut().zip(layout.children()).for_each(
|(child, layout)| {
Expand All @@ -162,6 +164,7 @@ where
cursor_position,
messages,
renderer,
clipboard,
)
},
);
Expand Down
5 changes: 4 additions & 1 deletion native/src/widget/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
use std::hash::Hash;

use crate::{
layout, Align, Element, Event, Hasher, Layout, Length, Point, Widget,
layout, Align, Clipboard, Element, Event, Hasher, Layout, Length, Point,
Widget,
};

use std::u32;
Expand Down Expand Up @@ -131,13 +132,15 @@ where
cursor_position: Point,
messages: &mut Vec<Message>,
renderer: &Renderer,
clipboard: Option<&dyn Clipboard>,
) {
self.content.widget.on_event(
event,
layout.children().next().unwrap(),
cursor_position,
messages,
renderer,
clipboard,
)
}

Expand Down
3 changes: 2 additions & 1 deletion native/src/widget/radio.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Create choices using radio buttons.
use crate::{
input::{mouse, ButtonState},
layout, row, text, Align, Color, Element, Event, Font, Hasher,
layout, row, text, Align, Clipboard, Color, Element, Event, Font, Hasher,
HorizontalAlignment, Layout, Length, Point, Rectangle, Row, Text,
VerticalAlignment, Widget,
};
Expand Down Expand Up @@ -113,6 +113,7 @@ where
cursor_position: Point,
messages: &mut Vec<Message>,
_renderer: &Renderer,
_clipboard: Option<&dyn Clipboard>,
) {
match event {
Event::Mouse(mouse::Event::Input {
Expand Down
5 changes: 4 additions & 1 deletion native/src/widget/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
use std::hash::Hash;

use crate::{
layout, Align, Element, Event, Hasher, Layout, Length, Point, Widget,
layout, Align, Clipboard, Element, Event, Hasher, Layout, Length, Point,
Widget,
};

use std::u32;
Expand Down Expand Up @@ -154,6 +155,7 @@ where
cursor_position: Point,
messages: &mut Vec<Message>,
renderer: &Renderer,
clipboard: Option<&dyn Clipboard>,
) {
self.children.iter_mut().zip(layout.children()).for_each(
|(child, layout)| {
Expand All @@ -163,6 +165,7 @@ where
cursor_position,
messages,
renderer,
clipboard,
)
},
);
Expand Down
6 changes: 4 additions & 2 deletions native/src/widget/scrollable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use crate::{
column,
input::{mouse, ButtonState},
layout, Align, Column, Element, Event, Hasher, Layout, Length, Point,
Rectangle, Size, Widget,
layout, Align, Clipboard, Column, Element, Event, Hasher, Layout, Length,
Point, Rectangle, Size, Widget,
};

use std::{f32, hash::Hash, u32};
Expand Down Expand Up @@ -143,6 +143,7 @@ where
cursor_position: Point,
messages: &mut Vec<Message>,
renderer: &Renderer,
clipboard: Option<&dyn Clipboard>,
) {
let bounds = layout.bounds();
let is_mouse_over = bounds.contains(cursor_position);
Expand Down Expand Up @@ -247,6 +248,7 @@ where
cursor_position,
messages,
renderer,
clipboard,
)
}

Expand Down
5 changes: 3 additions & 2 deletions native/src/widget/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//! [`State`]: struct.State.html
use crate::{
input::{mouse, ButtonState},
layout, Element, Event, Hasher, Layout, Length, Point, Rectangle, Size,
Widget,
layout, Clipboard, Element, Event, Hasher, Layout, Length, Point,
Rectangle, Size, Widget,
};

use std::{hash::Hash, ops::RangeInclusive};
Expand Down Expand Up @@ -133,6 +133,7 @@ where
cursor_position: Point,
messages: &mut Vec<Message>,
_renderer: &Renderer,
_clipboard: Option<&dyn Clipboard>,
) {
let mut change = || {
let bounds = layout.bounds();
Expand Down
Loading