Skip to content

Commit 271c979

Browse files
pauldeluciaogabrielidescoderabbitai[bot]
authored
feat: highlight button for active dpns subscreen (#51)
* feat: highlight button for active dpns subscreen * suggestion Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * remove unused import --------- Co-authored-by: Odysseas Gabrielides <odysseas.gabrielides@gmail.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent f5c37d4 commit 271c979

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/ui/components/dpns_subscreen_chooser_panel.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
use crate::context::AppContext;
12
use crate::ui::dpns_contested_names_screen::DPNSSubscreen;
2-
use crate::{app::AppAction, ui::RootScreenType};
3-
use egui::{Context, Frame, Margin, SidePanel};
3+
use crate::ui::RootScreenType;
4+
use crate::{app::AppAction, ui};
5+
use egui::{Color32, Context, Frame, Margin, RichText, SidePanel};
46

5-
pub fn add_dpns_subscreen_chooser_panel(ctx: &Context) -> AppAction {
7+
pub fn add_dpns_subscreen_chooser_panel(ctx: &Context, app_context: &AppContext) -> AppAction {
68
let mut action = AppAction::None;
79

810
let subscreens = vec![
@@ -11,6 +13,16 @@ pub fn add_dpns_subscreen_chooser_panel(ctx: &Context) -> AppAction {
1113
DPNSSubscreen::Owned,
1214
];
1315

16+
let active_screen = match app_context.get_settings() {
17+
Ok(Some(settings)) => match settings.1 {
18+
ui::RootScreenType::RootScreenDPNSActiveContests => DPNSSubscreen::Active,
19+
ui::RootScreenType::RootScreenDPNSPastContests => DPNSSubscreen::Past,
20+
ui::RootScreenType::RootScreenDPNSOwnedNames => DPNSSubscreen::Owned,
21+
_ => DPNSSubscreen::Active,
22+
},
23+
_ => DPNSSubscreen::Active, // Fallback to Active screen if settings unavailable
24+
};
25+
1426
SidePanel::left("dpns_subscreen_chooser_panel")
1527
.default_width(250.0)
1628
.frame(
@@ -25,8 +37,18 @@ pub fn add_dpns_subscreen_chooser_panel(ctx: &Context) -> AppAction {
2537
ui.add_space(10.0);
2638

2739
for subscreen in subscreens {
40+
let is_active = active_screen == subscreen;
41+
let (button_color, text_color) = if is_active {
42+
(Color32::from_rgb(0, 128, 255), Color32::WHITE)
43+
} else {
44+
(Color32::GRAY, Color32::WHITE)
45+
};
46+
let button = egui::Button::new(
47+
RichText::new(subscreen.display_name()).color(text_color),
48+
)
49+
.fill(button_color);
2850
// Show the subscreen name as a clickable option
29-
if ui.button(subscreen.display_name()).clicked() {
51+
if ui.add(button).clicked() {
3052
// Handle navigation based on which subscreen is selected
3153
match subscreen {
3254
DPNSSubscreen::Active => {

src/ui/dpns_contested_names_screen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ impl ScreenLike for DPNSContestedNamesScreen {
820820
);
821821
}
822822
}
823-
action |= add_dpns_subscreen_chooser_panel(ctx);
823+
action |= add_dpns_subscreen_chooser_panel(ctx, self.app_context.as_ref());
824824

825825
// Render the UI with the cloned contested_names vector
826826
egui::CentralPanel::default().show(ctx, |ui| {

0 commit comments

Comments
 (0)