Skip to content

Commit 561edcc

Browse files
Buckminsterfullerene02trumank
authored andcommitted
Red delete button with trashcan text
1 parent d5fdbc6 commit 561edcc

File tree

2 files changed

+47
-19
lines changed

2 files changed

+47
-19
lines changed

src/gui/mod.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::{
1515
};
1616

1717
use anyhow::{anyhow, Context, Result};
18-
use eframe::egui::{CollapsingHeader, RichText};
18+
use eframe::egui::{Button, CollapsingHeader, RichText};
1919
use eframe::epaint::{Pos2, Vec2};
2020
use eframe::{
2121
egui::{self, FontSelection, Layout, TextFormat, Ui},
@@ -60,6 +60,16 @@ pub fn gui(args: Option<Vec<String>>) -> Result<()> {
6060
Ok(())
6161
}
6262

63+
pub mod colors {
64+
use eframe::epaint::Color32;
65+
66+
pub const DARK_RED: Color32 = Color32::DARK_RED;
67+
pub const DARKER_RED: Color32 = Color32::from_rgb(110, 0, 0);
68+
69+
pub const DARK_GREEN: Color32 = Color32::DARK_GREEN;
70+
pub const DARKER_GREEN: Color32 = Color32::from_rgb(0, 80, 0);
71+
}
72+
6373
const MODIO_LOGO_PNG: &[u8] = include_bytes!("../../assets/modio-cog-blue.png");
6474

6575
pub struct App {
@@ -350,7 +360,7 @@ impl App {
350360

351361
if ui
352362
.add(toggle_switch(&mut mc.enabled))
353-
.on_hover_text_at_pointer("enabled?")
363+
.on_hover_text_at_pointer("Enabled?")
354364
.changed()
355365
{
356366
ctx.needs_save = true;
@@ -540,9 +550,17 @@ impl App {
540550

541551
let mut ui_item =
542552
|ctx: &mut Ctx, ui: &mut Ui, mc: &mut ModOrGroup, state: egui_dnd::ItemState| {
543-
if ui.button(" ➖ ").clicked() {
544-
ctx.btn_remove = Some(state.index);
545-
}
553+
ui.scope(|ui| {
554+
ui.visuals_mut().widgets.hovered.weak_bg_fill = colors::DARK_RED;
555+
ui.visuals_mut().widgets.active.weak_bg_fill = colors::DARKER_RED;
556+
if ui
557+
.add(Button::new(" 🗑 "))
558+
.on_hover_text_at_pointer("Delete mod")
559+
.clicked()
560+
{
561+
ctx.btn_remove = Some(state.index);
562+
};
563+
});
546564

547565
match mc {
548566
ModOrGroup::Individual(mc) => {
@@ -554,7 +572,7 @@ impl App {
554572
} => {
555573
if ui
556574
.add(toggle_switch(enabled))
557-
.on_hover_text_at_pointer("enabled?")
575+
.on_hover_text_at_pointer("Enabled?")
558576
.changed()
559577
{
560578
ctx.needs_save = true;
@@ -597,7 +615,7 @@ impl App {
597615
frame.show(ui, |ui| {
598616
ui.horizontal(|ui| {
599617
handle.ui(ui, |ui| {
600-
ui.label("");
618+
ui.label("");
601619
});
602620

603621
ui_item(&mut ctx, ui, item, state);

src/gui/named_combobox.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std;
22

3-
use super::{custom_popup_above_or_below_widget, is_committed};
3+
use super::{colors, custom_popup_above_or_below_widget, is_committed};
44

55
use eframe::egui;
66

@@ -84,8 +84,8 @@ where
8484
let mut modified = false;
8585
ui.push_id(name, |ui| {
8686
ui.horizontal(|ui| {
87-
mk_delete(ui, name, entries, &mut modified);
8887
mk_add(ui, name, entries, &mut modified);
88+
mk_delete(ui, name, entries, &mut modified);
8989
mk_rename(ui, name, entries, &mut modified);
9090

9191
ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
@@ -109,14 +109,18 @@ where
109109
N: NamedEntries<E>,
110110
{
111111
ui.add_enabled_ui(entries.len() > 1, |ui| {
112-
if ui
113-
.button(" ➖ ")
114-
.on_hover_text_at_pointer(format!("Delete {name}"))
115-
.clicked()
116-
{
117-
entries.remove_selected();
118-
*modified = true;
119-
}
112+
ui.scope(|ui| {
113+
ui.visuals_mut().widgets.hovered.weak_bg_fill = colors::DARK_RED;
114+
ui.visuals_mut().widgets.active.weak_bg_fill = colors::DARKER_RED;
115+
if ui
116+
.button(" 🗑 ")
117+
.on_hover_text_at_pointer(format!("Delete {name}"))
118+
.clicked()
119+
{
120+
entries.remove_selected();
121+
*modified = true;
122+
}
123+
});
120124
});
121125
}
122126

@@ -126,8 +130,14 @@ where
126130
{
127131
ui.add_enabled_ui(true, |ui| {
128132
let response = ui
129-
.button(" ➕ ")
130-
.on_hover_text_at_pointer(format!("Add new {name}"));
133+
.scope(|ui| {
134+
ui.visuals_mut().widgets.hovered.weak_bg_fill = colors::DARK_GREEN;
135+
ui.visuals_mut().widgets.active.weak_bg_fill = colors::DARKER_GREEN;
136+
ui.button(" ➕ ")
137+
.on_hover_text_at_pointer(format!("Add new {name}"))
138+
})
139+
.inner;
140+
131141
let popup_id = ui.make_persistent_id(format!("add-{name}"));
132142
if response.clicked() {
133143
ui.memory_mut(|mem| mem.open_popup(popup_id));

0 commit comments

Comments
 (0)