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

bring iced to master #257

Merged
merged 1 commit into from
Mar 13, 2024
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
1,899 changes: 892 additions & 1,007 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data = { version = "0.1.0", path = "data" }
notify-rust = "4"
chrono = { version = "0.4", features = ['serde'] }
fern = "0.6.1"
iced = { version = "0.12.0", features = ["tokio", "lazy", "advanced", "image"] }
iced = { version = "0.13.0-dev", features = ["tokio", "lazy", "advanced", "image"] }
log = "0.4.16"
once_cell = "1.18"
palette = "0.7.4"
Expand All @@ -37,5 +37,5 @@ embed-resource = "2.1.1"
members = ["data", "irc", "irc/proto"]

[patch.crates-io]
iced = { git = "https://github.com/tarkah/iced", rev = "f9db8d1efe68634b7b06ce07f12ea33a3e37d79c" }
iced_core = { git = "https://github.com/tarkah/iced", rev = "f9db8d1efe68634b7b06ce07f12ea33a3e37d79c" }
iced = { git = "https://github.com/iced-rs/iced", rev = "3d915d3cb30e5d08829aa2928676a53c505a601e" }
iced_core = { git = "https://github.com/iced-rs/iced", rev = "3d915d3cb30e5d08829aa2928676a53c505a601e" }
2 changes: 1 addition & 1 deletion data/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ chrono = { version = "0.4", features = ['serde'] }
dirs-next = "2.0.0"
flate2 = "1.0"
futures = "0.3.21"
iced_core = "0.12.0"
iced_core = "0.13.0-dev"
log = "0.4.16"
palette = "0.7.4"
rand = "0.8.4"
Expand Down
2 changes: 1 addition & 1 deletion data/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ impl Map {
}
}

pub fn nickname(&self, server: &Server) -> Option<NickRef> {
pub fn nickname<'a>(&'a self, server: &Server) -> Option<NickRef<'a>> {
self.client(server).map(Client::nickname)
}

Expand Down
5 changes: 2 additions & 3 deletions data/src/time.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::time::SystemTime;

use chrono::{DateTime, NaiveDateTime, TimeZone, Utc};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
Expand Down Expand Up @@ -28,7 +28,6 @@ impl Posix {
let seconds = (self.0 / 1_000_000_000) as i64;
let nanos = (self.0 % 1_000_000_000) as u32;

NaiveDateTime::from_timestamp_opt(seconds, nanos)
.map(|datetime| Utc.from_utc_datetime(&datetime))
DateTime::from_timestamp(seconds, nanos)
}
}
92 changes: 51 additions & 41 deletions src/buffer/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use iced::{Command, Length};

use super::{input_view, scroll_view, user_context};
use crate::theme;
use crate::widget::{selectable_text, Collection, Element};
use crate::widget::{selectable_text, Element};

mod topic;

