Skip to content

Commit

Permalink
added welcome and help screens
Browse files Browse the repository at this point in the history
  • Loading branch information
casperstorm committed Jun 25, 2023
1 parent ac72fec commit c2a62e4
Show file tree
Hide file tree
Showing 11 changed files with 504 additions and 62 deletions.
275 changes: 275 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ data = { version = "0.1.0", path = "data" }

chrono = { version = "0.4", features = ['serde'] }
fern = "0.6.1"
iced = { version = "0.9", features = ["tokio", "lazy", "advanced"] }
iced = { version = "0.9", features = ["tokio", "lazy", "advanced", "image"] }
log = "0.4.16"
palette = "=0.7.2"
thiserror = "1.0.30"
Expand Down
Binary file modified assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion data/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ pub enum Error {
DirectoryCreation,
#[error("config could not be read: {0}")]
Read(String),
#[error("config could not be parsed: {0}")]
#[error("{0}")]
Parse(String),
}
2 changes: 1 addition & 1 deletion src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub const MONO: Font = Font {
..Font::with_name("Iosevka Term")
};

pub const _MONO_BOLD: Font = Font {
pub const MONO_BOLD: Font = Font {
monospaced: true,
weight: font::Weight::Bold,
..Font::with_name("Iosevka Term")
Expand Down
5 changes: 5 additions & 0 deletions src/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ use crate::{font, theme};

// Based off https://github.com/iced-rs/iced_aw/blob/main/src/graphics/icons/bootstrap.rs

pub fn error<'a>() -> Text<'a> {
to_text('\u{f33a}')
}

pub fn globe<'a>() -> Text<'a> {
to_text('\u{f3ef}')
}
Expand Down Expand Up @@ -40,6 +44,7 @@ pub fn people<'a>() -> Text<'a> {

fn to_text<'a>(unicode: char) -> Text<'a> {
text(unicode.to_string())
.style(theme::Text::Primary)
.line_height(LineHeight::Relative(1.1))
.size(theme::ICON_SIZE)
.font(font::ICON)
Expand Down
110 changes: 79 additions & 31 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,51 @@ struct Halloy {
clients: data::client::Map,
}

enum Screen {
impl Halloy {
pub fn load_from_configuration() -> (Halloy, Command<Message>) {
let (screen, config, command) = match Config::load() {
Ok(config) => {
let (screen, command) = screen::Dashboard::new(&config);
(
Screen::Dashboard(screen),
config,
command.map(Message::Dashboard),
)
}
Err(error) => match &error {
config::Error::Parse(_) => (
Screen::Help(screen::Help::new(error)),
Config::default(),
Command::none(),
),
_ => (
Screen::Welcome(screen::Welcome::new()),
Config::default(),
Command::none(),
),
},
};

(
Halloy {
screen,
theme: Theme::new_from_palette(config.palette),
config,
clients: Default::default(),
},
command,
)
}
}

pub enum Screen {
Dashboard(screen::Dashboard),
Help(screen::Help),
Welcome(screen::Welcome),
}

#[derive(Debug)]
enum Message {
pub enum Message {
Dashboard(dashboard::Message),
Stream(stream::Update),
Help(help::Message),
Expand All @@ -107,42 +144,43 @@ enum Message {
FontsLoaded(Result<(), iced::font::Error>),
}

pub fn load_configuration() -> (Screen, Config, Command<Message>) {
match Config::load() {
Ok(config) => {
let (screen, command) = screen::Dashboard::new(&config);
(
Screen::Dashboard(screen),
config,
command.map(Message::Dashboard),
)
}
Err(error) => match &error {
config::Error::Parse(_) => (
Screen::Help(screen::Help::new(error)),
Config::default(),
Command::none(),
),
_ => (
Screen::Welcome(screen::Welcome::new()),
Config::default(),
Command::none(),
),
},
}
}

impl Application for Halloy {
type Executor = executor::Default;
type Message = Message;
type Flags = ();
type Theme = theme::Theme;
type Flags = ();

fn new(_flags: ()) -> (Halloy, Command<Self::Message>) {
let (config, config_error) = match Config::load() {
Ok(config) => (config, None),
Err(error) => (Config::default(), Some(error)),
};

let (screen, command) = match config_error {
Some(error) => match &error {
config::Error::Parse(_) => {
(Screen::Welcome(screen::Welcome::new()), Command::none())
}
_ => (Screen::Help(screen::Help::new(error)), Command::none()),
},
None => {
let (screen, command) = screen::Dashboard::new(&config);
(Screen::Dashboard(screen), command)
}
};
let (halloy, command) = Halloy::load_from_configuration();

(
Halloy {
screen,
theme: Theme::new_from_palette(config.palette),
config,
clients: Default::default(),
},
Command::batch(vec![
font::load().map(Message::FontsLoaded),
command.map(Message::Dashboard),
]),
halloy,
Command::batch(vec![font::load().map(Message::FontsLoaded), command]),
)
}

Expand Down Expand Up @@ -171,7 +209,17 @@ impl Application for Halloy {
return Command::none();
};

let _ = help.update(message);
if let Some(event) = help.update(message) {
match event {
help::Event::RefreshConfiguration => {
let (halloy, command) = Halloy::load_from_configuration();
*self = halloy;

return command;
}
}
}

Command::none()
}
Message::Welcome(message) => {
Expand Down
22 changes: 15 additions & 7 deletions src/screen/dashboard/side_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,24 @@ fn buffer_button<'a>(
} else {
icon::wifi_off()
},
text(server.to_string())
text(server.to_string()).style(theme::Text::Primary)
]
.spacing(8)
.align_items(iced::Alignment::Center),
Buffer::Channel(_, channel) => row![
horizontal_space(4),
icon::chat(),
text(channel).style(theme::Text::Primary)
]
.spacing(8)
.align_items(iced::Alignment::Center),
Buffer::Query(_, nick) => row![
horizontal_space(4),
icon::person(),
text(nick).style(theme::Text::Primary)
]
.spacing(8)
.align_items(iced::Alignment::Center),
Buffer::Channel(_, channel) => row![horizontal_space(4), icon::chat(), text(channel)]
.spacing(8)
.align_items(iced::Alignment::Center),
Buffer::Query(_, nick) => row![horizontal_space(4), icon::person(), text(nick)]
.spacing(8)
.align_items(iced::Alignment::Center),
};

let base = button(row)
Expand Down
65 changes: 57 additions & 8 deletions src/screen/help.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
use data::config;
use iced::widget::{column, container, text};
use data::{config, Config};
use iced::widget::{button, column, container, row, text, vertical_space};
use iced::{alignment, Length};

use crate::widget::Element;
use crate::widget::{Collection, Element};
use crate::{font, icon, theme};

#[derive(Debug, Clone)]
pub enum Message {}
pub enum Message {
RefreshConfiguration,
OpenConfigurationDirectory,
}

#[derive(Debug, Clone)]
pub enum Event {}
pub enum Event {
RefreshConfiguration,
}

#[derive(Debug, Clone)]
pub struct Help {
Expand All @@ -20,13 +26,56 @@ impl Help {
Help { error }
}

pub fn update(&mut self, _message: Message) -> Option<Event> {
None
pub fn update(&mut self, message: Message) -> Option<Event> {
match message {
Message::RefreshConfiguration => Some(Event::RefreshConfiguration),
Message::OpenConfigurationDirectory => {
let Ok(config) = Config::config_dir() else {
return None
};

let _ = open::that(config);

None
}
}
}

pub fn view<'a>(&self) -> Element<'a, Message> {
let config_button = Config::config_dir().ok().map(|_| {
button(
container(text("Open Directory"))
.align_x(alignment::Horizontal::Center)
.width(Length::Fill),
)
.width(Length::Fill)
.style(theme::Button::Secondary)
.on_press(Message::OpenConfigurationDirectory)
});
let refresh_button = button(
container(text("Refresh"))
.align_x(alignment::Horizontal::Center)
.width(Length::Fill),
)
.width(Length::Fill)
.style(theme::Button::Secondary)
.on_press(Message::RefreshConfiguration);

let content = column![]
.push(text("halloy help"))
.spacing(1)
.push(icon::error().size(45))
.push(vertical_space(10))
.push(text("Error reading configuration file").font(font::MONO_BOLD))
.push(vertical_space(3))
.push(text(self.error.to_string()).style(theme::Text::Error))
.push(vertical_space(10))
.push(
row![]
.width(250)
.spacing(4)
.push_maybe(config_button)
.push(refresh_button),
)
.align_items(iced::Alignment::Center);

container(content)
Expand Down
57 changes: 50 additions & 7 deletions src/screen/welcome.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
use data::config;
use iced::widget::{column, container, text};
use std::path::PathBuf;

use data::{config, Config};
use iced::widget::{button, column, container, image, row, text, vertical_space};
use iced::{alignment, Length};

use crate::widget::Element;
use crate::widget::{Collection, Element};
use crate::{font, theme};

#[derive(Debug, Clone)]
pub enum Message {}
pub enum Message {
RefreshConfiguration,
OpenConfigurationDirectory,
}

#[derive(Debug, Clone)]
pub enum Event {}
pub enum Event {
RefreshConfiguration,
}

#[derive(Debug, Clone)]
pub struct Welcome {}
Expand All @@ -23,11 +31,46 @@ impl Welcome {
}

pub fn view<'a>(&self) -> Element<'a, Message> {
let config_button = Config::config_dir().ok().map(|_| {
button(
container(text("Open Directory"))
.align_x(alignment::Horizontal::Center)
.width(Length::Fill),
)
.width(Length::Fill)
.style(theme::Button::Secondary)
.on_press(Message::OpenConfigurationDirectory)
});

let refresh_button = button(
container(text("Refresh"))
.align_x(alignment::Horizontal::Center)
.width(Length::Fill),
)
.width(Length::Fill)
.style(theme::Button::Secondary)
.on_press(Message::RefreshConfiguration);

let content = column![]
.push(text("halloy welcome"))
.spacing(1)
.push(image(format!("{}/assets/logo.png", env!("CARGO_MANIFEST_DIR"))).width(150))
.push(vertical_space(10))
.push(text("Welcome to Halloy!").font(font::MONO_BOLD))
.push(vertical_space(4))
.push(text(
"To get started, please create a configuration file. You can find help to create the configuration file on the website: halloy.squidowl.org",
))
.push(vertical_space(10))
.push(
row![]
.width(250)
.spacing(4)
.push_maybe(config_button)
.push(refresh_button),
)
.align_items(iced::Alignment::Center);

container(content)
container(container(content).width(450))
.align_x(alignment::Horizontal::Center)
.align_y(alignment::Vertical::Center)
.width(Length::Fill)
Expand Down
Loading

0 comments on commit c2a62e4

Please sign in to comment.