Skip to content

Commit

Permalink
Convert max height topic banner configuration to max lines.
Browse files Browse the repository at this point in the history
  • Loading branch information
andymandias committed Mar 4, 2024
1 parent 0b96149 commit a655b0d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
7 changes: 4 additions & 3 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ buffer:
# Topic changes will still show up as a server
# message in channel.
topic: !Banner
# Maximum height of the topic banner, when topic is set to !Banner.
# - Default is 42
max_height: 42
# Maximum visible lines of the topic banner before scrolling, when
# topic is set to !Banner.
# - Default is 2
max_lines: 2

# Control different server messages.
# - exclude [All, None, !Smart seconds]:
Expand Down
8 changes: 4 additions & 4 deletions data/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ pub enum Topic {
#[default]
Inline,
Banner {
#[serde(default = "default_topic_banner_max_height")]
max_height: u16,
#[serde(default = "default_topic_banner_max_lines")]
max_lines: u16,
},
}

fn default_topic_banner_max_height() -> u16 {
42
fn default_topic_banner_max_lines() -> u16 {
2
}

#[derive(Debug, Clone, Deserialize)]
Expand Down
6 changes: 5 additions & 1 deletion src/buffer/banner_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn view<'a>(
let content = column![column(messages)];

Some(
scrollable(container(content).width(Length::Fill).padding([4, 8]))
scrollable(container(content).width(Length::Fill).padding(padding()))
.style(theme::Scrollable::Banner)
.direction(scrollable::Direction::Vertical(
scrollable::Properties::default()
Expand All @@ -60,6 +60,10 @@ pub fn view<'a>(
)
}

pub fn padding() -> [u16; 2] {
[4, 8]
}

pub fn style_topic_who_time<'a>(
who: &str,
time: DateTime<Utc>,
Expand Down
23 changes: 14 additions & 9 deletions src/buffer/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use iced::{Command, Length};

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

#[derive(Debug, Clone)]
pub enum Message {
Expand Down Expand Up @@ -120,10 +120,7 @@ pub fn view<'a>(
data::buffer::InputVisibility::Always => status.connected(),
};

let topic_banner = if let Topic::Banner {
max_height: topic_banner_max_height,
} = config.buffer.topic
{
let topic_banner = if let Topic::Banner { max_lines } = config.buffer.topic {
banner_view::view(
&state.banner_view,
banner_view::Kind::ChannelTopic(&state.server, &state.channel),
Expand Down Expand Up @@ -169,10 +166,18 @@ pub fn view<'a>(
},
)
.map(|banner| {
column![container(banner.map(Message::BannerView))
.style(theme::Container::Banner)
.max_height(topic_banner_max_height)]
.width(Length::Fill)
let mut layout_column = column![];
for _ in 0..max_lines {
layout_column = layout_column.push(row![].push(selectable_text(" ")));
}

double_pass(
container(layout_column)
.width(Length::Fill)
.padding(banner_view::padding()),
column![container(banner.map(Message::BannerView)).style(theme::Container::Banner)]
.width(Length::Fill),
)
})
} else {
None
Expand Down

0 comments on commit a655b0d

Please sign in to comment.