Skip to content

Commit 4f66fad

Browse files
lklimekclaude
andcommitted
fix(ui): center text in direct Button::new(...).min_size(...) callsites
Companion to the ComponentStyles helper fix. These callsites bypass the helpers and construct egui::Button directly with .min_size(...), then dispatch via ui.add(...) or ui.add_enabled(...) — same left-shift bug. Swap each to ui.add_sized(size, button) (preserving enabled/disabled behavior where applicable). Covers send screens, tokens toolbar, tab switchers, nav-panel chooser buttons, and the StyledButton/GradientButton helpers. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 8428fb3 commit 4f66fad

17 files changed

Lines changed: 156 additions & 106 deletions

src/ui/components/dashpay_subscreen_chooser_panel.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ pub fn add_dashpay_subscreen_chooser_panel(
7070
.fill(DashColors::DASH_BLUE)
7171
.stroke(egui::Stroke::NONE)
7272
.corner_radius(egui::CornerRadius::same(Shape::RADIUS_MD))
73-
.min_size(egui::Vec2::new(150.0, 28.0))
7473
} else {
7574
egui::Button::new(
7675
RichText::new(display_name)
@@ -80,11 +79,10 @@ pub fn add_dashpay_subscreen_chooser_panel(
8079
.fill(DashColors::glass_white(dark_mode))
8180
.stroke(egui::Stroke::new(1.0, DashColors::border(dark_mode)))
8281
.corner_radius(egui::CornerRadius::same(Shape::RADIUS_MD))
83-
.min_size(egui::Vec2::new(150.0, 28.0))
8482
};
8583

8684
// Show the subscreen name as a clickable option
87-
if ui.add(button).clicked() {
85+
if ui.add_sized(egui::Vec2::new(150.0, 28.0), button).clicked() {
8886
// Handle navigation based on which subscreen is selected
8987
match subscreen {
9088
DashPaySubscreen::Contacts => {

src/ui/components/dpns_subscreen_chooser_panel.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ pub fn add_dpns_subscreen_chooser_panel(ctx: &Context, app_context: &AppContext)
6161
.fill(DashColors::DASH_BLUE)
6262
.stroke(egui::Stroke::NONE)
6363
.corner_radius(egui::CornerRadius::same(Shape::RADIUS_MD))
64-
.min_size(egui::Vec2::new(150.0, 28.0))
6564
} else {
6665
egui::Button::new(
6766
RichText::new(subscreen.display_name())
@@ -71,11 +70,10 @@ pub fn add_dpns_subscreen_chooser_panel(ctx: &Context, app_context: &AppContext)
7170
.fill(DashColors::glass_white(dark_mode))
7271
.stroke(egui::Stroke::new(1.0, DashColors::border(dark_mode)))
7372
.corner_radius(egui::CornerRadius::same(Shape::RADIUS_MD))
74-
.min_size(egui::Vec2::new(150.0, 28.0))
7573
};
7674

7775
// Show the subscreen name as a clickable option
78-
if ui.add(button).clicked() {
76+
if ui.add_sized(egui::Vec2::new(150.0, 28.0), button).clicked() {
7977
// Handle navigation based on which subscreen is selected
8078
match subscreen {
8179
DPNSSubscreen::Active => {

src/ui/components/styled.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,18 @@ impl StyledButton {
111111
button = button.stroke(stroke);
112112
}
113113

114-
if let Some(min_width) = self.min_width {
115-
button = button.min_size(Vec2::new(min_width, 0.0));
116-
}
117-
118-
let response = ui.add_enabled(self.enabled, button);
114+
// When a caller requested a minimum width, use `add_sized` so the button's
115+
// `AtomLayout` inherits `horizontal_align = Center` from a
116+
// `centered_and_justified` inner layout. Otherwise plain `add` preserves
117+
// content-sized behaviour.
118+
let response = if let Some(min_width) = self.min_width {
119+
ui.add_enabled_ui(self.enabled, |ui| {
120+
ui.add_sized(Vec2::new(min_width, 0.0), button)
121+
})
122+
.inner
123+
} else {
124+
ui.add_enabled(self.enabled, button)
125+
};
119126

120127
if response.hovered() && self.enabled {
121128
ui.ctx().set_cursor_icon(egui::CursorIcon::PointingHand);
@@ -253,7 +260,7 @@ impl GradientButton {
253260
let time = ui.ctx().input(|i| i.time as f32);
254261
let animated_color = DashColors::gradient_animated(time);
255262

256-
let mut button = Button::new(
263+
let button = Button::new(
257264
RichText::new(self.text)
258265
.color(DashColors::WHITE)
259266
.size(Typography::SCALE_BASE),
@@ -262,11 +269,13 @@ impl GradientButton {
262269
.stroke(Stroke::NONE)
263270
.corner_radius(egui::CornerRadius::same(Shape::RADIUS_MD));
264271

265-
if let Some(width) = self.min_width {
266-
button = button.min_size(Vec2::new(width, 36.0));
267-
}
268-
269-
let response = ui.add(button);
272+
// See `StyledButton::show` for why `add_sized` is used when `min_width`
273+
// is set: it keeps text centered inside the button rect.
274+
let response = if let Some(width) = self.min_width {
275+
ui.add_sized(Vec2::new(width, 36.0), button)
276+
} else {
277+
ui.add(button)
278+
};
270279

271280
// Request repaint for animation
272281
self.app_context.repaint_animation(ui.ctx());

src/ui/components/tokens_subscreen_chooser_panel.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ pub fn add_tokens_subscreen_chooser_panel(ctx: &Context, app_context: &AppContex
6060
.fill(DashColors::DASH_BLUE)
6161
.stroke(egui::Stroke::NONE)
6262
.corner_radius(egui::CornerRadius::same(Shape::RADIUS_MD))
63-
.min_size(egui::Vec2::new(150.0, 28.0))
6463
} else {
6564
egui::Button::new(
6665
RichText::new(subscreen.display_name())
@@ -70,11 +69,10 @@ pub fn add_tokens_subscreen_chooser_panel(ctx: &Context, app_context: &AppContex
7069
.fill(DashColors::glass_white(dark_mode))
7170
.stroke(egui::Stroke::new(1.0, DashColors::border(dark_mode)))
7271
.corner_radius(egui::CornerRadius::same(Shape::RADIUS_MD))
73-
.min_size(egui::Vec2::new(150.0, 28.0))
7472
};
7573

7674
// Show the subscreen name as a clickable option
77-
if ui.add(button).clicked() {
75+
if ui.add_sized(egui::Vec2::new(150.0, 28.0), button).clicked() {
7876
// Handle navigation based on which subscreen is selected
7977
match subscreen {
8078
TokensSubscreen::MyTokens => {

src/ui/components/tools_subscreen_chooser_panel.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ pub fn add_tools_subscreen_chooser_panel(ctx: &Context, app_context: &AppContext
128128
.fill(DashColors::DASH_BLUE)
129129
.stroke(egui::Stroke::NONE)
130130
.corner_radius(egui::CornerRadius::same(Shape::RADIUS_MD))
131-
.min_size(egui::Vec2::new(150.0, 28.0))
132131
} else {
133132
egui::Button::new(
134133
RichText::new(subscreen.display_name())
@@ -138,13 +137,16 @@ pub fn add_tools_subscreen_chooser_panel(ctx: &Context, app_context: &AppContext
138137
.fill(DashColors::glass_white(dark_mode))
139138
.stroke(egui::Stroke::new(1.0, DashColors::border(dark_mode)))
140139
.corner_radius(egui::CornerRadius::same(Shape::RADIUS_MD))
141-
.min_size(egui::Vec2::new(150.0, 28.0))
142140
};
143141

144142
// Show the subscreen name as a clickable option. Disable
145143
// tools that require a Core RPC connection while running
146144
// on the built-in SPV backend.
147-
let mut response = ui.add_enabled(is_enabled, button);
145+
let mut response = ui
146+
.add_enabled_ui(is_enabled, |ui| {
147+
ui.add_sized(egui::Vec2::new(150.0, 28.0), button)
148+
})
149+
.inner;
148150
if !is_enabled {
149151
response = response.on_disabled_hover_text(
150152
"This tool requires a local Dash Core node. Open Settings, switch to Expert mode, and select Local Dash Core node to enable it.",

src/ui/dashpay/contact_requests.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -667,10 +667,12 @@ impl ContactRequests {
667667
} else {
668668
egui::Stroke::new(1.0, DashColors::border(dark_mode))
669669
})
670-
.corner_radius(egui::CornerRadius::same(4))
671-
.min_size(egui::Vec2::new(120.0, 28.0));
670+
.corner_radius(egui::CornerRadius::same(4));
672671

673-
if ui.add(incoming_tab).clicked() {
672+
if ui
673+
.add_sized(egui::Vec2::new(120.0, 28.0), incoming_tab)
674+
.clicked()
675+
{
674676
self.active_tab = RequestTab::Incoming;
675677
}
676678

@@ -693,10 +695,12 @@ impl ContactRequests {
693695
} else {
694696
egui::Stroke::new(1.0, DashColors::border(dark_mode))
695697
})
696-
.corner_radius(egui::CornerRadius::same(4))
697-
.min_size(egui::Vec2::new(120.0, 28.0));
698+
.corner_radius(egui::CornerRadius::same(4));
698699

699-
if ui.add(outgoing_tab).clicked() {
700+
if ui
701+
.add_sized(egui::Vec2::new(120.0, 28.0), outgoing_tab)
702+
.clicked()
703+
{
700704
self.active_tab = RequestTab::Outgoing;
701705
}
702706
});

src/ui/dashpay/contacts_list.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,12 @@ impl ContactsList {
358358
} else {
359359
egui::Stroke::new(1.0, DashColors::border(dark_mode))
360360
})
361-
.corner_radius(egui::CornerRadius::same(4))
362-
.min_size(egui::Vec2::new(120.0, 28.0));
361+
.corner_radius(egui::CornerRadius::same(4));
363362

364-
if ui.add(contacts_tab).clicked() {
363+
if ui
364+
.add_sized(egui::Vec2::new(120.0, 28.0), contacts_tab)
365+
.clicked()
366+
{
365367
self.active_tab = ContactsTab::Contacts;
366368
}
367369

@@ -392,10 +394,12 @@ impl ContactsList {
392394
} else {
393395
egui::Stroke::new(1.0, DashColors::border(dark_mode))
394396
})
395-
.corner_radius(egui::CornerRadius::same(4))
396-
.min_size(egui::Vec2::new(120.0, 28.0));
397+
.corner_radius(egui::CornerRadius::same(4));
397398

398-
if ui.add(requests_tab).clicked() {
399+
if ui
400+
.add_sized(egui::Vec2::new(120.0, 28.0), requests_tab)
401+
.clicked()
402+
{
399403
self.active_tab = ContactsTab::Requests;
400404
}
401405
});

src/ui/dashpay/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,9 @@ pub fn render_no_identities_card(ui: &mut Ui, app_context: &Arc<AppContext>) ->
9999
.color(egui::Color32::WHITE)
100100
.strong(),
101101
)
102-
.fill(DashColors::DASH_BLUE)
103-
.min_size(egui::vec2(150.0, 36.0));
102+
.fill(DashColors::DASH_BLUE);
104103

105-
if ui.add(button).clicked() {
104+
if ui.add_sized(egui::vec2(150.0, 36.0), button).clicked() {
106105
return AppAction::AddScreen(
107106
ScreenType::AddExistingIdentity.create_screen(app_context),
108107
);

src/ui/identities/top_up_identity_screen/by_platform_address.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,15 @@ impl TopUpIdentityScreen {
192192
DashColors::DASH_BLUE
193193
} else {
194194
DashColors::DASH_BLUE.gamma_multiply(0.5)
195-
})
196-
.min_size(egui::vec2(120.0, 36.0));
195+
});
197196

198-
if ui.add_enabled(can_top_up, button).clicked() {
197+
if ui
198+
.add_enabled_ui(can_top_up, |ui| {
199+
ui.add_sized(egui::vec2(120.0, 36.0), button)
200+
})
201+
.inner
202+
.clicked()
203+
{
199204
match self.validate_and_top_up_from_platform() {
200205
Ok(top_up_action) => {
201206
action = top_up_action;

src/ui/identities/transfer_screen.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,12 @@ impl TransferScreen {
211211
selected_fill
212212
} else {
213213
unselected_fill
214-
})
215-
.min_size(egui::vec2(120.0, 28.0));
214+
});
216215

217-
if ui.add(identity_button).clicked() {
216+
if ui
217+
.add_sized(egui::vec2(120.0, 28.0), identity_button)
218+
.clicked()
219+
{
218220
self.destination_type = TransferDestinationType::Identity;
219221
}
220222

@@ -236,10 +238,12 @@ impl TransferScreen {
236238
selected_fill
237239
} else {
238240
unselected_fill
239-
})
240-
.min_size(egui::vec2(140.0, 28.0));
241+
});
241242

242-
if ui.add(platform_button).clicked() {
243+
if ui
244+
.add_sized(egui::vec2(140.0, 28.0), platform_button)
245+
.clicked()
246+
{
243247
self.destination_type = TransferDestinationType::PlatformAddress;
244248
}
245249
});

0 commit comments

Comments
 (0)