Merge branch 'master' into fear/linear-gradients
This commit is contained in:
commit
921c94162e
26 changed files with 802 additions and 65 deletions
10
examples/cached/Cargo.toml
Normal file
10
examples/cached/Cargo.toml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "cached"
|
||||
version = "0.1.0"
|
||||
authors = ["Nick Senger <dev@nsenger.com>"]
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
iced = { path = "../..", features = ["debug"] }
|
||||
iced_lazy = { path = "../../lazy" }
|
||||
139
examples/cached/src/main.rs
Normal file
139
examples/cached/src/main.rs
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
use iced::theme;
|
||||
use iced::widget::{
|
||||
button, column, horizontal_space, row, scrollable, text, text_input,
|
||||
};
|
||||
use iced::{Element, Length, Sandbox, Settings};
|
||||
use iced_lazy::lazy;
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
App::run(Settings::default())
|
||||
}
|
||||
|
||||
struct App {
|
||||
options: HashSet<String>,
|
||||
input: String,
|
||||
order: Order,
|
||||
}
|
||||
|
||||
impl Default for App {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
options: ["Foo", "Bar", "Baz", "Qux", "Corge", "Waldo", "Fred"]
|
||||
.into_iter()
|
||||
.map(ToString::to_string)
|
||||
.collect(),
|
||||
input: Default::default(),
|
||||
order: Order::Ascending,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
enum Message {
|
||||
InputChanged(String),
|
||||
ToggleOrder,
|
||||
DeleteOption(String),
|
||||
AddOption(String),
|
||||
}
|
||||
|
||||
impl Sandbox for App {
|
||||
type Message = Message;
|
||||
|
||||
fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
String::from("Cached - Iced")
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Message) {
|
||||
match message {
|
||||
Message::InputChanged(input) => {
|
||||
self.input = input;
|
||||
}
|
||||
Message::ToggleOrder => {
|
||||
self.order = match self.order {
|
||||
Order::Ascending => Order::Descending,
|
||||
Order::Descending => Order::Ascending,
|
||||
}
|
||||
}
|
||||
Message::AddOption(option) => {
|
||||
self.options.insert(option);
|
||||
self.input.clear();
|
||||
}
|
||||
Message::DeleteOption(option) => {
|
||||
self.options.remove(&option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Message> {
|
||||
let options = lazy((&self.order, self.options.len()), || {
|
||||
let mut options: Vec<_> = self.options.iter().collect();
|
||||
|
||||
options.sort_by(|a, b| match self.order {
|
||||
Order::Ascending => a.to_lowercase().cmp(&b.to_lowercase()),
|
||||
Order::Descending => b.to_lowercase().cmp(&a.to_lowercase()),
|
||||
});
|
||||
|
||||
column(
|
||||
options
|
||||
.into_iter()
|
||||
.map(|option| {
|
||||
row![
|
||||
text(option),
|
||||
horizontal_space(Length::Fill),
|
||||
button("Delete")
|
||||
.on_press(Message::DeleteOption(
|
||||
option.to_string(),
|
||||
),)
|
||||
.style(theme::Button::Destructive)
|
||||
]
|
||||
.into()
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
.spacing(10)
|
||||
});
|
||||
|
||||
column![
|
||||
scrollable(options).height(Length::Fill),
|
||||
row![
|
||||
text_input(
|
||||
"Add a new option",
|
||||
&self.input,
|
||||
Message::InputChanged,
|
||||
)
|
||||
.on_submit(Message::AddOption(self.input.clone())),
|
||||
button(text(format!("Toggle Order ({})", self.order)))
|
||||
.on_press(Message::ToggleOrder)
|
||||
]
|
||||
.spacing(10)
|
||||
]
|
||||
.spacing(20)
|
||||
.padding(20)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash)]
|
||||
enum Order {
|
||||
Ascending,
|
||||
Descending,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Order {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
match self {
|
||||
Self::Ascending => "Ascending",
|
||||
Self::Descending => "Descending",
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -119,6 +119,7 @@ pub fn main() {
|
|||
width: physical_size.width,
|
||||
height: physical_size.height,
|
||||
present_mode: wgpu::PresentMode::AutoVsync,
|
||||
alpha_mode: wgpu::CompositeAlphaMode::Auto,
|
||||
},
|
||||
);
|
||||
|
||||
|
|
@ -213,6 +214,7 @@ pub fn main() {
|
|||
width: size.width,
|
||||
height: size.height,
|
||||
present_mode: wgpu::PresentMode::AutoVsync,
|
||||
alpha_mode: wgpu::CompositeAlphaMode::Auto
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
|||
10
examples/lazy/Cargo.toml
Normal file
10
examples/lazy/Cargo.toml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "lazy"
|
||||
version = "0.1.0"
|
||||
authors = ["Nick Senger <dev@nsenger.com>"]
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
iced = { path = "../..", features = ["debug"] }
|
||||
iced_lazy = { path = "../../lazy" }
|
||||
139
examples/lazy/src/main.rs
Normal file
139
examples/lazy/src/main.rs
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
use iced::theme;
|
||||
use iced::widget::{
|
||||
button, column, horizontal_space, row, scrollable, text, text_input,
|
||||
};
|
||||
use iced::{Element, Length, Sandbox, Settings};
|
||||
use iced_lazy::lazy;
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
App::run(Settings::default())
|
||||
}
|
||||
|
||||
struct App {
|
||||
options: HashSet<String>,
|
||||
input: String,
|
||||
order: Order,
|
||||
}
|
||||
|
||||
impl Default for App {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
options: ["Foo", "Bar", "Baz", "Qux", "Corge", "Waldo", "Fred"]
|
||||
.into_iter()
|
||||
.map(ToString::to_string)
|
||||
.collect(),
|
||||
input: Default::default(),
|
||||
order: Order::Ascending,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
enum Message {
|
||||
InputChanged(String),
|
||||
ToggleOrder,
|
||||
DeleteOption(String),
|
||||
AddOption(String),
|
||||
}
|
||||
|
||||
impl Sandbox for App {
|
||||
type Message = Message;
|
||||
|
||||
fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
String::from("Cached - Iced")
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Message) {
|
||||
match message {
|
||||
Message::InputChanged(input) => {
|
||||
self.input = input;
|
||||
}
|
||||
Message::ToggleOrder => {
|
||||
self.order = match self.order {
|
||||
Order::Ascending => Order::Descending,
|
||||
Order::Descending => Order::Ascending,
|
||||
}
|
||||
}
|
||||
Message::AddOption(option) => {
|
||||
self.options.insert(option);
|
||||
self.input.clear();
|
||||
}
|
||||
Message::DeleteOption(option) => {
|
||||
self.options.remove(&option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Message> {
|
||||
let options = lazy((&self.order, self.options.len()), || {
|
||||
let mut options: Vec<_> = self.options.iter().collect();
|
||||
|
||||
options.sort_by(|a, b| match self.order {
|
||||
Order::Ascending => a.to_lowercase().cmp(&b.to_lowercase()),
|
||||
Order::Descending => b.to_lowercase().cmp(&a.to_lowercase()),
|
||||
});
|
||||
|
||||
column(
|
||||
options
|
||||
.into_iter()
|
||||
.map(|option| {
|
||||
row![
|
||||
text(option),
|
||||
horizontal_space(Length::Fill),
|
||||
button("Delete")
|
||||
.on_press(Message::DeleteOption(
|
||||
option.to_string(),
|
||||
),)
|
||||
.style(theme::Button::Destructive)
|
||||
]
|
||||
.into()
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
.spacing(10)
|
||||
});
|
||||
|
||||
column![
|
||||
scrollable(options).height(Length::Fill),
|
||||
row![
|
||||
text_input(
|
||||
"Add a new option",
|
||||
&self.input,
|
||||
Message::InputChanged,
|
||||
)
|
||||
.on_submit(Message::AddOption(self.input.clone())),
|
||||
button(text(format!("Toggle Order ({})", self.order)))
|
||||
.on_press(Message::ToggleOrder)
|
||||
]
|
||||
.spacing(10)
|
||||
]
|
||||
.spacing(20)
|
||||
.padding(20)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash)]
|
||||
enum Order {
|
||||
Ascending,
|
||||
Descending,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Order {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
match self {
|
||||
Self::Ascending => "Ascending",
|
||||
Self::Descending => "Descending",
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ publish = false
|
|||
iced = { path = "../..", features = ["async-std", "debug"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
lazy_static = "1.4"
|
||||
once_cell = "1.15"
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
async-std = "1.0"
|
||||
|
|
|
|||
|
|
@ -11,12 +11,10 @@ use iced::window;
|
|||
use iced::{Application, Element};
|
||||
use iced::{Color, Command, Font, Length, Settings, Subscription};
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use once_cell::sync::Lazy;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
lazy_static! {
|
||||
static ref INPUT_ID: text_input::Id = text_input::Id::unique();
|
||||
}
|
||||
static INPUT_ID: Lazy<text_input::Id> = Lazy::new(text_input::Id::unique);
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
Todos::run(Settings {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ publish = false
|
|||
iced = { path = "../..", features = ["tokio", "debug"] }
|
||||
iced_native = { path = "../../native" }
|
||||
iced_futures = { path = "../../futures" }
|
||||
lazy_static = "1.4"
|
||||
once_cell = "1.15"
|
||||
|
||||
[dependencies.async-tungstenite]
|
||||
version = "0.16"
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use iced::widget::{
|
|||
use iced::{
|
||||
Application, Color, Command, Element, Length, Settings, Subscription, Theme,
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
WebSocket::run(Settings::default())
|
||||
|
|
@ -165,6 +166,4 @@ impl Default for State {
|
|||
}
|
||||
}
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref MESSAGE_LOG: scrollable::Id = scrollable::Id::unique();
|
||||
}
|
||||
static MESSAGE_LOG: Lazy<scrollable::Id> = Lazy::new(scrollable::Id::unique);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue