Skip to content

Commit 9b67719

Browse files
authored
Merge pull request #873 from JakeStanger/feat/launcher-paginate
Launcher pagination and label truncation options
2 parents 5049226 + ba5ec80 commit 9b67719

File tree

7 files changed

+322
-39
lines changed

7 files changed

+322
-39
lines changed

docs/modules/Custom.md

+10-5
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,16 @@ A text label. Pango markup is supported.
5454

5555
> Type `label`
5656
57-
| Name | Type | Default | Description |
58-
|---------------|------------------------------------------------------------|----------------|----------------------------------------------------------------------|
59-
| `label` | [Dynamic String](dynamic-values#dynamic-string) | `null` | Widget text label. Pango markup and embedded scripts are supported. |
60-
| `orientation` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | Orientation of the label text. |
61-
| `justify` | `'left'`, `'right'`, `'center'`, or `'fill'` | `'left'` | Justification (alignment) of the label text. |
57+
| Name | Type | Default | Description |
58+
|-----------------------|------------------------------------------------------------|----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
59+
| `label` | [Dynamic String](dynamic-values#dynamic-string) | `null` | Widget text label. Pango markup and embedded scripts are supported. |
60+
| `orientation` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | Orientation of the label text. |
61+
| `justify` | `'left'`, `'right'`, `'center'`, or `'fill'` | `'left'` | Justification (alignment) of the label text. |
62+
| `truncate` | `'start'` or `'middle'` or `'end'` or `off` or `Map` | `off` | 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. |
63+
| `truncate.mode` | `'start'` or `'middle'` or `'end'` or `off` | `off` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. |
64+
| `truncate.length` | `integer` | `null` | The fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. |
65+
| `truncate.max_length` | `integer` | `null` | The maximum number of characters before truncating. Leave blank to let GTK automatically handle. |
66+
6267

6368
#### Button
6469

docs/modules/Label.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ For more advanced use-cases, use [custom](custom).
77

88
> Type: `label`
99
10-
| Name | Type | Default | Description |
11-
|---------|-------------------------------------------------|---------|------------------------|
12-
| `label` | [Dynamic String](dynamic-values#dynamic-string) | `null` | Text to show on label. |
10+
| Name | Type | Default | Description |
11+
|-----------------------|------------------------------------------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
12+
| `label` | [Dynamic String](dynamic-values#dynamic-string) | `null` | Text to show on label. |
13+
| `truncate` | `'start'` or `'middle'` or `'end'` or `off` or `Map` | `off` | 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. |
14+
| `truncate.mode` | `'start'` or `'middle'` or `'end'` or `off` | `off` | The location of the ellipses and where to truncate text from. Leave null to avoid truncating. |
15+
| `truncate.length` | `integer` | `null` | The fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. |
16+
| `truncate.max_length` | `integer` | `null` | The maximum number of characters before truncating. Leave blank to let GTK automatically handle. |
17+
1318

1419
<details>
1520
<summary>JSON</summary>

docs/modules/Launcher.md

+29-25
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,23 @@ Optionally displays a launchable set of favourites.
1313

1414
> Type: `launcher`
1515
16-
| | Type | Default | Description |
17-
|-----------------------------|---------------------------------------------|----------|--------------------------------------------------------------------------------------------------------------------------|
18-
| `favorites` | `string[]` | `[]` | List of app IDs (or classes) to always show at the start of the launcher. |
19-
| `show_names` | `boolean` | `false` | Whether to show app names on the button label. Names will still show on tooltips when set to false. |
20-
| `show_icons` | `boolean` | `true` | Whether to show app icons on the button. |
21-
| `icon_size` | `integer` | `32` | Size to render icon at (image icons only). |
22-
| `reversed` | `boolean` | `false` | Whether to reverse the order of favorites/items |
23-
| `minimize_focused` | `boolean` | `true` | Whether to minimize a focused window when its icon is clicked. Only minimizes single windows. |
24-
| `truncate.mode` | `'start'` or `'middle'` or `'end'` or `off` | `end` | The location of the ellipses and where to truncate text from. Applies to application names when `show_names` is enabled. |
25-
| `truncate.length` | `integer` | `null` | The fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. |
26-
| `truncate.max_length` | `integer` | `null` | The maximum number of characters before truncating. Leave blank to let GTK automatically handle. |
27-
| `truncate_popup.mode` | `'start'` or `'middle'` or `'end'` or `off` | `middle` | The location of the ellipses and where to truncate text from. Applies to window names within a group popup. |
28-
| `truncate_popup.length` | `integer` | `null` | The fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. |
29-
| `truncate_popup.max_length` | `integer` | `25` | The maximum number of characters before truncating. Leave blank to let GTK automatically handle. |
30-
31-
16+
| | Type | Default | Description |
17+
|-----------------------------|---------------------------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
18+
| `favorites` | `string[]` | `[]` | List of app IDs (or classes) to always show at the start of the launcher. |
19+
| `show_names` | `boolean` | `false` | Whether to show app names on the button label. Names will still show on tooltips when set to false. |
20+
| `show_icons` | `boolean` | `true` | Whether to show app icons on the button. |
21+
| `icon_size` | `integer` | `32` | Size to render icon at (image icons only). |
22+
| `reversed` | `boolean` | `false` | Whether to reverse the order of favorites/items |
23+
| `minimize_focused` | `boolean` | `true` | Whether to minimize a focused window when its icon is clicked. Only minimizes single windows. |
24+
| `truncate.mode` | `'start'` or `'middle'` or `'end'` or `off` | `end` | Location of the ellipses and where to truncate text from. Applies to application names when `show_names` is enabled. |
25+
| `truncate.length` | `integer` | `null` | Fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. |
26+
| `truncate.max_length` | `integer` | `null` | Maximum number of characters before truncating. Leave blank to let GTK automatically handle. |
27+
| `truncate_popup.mode` | `'start'` or `'middle'` or `'end'` or `off` | `middle` | Location of the ellipses and where to truncate text from. Applies to window names within a group popup. |
28+
| `truncate_popup.length` | `integer` | `null` | Fixed width (in chars) of the widget. Leave blank to let GTK automatically handle. |
29+
| `truncate_popup.max_length` | `integer` | `25` | Maximum number of characters before truncating. Leave blank to let GTK automatically handle. |
30+
| `page_size` | `integer` | `1000` | Number of items to show on a page. When the number of items is reached, controls appear which can be used to move forward/back through the list of items. |
31+
| `icons.page_back` | `string` or [image](images) | `󰅁` | Icon to show for page back button. |
32+
| `icons.page_forward` | `string` or [image](images) | `󰅂` | Icon to show for page forward button. |
3233
<details>
3334
<summary>JSON</summary>
3435

@@ -104,14 +105,17 @@ start:
104105

105106
## Styling
106107

107-
| Selector | Description |
108-
|-------------------------------|--------------------------|
109-
| `.launcher` | Launcher widget box |
110-
| `.launcher .item` | App button |
111-
| `.launcher .item.open` | App button (open app) |
112-
| `.launcher .item.focused` | App button (focused app) |
113-
| `.launcher .item.urgent` | App button (urgent app) |
114-
| `.popup-launcher` | Popup container |
115-
| `.popup-launcher .popup-item` | Window button in popup |
108+
| Selector | Description |
109+
|--------------------------------------|---------------------------|
110+
| `.launcher` | Launcher widget box |
111+
| `.launcher .item` | App button |
112+
| `.launcher .item.open` | App button (open app) |
113+
| `.launcher .item.focused` | App button (focused app) |
114+
| `.launcher .item.urgent` | App button (urgent app) |
115+
| `.launcher .pagination` | Pagination controls box |
116+
| `.launcher .pagination .btn-back` | Pagination back button |
117+
| `.launcher .pagination .btn-forward` | Pagination forward button |
118+
| `.popup-launcher` | Popup container |
119+
| `.popup-launcher .popup-item` | Window button in popup |
116120

117121
For more information on styling, please see the [styling guide](styling-guide).

src/modules/custom/label.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use serde::Deserialize;
44

55
use super::{CustomWidget, CustomWidgetContext};
66
use crate::build;
7-
use crate::config::{ModuleJustification, ModuleOrientation};
7+
use crate::config::{ModuleJustification, ModuleOrientation, TruncateMode};
88
use crate::dynamic_value::dynamic_string;
99
use crate::gtk_helpers::IronbarLabelExt;
1010

@@ -44,6 +44,11 @@ pub struct LabelWidget {
4444
/// **Default**: `left`
4545
#[serde(default)]
4646
justify: ModuleJustification,
47+
48+
/// See [truncate options](module-level-options#truncate-mode).
49+
///
50+
/// **Default**: `null`
51+
truncate: Option<TruncateMode>,
4752
}
4853

4954
impl CustomWidget for LabelWidget {
@@ -56,6 +61,10 @@ impl CustomWidget for LabelWidget {
5661
label.set_justify(self.justify.into());
5762
label.set_use_markup(true);
5863

64+
if let Some(truncate) = self.truncate {
65+
label.truncate(truncate);
66+
}
67+
5968
{
6069
let label = label.clone();
6170
dynamic_string(&self.label, move |string| {

src/modules/label.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::config::CommonConfig;
1+
use crate::config::{CommonConfig, TruncateMode};
22
use crate::dynamic_value::dynamic_string;
33
use crate::gtk_helpers::IronbarLabelExt;
44
use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext};
@@ -17,6 +17,12 @@ pub struct LabelModule {
1717
/// **Required**
1818
label: String,
1919

20+
// -- Common --
21+
/// See [truncate options](module-level-options#truncate-mode).
22+
///
23+
/// **Default**: `null`
24+
truncate: Option<TruncateMode>,
25+
2026
/// See [common options](module-level-options#common-options).
2127
#[serde(flatten)]
2228
pub common: Option<CommonConfig>,
@@ -26,6 +32,7 @@ impl LabelModule {
2632
pub(crate) fn new(label: String) -> Self {
2733
Self {
2834
label,
35+
truncate: None,
2936
common: Some(CommonConfig::default()),
3037
}
3138
}
@@ -58,6 +65,10 @@ impl Module<Label> for LabelModule {
5865
) -> Result<ModuleParts<Label>> {
5966
let label = Label::builder().use_markup(true).build();
6067

68+
if let Some(truncate) = self.truncate {
69+
label.truncate(truncate);
70+
}
71+
6172
{
6273
let label = label.clone();
6374
glib_recv!(context.subscribe(), string => label.set_label_escaped(&string));

0 commit comments

Comments
 (0)