#581: the Discord pill fits its label and field text sits on the field's middle

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QiAJeFttZp83Fh7YuzAR5f
This commit is contained in:
Claude
2026-10-10 19:16:03 +00:00
parent e4916e5ca9
commit bf5e6c6cec
3 changed files with 43 additions and 3 deletions
+26
View File
@@ -277,6 +277,8 @@ fn field(ui: &mut Ui, rect: Rect, text: &mut String, hint: &str, t: &Tokens, sea
.hint_text(hint)
.frame(egui::Frame::NONE)
.desired_width(inner.width())
// As tall as the field, so the text and the hint sit on its middle (they sat high, #581).
.min_size(inner.size())
.font(Tokens::ui(12.0))
.vertical_align(egui::Align::Center),
)
@@ -559,3 +561,27 @@ pub fn popup_is_open(ui: &Ui, id: egui::Id) -> bool {
pub fn open_popup(ui: &Ui, id: egui::Id) {
ui.data_mut(|d| d.insert_temp(id.with("open"), true));
}
#[cfg(test)]
mod tests {
use super::*;
/// #581: a field's text edit fills it, so its text and hint sit on the field's middle line
/// (it was a row at the top of the field, its text high).
#[test]
fn field_text_is_vertically_centred() {
let ctx = egui::Context::default();
let t = Tokens::for_kind(Default::default());
for h in [22.0, 26.0, 30.0] {
let field = Rect::from_min_size(pos2(20.0, 40.0), vec2(220.0, h));
let mut text = String::new();
let mut got = None;
let mut out = ctx.run_ui(Default::default(), |ui| {
got = Some(search_field(ui, field, &mut text, "Filter recent files", &t).rect);
});
out.textures_delta.clear();
let r = got.expect("the field was drawn");
assert!((r.center().y - field.center().y).abs() < 0.5 && r.height() >= h - 2.5, "{h}: {r:?} in {field:?}");
}
}
}