mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-07-01 18:51:04 +02:00
feat(truncate): ability to set fixed length
BREAKING CHANGE: This changes the behaviour of `truncate.length`. A new property, `truncate.max_length`, has been introduced that uses the old behaviour.
This commit is contained in:
parent
1ad1961396
commit
ca4fe422f2
3 changed files with 44 additions and 30 deletions
|
@ -24,31 +24,43 @@ impl From<EllipsizeMode> for GtkEllipsizeMode {
|
|||
#[serde(untagged)]
|
||||
pub enum TruncateMode {
|
||||
Auto(EllipsizeMode),
|
||||
MaxLength {
|
||||
Length {
|
||||
mode: EllipsizeMode,
|
||||
length: Option<i32>,
|
||||
max_length: Option<i32>,
|
||||
},
|
||||
}
|
||||
|
||||
impl TruncateMode {
|
||||
const fn mode(&self) -> EllipsizeMode {
|
||||
match self {
|
||||
Self::MaxLength { mode, .. } | Self::Auto(mode) => *mode,
|
||||
Self::Length { mode, .. } | Self::Auto(mode) => *mode,
|
||||
}
|
||||
}
|
||||
|
||||
const fn length(&self) -> Option<i32> {
|
||||
match self {
|
||||
Self::Auto(_) => None,
|
||||
Self::MaxLength { length, .. } => *length,
|
||||
Self::Length { length, .. } => *length,
|
||||
}
|
||||
}
|
||||
|
||||
const fn max_length(&self) -> Option<i32> {
|
||||
match self {
|
||||
Self::Auto(_) => None,
|
||||
Self::Length { max_length, .. } => *max_length,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn truncate_label(&self, label: >k::Label) {
|
||||
label.set_ellipsize(self.mode().into());
|
||||
|
||||
if let Some(max_length) = self.length() {
|
||||
label.set_max_width_chars(max_length);
|
||||
if let Some(length) = self.length() {
|
||||
label.set_width_chars(length);
|
||||
}
|
||||
|
||||
if let Some(length) = self.max_length() {
|
||||
label.set_max_width_chars(length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue