Style the message log
This commit is contained in:
parent
8dddabc0e6
commit
d077040823
2 changed files with 133 additions and 37 deletions
10
shell.nix
10
shell.nix
|
@ -4,6 +4,8 @@
|
||||||
cargo
|
cargo
|
||||||
clippy
|
clippy
|
||||||
clang
|
clang
|
||||||
|
rust-analyzer
|
||||||
|
rustPlatform.rustcSrc
|
||||||
llvmPackages.bintools
|
llvmPackages.bintools
|
||||||
|
|
||||||
pkg-config
|
pkg-config
|
||||||
|
@ -23,16 +25,18 @@
|
||||||
xorg.libXi
|
xorg.libXi
|
||||||
xorg.libX11
|
xorg.libX11
|
||||||
];
|
];
|
||||||
|
|
||||||
RUSTC_VERSION = pkgs.lib.readFile ./rust-toolchain;
|
RUSTC_VERSION = pkgs.lib.readFile ./rust-toolchain;
|
||||||
# https://github.com/rust-lang/rust-bindgen#environment-variables
|
|
||||||
LIBCLANG_PATH = pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ];
|
LIBCLANG_PATH = pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ];
|
||||||
|
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin
|
export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin
|
||||||
export PATH=$PATH:''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/
|
export PATH=$PATH:''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Add libvmi precompiled library to rustc search path
|
# Add libvmi precompiled library to rustc search path
|
||||||
RUSTFLAGS = (builtins.map (a: ''-L ${a}/lib'') [
|
RUSTFLAGS = (builtins.map (a: ''-L ${a}/lib'') [
|
||||||
# pkgs.libvmi
|
#pkgs.libvmi
|
||||||
]);
|
]);
|
||||||
# Add libvmi, glibc, clang, glib headers to bindgen search path
|
# Add libvmi, glibc, clang, glib headers to bindgen search path
|
||||||
BINDGEN_EXTRA_CLANG_ARGS =
|
BINDGEN_EXTRA_CLANG_ARGS =
|
||||||
|
@ -47,6 +51,6 @@
|
||||||
''-I"${pkgs.glib.dev}/include/glib-2.0"''
|
''-I"${pkgs.glib.dev}/include/glib-2.0"''
|
||||||
''-I${pkgs.glib.out}/lib/glib-2.0/include/''
|
''-I${pkgs.glib.out}/lib/glib-2.0/include/''
|
||||||
];
|
];
|
||||||
LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath buildInputs}";
|
|
||||||
|
|
||||||
|
LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath buildInputs}";
|
||||||
}
|
}
|
||||||
|
|
126
src/main.rs
126
src/main.rs
|
@ -7,6 +7,7 @@ use std::cell::RefCell;
|
||||||
|
|
||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
|
use iced::alignment::Horizontal;
|
||||||
use iced::theme::Theme;
|
use iced::theme::Theme;
|
||||||
use iced::widget::{column, container, mouse_area, row, scrollable, text, text_input};
|
use iced::widget::{column, container, mouse_area, row, scrollable, text, text_input};
|
||||||
use iced::{executor, Application, Background, Color, Length, Settings};
|
use iced::{executor, Application, Background, Color, Length, Settings};
|
||||||
|
@ -194,31 +195,75 @@ impl Application for Cri {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self) -> iced::Element<'_, Self::Message, iced::Renderer<Self::Theme>> {
|
fn view(&self) -> iced::Element<'_, Self::Message, iced::Renderer<Self::Theme>> {
|
||||||
let dark_green = Color::new(0.153, 0.682, 0.377, 1.0);
|
let lighter_grey = Color::new(0.93, 0.94, 0.95, 1.0);
|
||||||
let dark_grey = Color::new(0.584, 0.647, 0.651, 1.0);
|
let dark_grey = Color::new(0.58, 0.65, 0.65, 1.0);
|
||||||
let _darker_grey = Color::new(0.498, 0.549, 0.553, 1.0);
|
let lighter_green = Color::new(0.94, 0.99, 0.87, 1.0);
|
||||||
|
let dark_red = Color::new(0.75, 0.22, 0.17, 1.0);
|
||||||
|
|
||||||
let log = scrollable(column(
|
let event_appearance = container::Appearance {
|
||||||
self.message_log
|
background: Some(Background::Color(dark_grey)),
|
||||||
|
border_radius: 8.0.into(),
|
||||||
|
text_color: Some(Color::WHITE),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let message_appearance = container::Appearance {
|
||||||
|
background: Some(Background::Color(Color::WHITE)),
|
||||||
|
border_radius: 8.0.into(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let own_message_appearance = container::Appearance {
|
||||||
|
background: Some(Background::Color(lighter_green)),
|
||||||
|
border_radius: 8.0.into(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let messages = self
|
||||||
|
.message_log
|
||||||
.get(&self.active_channel)
|
.get(&self.active_channel)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|message| match message {
|
.flat_map(|message| -> Option<iced::Element<_>> {
|
||||||
IrcMessage::Join { nickname } => {
|
match message {
|
||||||
Some(text(format!("* {nickname} joined the channel")).style(dark_green))
|
IrcMessage::Join { nickname } => Some(
|
||||||
}
|
container(
|
||||||
|
container(text(format!("{nickname} joined the channel")))
|
||||||
|
.style(move |_: &_| event_appearance)
|
||||||
|
.padding([3, 10]),
|
||||||
|
)
|
||||||
|
.width(Length::Fill)
|
||||||
|
.center_x()
|
||||||
|
.padding([3, 0])
|
||||||
|
.into(),
|
||||||
|
),
|
||||||
IrcMessage::Part { nickname, reason } => {
|
IrcMessage::Part { nickname, reason } => {
|
||||||
let reason = match reason {
|
let reason = match reason {
|
||||||
Some(reason) => format!(" ({reason})"),
|
Some(reason) => format!(" ({reason})"),
|
||||||
None => String::new(),
|
None => String::new(),
|
||||||
};
|
};
|
||||||
Some(
|
Some(
|
||||||
text(format!("* {nickname} left the channel{reason}"))
|
container(
|
||||||
.style(dark_green),
|
container(text(format!("{nickname} left the channel{reason}")))
|
||||||
|
.style(move |_: &_| event_appearance)
|
||||||
|
.padding([3, 10]),
|
||||||
|
)
|
||||||
|
.width(Length::Fill)
|
||||||
|
.center_x()
|
||||||
|
.padding([3, 0])
|
||||||
|
.into(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
IrcMessage::Nick { old, new } => Some(
|
IrcMessage::Nick { old, new } => Some(
|
||||||
text(format!("* {old} changed their nickname to {new}")).style(dark_green),
|
container(
|
||||||
|
container(text(format!("{old} changed their nickname to {new}")))
|
||||||
|
.style(move |_: &_| event_appearance)
|
||||||
|
.padding([3, 10]),
|
||||||
|
)
|
||||||
|
.width(Length::Fill)
|
||||||
|
.center_x()
|
||||||
|
.padding([3, 0])
|
||||||
|
.into(),
|
||||||
),
|
),
|
||||||
IrcMessage::Quit { nickname, reason } => {
|
IrcMessage::Quit { nickname, reason } => {
|
||||||
let reason = match reason {
|
let reason = match reason {
|
||||||
|
@ -227,18 +272,65 @@ impl Application for Cri {
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(
|
Some(
|
||||||
text(format!("* {nickname} quit the server{reason}")).style(dark_green),
|
container(
|
||||||
|
container(text(format!("{nickname} left the server{reason}")))
|
||||||
|
.style(move |_: &_| event_appearance)
|
||||||
|
.padding([3, 10]),
|
||||||
|
)
|
||||||
|
.width(Length::Fill)
|
||||||
|
.center_x()
|
||||||
|
.padding([3, 0])
|
||||||
|
.into(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
IrcMessage::Privmsg { nickname, message } => {
|
IrcMessage::Privmsg { nickname, message } => {
|
||||||
Some(text(format!("<{nickname}> {message}")))
|
// TODO don't hardcode nickname lol
|
||||||
|
let is_self = nickname == "cri";
|
||||||
|
|
||||||
|
let mut elements = Vec::new();
|
||||||
|
if !is_self {
|
||||||
|
elements.push(text(nickname).style(dark_red).into())
|
||||||
|
}
|
||||||
|
elements.push(text(message).into());
|
||||||
|
|
||||||
|
Some(
|
||||||
|
container(
|
||||||
|
container(column(elements))
|
||||||
|
.style(move |_: &_| {
|
||||||
|
if is_self {
|
||||||
|
own_message_appearance
|
||||||
|
} else {
|
||||||
|
message_appearance
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.padding([4, 10]),
|
||||||
|
)
|
||||||
|
.width(Length::Fill)
|
||||||
|
.align_x(if is_self {
|
||||||
|
Horizontal::Right
|
||||||
|
} else {
|
||||||
|
Horizontal::Left
|
||||||
|
})
|
||||||
|
.padding([4, 8])
|
||||||
|
.into(),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.map(|element| element.into())
|
.map(|element| element.into())
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>();
|
||||||
))
|
|
||||||
|
let log = container(
|
||||||
|
scrollable(column(messages))
|
||||||
.height(Length::Fill)
|
.height(Length::Fill)
|
||||||
.width(Length::Fill);
|
.width(Length::Fill),
|
||||||
|
)
|
||||||
|
.height(Length::Fill)
|
||||||
|
.width(Length::Fill)
|
||||||
|
.style(move |_: &_| container::Appearance {
|
||||||
|
background: Some(Background::Color(lighter_grey)),
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
|
||||||
let message_box = text_input("your magnum opus", &self.input_value)
|
let message_box = text_input("your magnum opus", &self.input_value)
|
||||||
.id(INPUT_ID.clone())
|
.id(INPUT_ID.clone())
|
||||||
|
|
Loading…
Reference in a new issue