summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-12-18 21:33:01 +0100
committerMatthias Beyer <mail@beyermatthias.de>2021-12-18 21:34:08 +0100
commit7675eba9244475c3847fd48eb13b5d8b54cf271c (patch)
treef65ebfbbe9da51c8b789651ac0156023ed2db589
parent6c03b953ee5172c52ec001cf24e8143f034a1828 (diff)
Add way to show application log
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--gui/src/app/message.rs2
-rw-r--r--gui/src/app/mod.rs107
2 files changed, 88 insertions, 21 deletions
diff --git a/gui/src/app/message.rs b/gui/src/app/message.rs
index f530774..68be044 100644
--- a/gui/src/app/message.rs
+++ b/gui/src/app/message.rs
@@ -10,6 +10,8 @@ pub enum Message {
Loaded(Arc<Profile>),
FailedToLoad(String),
+ ToggleLog,
+
InputChanged(String),
CreatePost,
diff --git a/gui/src/app/mod.rs b/gui/src/app/mod.rs
index 3cf45f9..dfd5677 100644
--- a/gui/src/app/mod.rs
+++ b/gui/src/app/mod.rs
@@ -5,6 +5,7 @@ use iced::Application;
use iced::Column;
use iced::Container;
use iced::Length;
+use iced::Row;
use iced::Scrollable;
use iced::TextInput;
use iced::scrollable;
@@ -27,6 +28,8 @@ enum Distrox {
input: text_input::State,
input_value: String,
timeline: Timeline,
+
+ log_visible: bool,
},
FailedToStart,
}
@@ -65,6 +68,7 @@ impl Application for Distrox {
input: text_input::State::default(),
input_value: String::default(),
timeline: Timeline::new(),
+ log_visible: false
};
}
@@ -78,7 +82,7 @@ impl Application for Distrox {
}
}
- Distrox::Loaded { profile, ref mut input_value, timeline, .. } => {
+ Distrox::Loaded { profile, ref mut input_value, timeline, log_visible, .. } => {
match message {
Message::InputChanged(input) => {
*input_value = input;
@@ -121,6 +125,11 @@ impl Application for Distrox {
log::trace!("Timeline scrolled: {}", f);
}
+ Message::ToggleLog => {
+ log::trace!("Log toggled");
+ *log_visible = !*log_visible;
+ }
+
_ => {}
}
}
@@ -149,24 +158,58 @@ impl Application for Distrox {
.into()
}
- Distrox::Loaded { input, input_value, timeline, scroll, .. } => {
- let input = TextInput::new(
- input,
- "What do you want to tell the world?",
- input_value,
- Message::InputChanged,
- )
- .padding(15)
- .size(12)
- .on_submit(Message::CreatePost);
-
- let timeline = timeline.view();
-
- Scrollable::new(scroll)
- .padding(40)
- .push(input)
- .push(timeline)
- .into()
+ Distrox::Loaded { input, input_value, timeline, scroll, log_visible, .. } => {
+ let left_column = Column::new()
+ .into();
+
+ let mid_column = Column::new()
+ .push({
+ let input = TextInput::new(
+ input,
+ "What do you want to tell the world?",
+ input_value,
+ Message::InputChanged,
+ )
+ .padding(15)
+ .size(12)
+ .on_submit(Message::CreatePost);
+
+ let timeline = timeline.view();
+
+ Scrollable::new(scroll)
+ .padding(40)
+ .push(input)
+ .push(timeline)
+ })
+ .into();
+
+ let right_column = Column::new()
+ .into();
+
+ let content = Row::with_children(vec![
+ left_column,
+ mid_column,
+ right_column
+ ])
+ .spacing(20)
+ .height(Length::Fill)
+ .width(Length::Fill);
+
+ let content = Column::new()
+ .height(Length::Fill)
+ .width(Length::Fill)
+ .push(content);
+
+ if *log_visible {
+ let log = Column::new()
+ .push({
+ iced::Text::new("Here goes some log,... not yet implemented!")
+ .size(8)
+ });
+ content.push(log)
+ } else {
+ content
+ }.into()
}
Distrox::FailedToStart => {
@@ -176,7 +219,7 @@ impl Application for Distrox {
}
fn subscription(&self) -> iced::Subscription<Self::Message> {
- match self {
+ let post_loading_subs = match self {
Distrox::Loaded { profile, .. } => {
let head = profile.head();
@@ -190,7 +233,29 @@ impl Application for Distrox {
}
}
_ => iced::Subscription::none(),
- }
+ };
+
+ let keyboard_subs = {
+ use iced_native::event::Event;
+
+ iced_native::subscription::events_with(|event, _| {
+ match event {
+ Event::Keyboard(iced_native::keyboard::Event::KeyPressed { key_code, .. }) => {
+ if key_code == iced_native::keyboard::KeyCode::F11 {
+ Some(Message::ToggleLog)
+ } else {
+ None
+ }
+ },
+ _ => None,
+ }
+ })
+ };
+
+ iced::Subscription::batch(vec![
+ post_loading_subs,
+ keyboard_subs
+ ])
}
}