Expand Down Expand Up @@ -42,64 +42,71 @@ pub fn view<'a>(
history,
config,
move |message| {
let timestamp = config
.buffer
.format_timestamp(&message.server_time)
.map(|timestamp| selectable_text(timestamp).style(theme::Text::Transparent));
let timestamp =
config
.buffer
.format_timestamp(&message.server_time)
.map(|timestamp| {
selectable_text(timestamp).style(theme::selectable_text::transparent)
});

match message.target.source() {
message::Source::User(user) => {
let nick = user_context::view(
selectable_text(config.buffer.nickname.brackets.format(user)).style(
theme::Text::Nickname(
user.color_seed(&config.buffer.nickname.color),
false,
),
|theme| {
theme::selectable_text::nickname(
theme,
user.color_seed(&config.buffer.nickname.color),
false,
)
},
),
user.clone(),
)
.map(scroll_view::Message::UserContext);
let row_style = match our_nick {
Some(nick)
if message::reference_user(
user.nickname(),
nick,
&message.text,
) =>
{
theme::Container::Highlight
}
_ => theme::Container::Default,
};

let space = selectable_text(" ");
let message = selectable_text(&message.text);
let text = selectable_text(&message.text);

Some(
container(
row![]
.push_maybe(timestamp)
.push(nick)
.push(space)
.push(message),
.push(text),
)
.style(row_style)
.style(move |theme, status| match our_nick {
Some(nick)
if message::reference_user(
user.nickname(),
nick,
&message.text,
) =>
{
theme::container::highlight(theme, status)
}
_ => Default::default(),
})
.into(),
)
}
message::Source::Server(_) => {
let message = selectable_text(&message.text).style(theme::Text::Server);
let message =
selectable_text(&message.text).style(theme::selectable_text::info);

Some(container(row![].push_maybe(timestamp).push(message)).into())
}
message::Source::Action => {
let message = selectable_text(&message.text).style(theme::Text::Accent);
let message =
selectable_text(&message.text).style(theme::selectable_text::accent);

Some(container(row![].push_maybe(timestamp).push(message)).into())
}
message::Source::Internal(message::source::Internal::Status(status)) => {
let message =
selectable_text(&message.text).style(theme::Text::Status(*status));
let message = selectable_text(&message.text)
.style(|theme| theme::selectable_text::status(theme, *status));

Some(container(row![].push_maybe(timestamp).push(message)).into())
}
Expand Down Expand Up @@ -260,38 +267,41 @@ fn topic<'a>(

mod nick_list {
use data::{Config, User};
use iced::widget::{column, container, scrollable, text};
use iced::widget::{column, container, scrollable, text, Scrollable};
use iced::Length;
use user_context::Message;

use crate::buffer::user_context;
use crate::theme;
use crate::widget::Element;

pub fn view<'a>(users: &[User], config: &'a Config) -> Element<'a, Message> {
pub fn view<'a>(users: &'a [User], config: &'a Config) -> Element<'a, Message> {
let column = column(users.iter().map(|user| {
let content = text(format!(
"{}{}",
user.highest_access_level(),
user.nickname()
))
.style(theme::Text::Nickname(
user.color_seed(&config.buffer.channel.users.color),
user.is_away(),
));
.style(|theme| {
theme::text::nickname(
theme,
user.color_seed(&config.buffer.channel.users.color),
user.is_away(),
)
});

user_context::view(content, user.clone())
}))
.padding(4)
.spacing(1);

container(
scrollable(column)
.direction(scrollable::Direction::Vertical(
scrollable::Properties::new().width(1).scroller_width(1),
))
.style(theme::Scrollable::Hidden),
)
container(Scrollable::with_direction_and_style(
column,
scrollable::Direction::Vertical(
scrollable::Properties::new().width(1).scroller_width(1),
),
theme::scrollable::hidden,
))
.width(Length::Shrink)
.max_width(120)
.height(Length::Fill)
Expand Down
38 changes: 19 additions & 19 deletions src/buffer/channel/topic.rs
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
use chrono::{DateTime, Utc};
use data::user::Nick;
use data::{Config, User};
use iced::widget::{column, container, horizontal_rule, row, scrollable};
use iced::widget::{column, container, horizontal_rule, row, scrollable, Scrollable};
use iced::Length;

use super::user_context;
use crate::theme;
use crate::widget::{double_pass, selectable_text, Collection, Element};
use crate::widget::{double_pass, selectable_text, Element};

pub fn view<'a>(
text: &'a str,
who: Option<&'a str>,
time: Option<&'a DateTime<Utc>>,
max_lines: u16,
users: &[User],
users: &'a [User],
config: &'a Config,
) -> Element<'a, user_context::Message> {
let set_by = who.and_then(|who| {
let nick = Nick::from(who.split('!').next()?);

let user = if let Some(user) = users.iter().find(|user| user.nickname() == nick) {
user_context::view(
selectable_text(who).style(theme::Text::Nickname(
user.color_seed(&config.buffer.nickname.color),
false,
)),
selectable_text(who).style(|theme| {
theme::selectable_text::nickname(
theme,
user.color_seed(&config.buffer.nickname.color),
false,
)
}),
user.clone(),
)
} else {
selectable_text(who).style(theme::Text::Server).into()
selectable_text(who).style(theme::selectable_text::info).into()
};

Some(row![
selectable_text("set by ").style(theme::Text::Transparent),
selectable_text("set by ").style(theme::selectable_text::transparent),
user,
selectable_text(format!(" at {}", time?.to_rfc2822())).style(theme::Text::Transparent),
selectable_text(format!(" at {}", time?.to_rfc2822())).style(theme::selectable_text::transparent),
])
});

let content = column![selectable_text(text).style(theme::Text::Transparent)].push_maybe(set_by);
let content = column![selectable_text(text).style(theme::selectable_text::transparent)].push_maybe(set_by);

let scrollable = scrollable(container(content).width(Length::Fill).padding(padding()))
.style(theme::Scrollable::Hidden)
.direction(scrollable::Direction::Vertical(
scrollable::Properties::default()
.alignment(scrollable::Alignment::Start)
.width(5)
.scroller_width(5),
));
let scrollable = Scrollable::with_direction_and_style(
container(content).width(Length::Fill).padding(padding()),
scrollable::Direction::Vertical(scrollable::Properties::new().width(1).scroller_width(1)),
theme::scrollable::hidden,
);

// Use double pass to limit layout to `max_lines` of text
column![
Expand Down
36 changes: 22 additions & 14 deletions src/buffer/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use iced::{Command, Length};

use super::{input_view, scroll_view, user_context};
use crate::theme;
use crate::widget::{selectable_text, Collection, Element};
use crate::widget::{selectable_text, Element};

#[derive(Debug, Clone)]
pub enum Message {
Expand Down Expand Up @@ -36,19 +36,25 @@ pub fn view<'a>(
history,
config,
|message| {
let timestamp = config
.buffer
.format_timestamp(&message.server_time)
.map(|timestamp| selectable_text(timestamp).style(theme::Text::Transparent));
let timestamp =
config
.buffer
.format_timestamp(&message.server_time)
.map(|timestamp| {
selectable_text(timestamp).style(theme::selectable_text::transparent)
});

match message.target.source() {
message::Source::User(user) => {
let nick = user_context::view(
selectable_text(config.buffer.nickname.brackets.format(user)).style(
theme::Text::Nickname(
user.color_seed(&config.buffer.nickname.color),
false,
),
|theme| {
theme::selectable_text::nickname(
theme,
user.color_seed(&config.buffer.nickname.color),
false,
)
},
),
user.clone(),
)
Expand All @@ -69,18 +75,20 @@ pub fn view<'a>(
)
}
message::Source::Server(_) => {
let message = selectable_text(&message.text).style(theme::Text::Server);
let message =
selectable_text(&message.text).style(theme::selectable_text::info);

Some(container(row![].push_maybe(timestamp).push(message)).into())
}
message::Source::Action => {
let message = selectable_text(&message.text).style(theme::Text::Accent);
let message =
selectable_text(&message.text).style(theme::selectable_text::accent);

Some(container(row![].push_maybe(timestamp).push(message)).into())
}
message::Source::Internal(message::source::Internal::Status(status)) => {
let message =
selectable_text(&message.text).style(theme::Text::Status(*status));
let message = selectable_text(&message.text)
.style(|theme| theme::selectable_text::status(theme, *status));

Some(container(row![].push_maybe(timestamp).push(message)).into())
}
Expand All @@ -100,7 +108,7 @@ pub fn view<'a>(

let text_input = show_text_input.then(|| {
column![
vertical_space(4),
vertical_space().height(4),
input_view::view(&state.input_view, buffer, input, &[], channels, is_focused)
.map(Message::InputView)
]
Expand Down
Loading
Loading