diff --git a/docs/modules/Focused.md b/docs/modules/Focused.md index 52469d3..514cbcf 100644 --- a/docs/modules/Focused.md +++ b/docs/modules/Focused.md @@ -7,14 +7,15 @@ Displays the title and/or icon of the currently focused window. > Type: `focused` -| Name | Type | Default | Description | -|-------------------|---------------------------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------| -| `show_icon` | `boolean` | `true` | Whether to show the app's icon | -| `show_title` | `boolean` | `true` | Whether to show the app's title | -| `icon_size` | `integer` | `32` | Size of icon in pixels | -| `truncate` | `start` or `middle` or `end` or `Map` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. Use the long-hand `Map` version if specifying a length. | -| `truncate.mode` | `start` or `middle` or `end` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. | -| `truncate.length` | `integer` | `null` | The maximum number of characters before truncating. Leave blank to let GTK automatically handle. | +| Name | Type | Default | Description | +|-----------------------|---------------------------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------| +| `show_icon` | `boolean` | `true` | Whether to show the app's icon | +| `show_title` | `boolean` | `true` | Whether to show the app's title | +| `icon_size` | `integer` | `32` | Size of icon in pixels | +| `truncate` | `start` or `middle` or `end` or `Map` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. Use the long-hand `Map` version if specifying a length. | +| `truncate.mode` | `start` or `middle` or `end` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. | +| `truncate.length` | `integer` | `null` | The fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. | +| `truncate.max_length` | `integer` | `null` | The maximum number of characters before truncating. Leave blank to let GTK automatically handle. |
JSON diff --git a/docs/modules/Music.md b/docs/modules/Music.md index 46608c7..044c816 100644 --- a/docs/modules/Music.md +++ b/docs/modules/Music.md @@ -11,23 +11,24 @@ in MPRIS mode, the widget will listen to all players and automatically detect/di > Type: `music` -| | Type | Default | Description | -|-------------------|---------------------------------------|----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------| -| `player_type` | `mpris` or `mpd` | `mpris` | Whether to connect to MPRIS players or an MPD server. | -| `format` | `string` | `{title} / {artist}` | Format string for the widget. More info below. | -| `truncate` | `start` or `middle` or `end` or `Map` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. Use the long-hand `Map` version if specifying a length. | -| `truncate.mode` | `start` or `middle` or `end` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. | -| `truncate.length` | `integer` | `null` | The maximum number of characters before truncating. Leave blank to let GTK automatically handle. | -| `icons.play` | `string/image` | `` | Icon to show when playing. | -| `icons.pause` | `string/image` | `` | Icon to show when paused. | -| `icons.prev` | `string/image` | `玲` | Icon to show on previous button. | -| `icons.next` | `string/image` | `怜` | Icon to show on next button. | -| `icons.volume` | `string/image` | `墳` | Icon to show under popup volume slider. | -| `icons.track` | `string/image` | `` | Icon to show next to track title. | -| `icons.album` | `string/image` | `` | Icon to show next to album name. | -| `icons.artist` | `string/image` | `ﴁ` | Icon to show next to artist name. | -| `host` | `string/image` | `localhost:6600` | [MPD Only] TCP or Unix socket for the MPD server. | -| `music_dir` | `string/image` | `$HOME/Music` | [MPD Only] Path to MPD server's music directory on disc. Required for album art. | +| | Type | Default | Description | +|-----------------------|---------------------------------------|----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------| +| `player_type` | `mpris` or `mpd` | `mpris` | Whether to connect to MPRIS players or an MPD server. | +| `format` | `string` | `{title} / {artist}` | Format string for the widget. More info below. | +| `truncate` | `start` or `middle` or `end` or `Map` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. Use the long-hand `Map` version if specifying a length. | +| `truncate.mode` | `start` or `middle` or `end` | `null` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. | +| `truncate.length` | `integer` | `null` | The fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. | +| `truncate.max_length` | `integer` | `null` | The maximum number of characters before truncating. Leave blank to let GTK automatically handle. | +| `icons.play` | `string/image` | `` | Icon to show when playing. | +| `icons.pause` | `string/image` | `` | Icon to show when paused. | +| `icons.prev` | `string/image` | `玲` | Icon to show on previous button. | +| `icons.next` | `string/image` | `怜` | Icon to show on next button. | +| `icons.volume` | `string/image` | `墳` | Icon to show under popup volume slider. | +| `icons.track` | `string/image` | `` | Icon to show next to track title. | +| `icons.album` | `string/image` | `` | Icon to show next to album name. | +| `icons.artist` | `string/image` | `ﴁ` | Icon to show next to artist name. | +| `host` | `string/image` | `localhost:6600` | [MPD Only] TCP or Unix socket for the MPD server. | +| `music_dir` | `string/image` | `$HOME/Music` | [MPD Only] Path to MPD server's music directory on disc. Required for album art. | See [here](images) for information on images. diff --git a/src/config/truncate.rs b/src/config/truncate.rs index ebf8a8c..fed4ffc 100644 --- a/src/config/truncate.rs +++ b/src/config/truncate.rs @@ -24,31 +24,43 @@ impl From for GtkEllipsizeMode { #[serde(untagged)] pub enum TruncateMode { Auto(EllipsizeMode), - MaxLength { + Length { mode: EllipsizeMode, length: Option, + max_length: Option, }, } 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 { match self { Self::Auto(_) => None, - Self::MaxLength { length, .. } => *length, + Self::Length { length, .. } => *length, + } + } + + const fn max_length(&self) -> Option { + 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); } } }