Skip to content

Commit e283882

Browse files
committed
Fix vote % text
1 parent a2fe267 commit e283882

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

game/client-ui/src/vote/main_frame.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,24 @@ pub fn render(ui: &mut egui::Ui, pipe: &mut UiRenderPipe<UserData>, ui_state: &m
116116
},
117117
Color32::RED,
118118
);
119-
at.x -= no_size / 2.0 - 5.0;
120-
ui.painter().text(
121-
at,
122-
egui::Align2::LEFT_CENTER,
119+
at = rect.left_center();
120+
let galley = ui.painter().layout_no_wrap(
123121
format!("{:.1}%", no_perc * 100.0),
124122
FontId::default(),
125123
Color32::WHITE,
126124
);
125+
let size = galley.size();
126+
ui.painter().galley(
127+
if size.x + 10.0 < rect.width() {
128+
at + egui::vec2(5.0, -size.y / 2.0)
129+
} else {
130+
rect.right_center()
131+
- egui::vec2(size.x, size.y / 2.0)
132+
- egui::vec2(5.0, 0.0)
133+
},
134+
galley,
135+
Color32::WHITE,
136+
);
127137
}
128138

129139
if yes_perc > 0.0 {
@@ -142,13 +152,21 @@ pub fn render(ui: &mut egui::Ui, pipe: &mut UiRenderPipe<UserData>, ui_state: &m
142152
},
143153
Color32::GREEN,
144154
);
145-
at.x += yes_size / 2.0 - 5.0;
146-
ui.painter().text(
147-
at,
148-
egui::Align2::RIGHT_CENTER,
155+
at = rect.right_center();
156+
let galley = ui.painter().layout_no_wrap(
149157
format!("{:.1}%", yes_perc * 100.0),
150158
FontId::default(),
151-
Color32::BLACK,
159+
Color32::DARK_GRAY,
160+
);
161+
let size = galley.size();
162+
ui.painter().galley(
163+
if size.x + 10.0 < rect.width() {
164+
at - egui::vec2(size.x, size.y / 2.0) - egui::vec2(5.0, 0.0)
165+
} else {
166+
rect.left_center() + egui::vec2(5.0, -size.y / 2.0)
167+
},
168+
galley,
169+
Color32::DARK_GRAY,
152170
);
153171
}
154172

0 commit comments

Comments
 (0)