Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/gallery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl Gallery {
} else {
icons::ph::MOON
};
if c::icon_button(ui, t, glyph, 32.0).clicked() {
if c::icon_button(ui, t, glyph, 32.0, t.text_2).clicked() {
self.dark = !self.dark;
}
});
Expand All @@ -142,8 +142,8 @@ impl Gallery {
ui.add_space(8.0);
c::text_button(ui, t, c::ButtonKind::Secondary, "Secondary", 34.0);
ui.add_space(12.0);
c::icon_button(ui, t, icons::ph::GEAR_SIX, 34.0);
c::icon_button(ui, t, icons::ph::TRASH, 34.0);
c::icon_button(ui, t, icons::ph::GEAR_SIX, 34.0, t.text_2);
c::icon_button(ui, t, icons::ph::TRASH, 34.0, t.accent);
ui.add_space(12.0);
c::link(ui, t, "A text link");
});
Expand Down
13 changes: 7 additions & 6 deletions src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ pub fn new_tile(

/// A square, frameless icon button. `glyph` is a [`icons::ph`] constant.
///
/// `side` is the button's width and height. Hover eases a soft background in.
pub fn icon_button(ui: &mut Ui, t: &Tokens, glyph: &str, side: f32) -> Response {
/// `side` is the button's width and height; `ink` is the glyph's rest colour
/// (pass `t.text_2` for a muted button, `t.text` or `t.accent` for a
/// prominent one). Hover eases a soft background in and brightens the glyph.
pub fn icon_button(ui: &mut Ui, t: &Tokens, glyph: &str, side: f32, ink: Color32) -> Response {
let (rect, response) = ui.allocate_exact_size(Vec2::splat(side), Sense::click());
let hv = hover_t(ui, response.id, response.hovered());
if hv > 0.001 {
Expand All @@ -134,13 +136,12 @@ pub fn icon_button(ui: &mut Ui, t: &Tokens, glyph: &str, side: f32) -> Response
Stroke::new(1.0, t.border.gamma_multiply(hv)),
);
}
let ink = lerp_color(t.text_2, t.text, hv);
ui.painter().text(
rect.center(),
egui::Align2::CENTER_CENTER,
glyph,
icons::font(side * 0.5),
ink,
lerp_color(ink, Color32::WHITE, 0.3 * hv),
);
response
}
Expand Down Expand Up @@ -244,7 +245,7 @@ pub fn menu_button(
side: f32,
add_items: impl FnOnce(&mut Ui),
) -> Response {
let trigger = icon_button(ui, t, glyph, side);
let trigger = icon_button(ui, t, glyph, side, t.text_2);
let popup_id = egui::Id::new(id_source);
if trigger.clicked() {
ui.memory_mut(|m| m.toggle_popup(popup_id));
Expand Down Expand Up @@ -530,7 +531,7 @@ pub fn modal(
.color(t.text),
);
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
if icon_button(ui, t, icons::ph::X, 26.0).clicked() {
if icon_button(ui, t, icons::ph::X, 26.0, t.text_2).clicked() {
*open = false;
}
});
Expand Down
Loading