Skip to content

Commit 715a60c

Browse files
committed
Implemented theme icons.
Theme icons are icon widgets that are created with only their name as arguments. The global static `ICON_LOADER` then searches the currently used icon theme for an icon with that name. If an icon with that name exists with multiple sizes in the theme, the icon with the best size for the widget is chosen.
1 parent 4644658 commit 715a60c

7 files changed

Lines changed: 530 additions & 40 deletions

File tree

examples/todos.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use iced::{
22
button, scrollable, text_input, Align, Application, Button, Checkbox,
33
Color, Column, Command, Container, Element, Font, HorizontalAlignment,
4-
Length, Row, Scrollable, Settings, Text, TextInput,
4+
Icon, Length, Row, Scrollable, Settings, Text, TextInput,
55
};
66
use serde::{Deserialize, Serialize};
77

@@ -291,12 +291,9 @@ impl Task {
291291
.align_items(Align::Center)
292292
.push(checkbox)
293293
.push(
294-
Button::new(
295-
edit_button,
296-
edit_icon().color([0.5, 0.5, 0.5]),
297-
)
298-
.on_press(TaskMessage::Edit)
299-
.padding(10),
294+
Button::new(edit_button, edit_icon())
295+
.on_press(TaskMessage::Edit)
296+
.padding(10),
300297
)
301298
.into()
302299
}
@@ -320,14 +317,11 @@ impl Task {
320317
.push(
321318
Button::new(
322319
delete_button,
323-
Row::new()
324-
.spacing(10)
325-
.push(delete_icon().color(Color::WHITE))
326-
.push(
327-
Text::new("Delete")
328-
.width(Length::Shrink)
329-
.color(Color::WHITE),
330-
),
320+
Row::new().spacing(10).push(delete_icon()).push(
321+
Text::new("Delete")
322+
.width(Length::Shrink)
323+
.color(Color::WHITE),
324+
),
331325
)
332326
.on_press(TaskMessage::Delete)
333327
.padding(10)
@@ -471,12 +465,24 @@ fn icon(unicode: char) -> Text {
471465
.size(20)
472466
}
473467

474-
fn edit_icon() -> Text {
475-
icon('\u{F303}')
468+
fn edit_icon<'a, Message>() -> Element<'a, Message> {
469+
if Icon::theme_includes_icon("document-properties") {
470+
Icon::from_theme("document-properties")
471+
.size(Length::Units(32))
472+
.into()
473+
} else {
474+
icon('\u{F303}').color([0.5, 0.5, 0.5]).into()
475+
}
476476
}
477477

478-
fn delete_icon() -> Text {
479-
icon('\u{F1F8}')
478+
fn delete_icon<'a, Message>() -> Element<'a, Message> {
479+
if Icon::theme_includes_icon("edit-delete") {
480+
Icon::from_theme("edit-delete")
481+
.size(Length::Units(32))
482+
.into()
483+
} else {
484+
icon('\u{F1F8}').color(Color::WHITE).into()
485+
}
480486
}
481487

482488
// Persistence

native/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ iced_core = { version = "0.1.0", path = "../core", features = ["command"] }
1212
twox-hash = "1.5"
1313
raw-window-handle = "0.3"
1414
unicode-segmentation = "1.6"
15+
xdg = "2.2"
16+
rust-ini = "0.13"
17+
lazy_static = "1.4"

native/src/icon_loader.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//! A collection of structs to handle themed icons.
2+
3+
mod icon_loader;
4+
5+
pub use icon_loader::*;

0 commit comments

Comments
 (0)