[layout] remove ui.horizontal_centered and make centering the default

This commit is contained in:
Emil Ernerfeldt 2020-09-18 23:41:02 +02:00
parent 4df8def9e2
commit 283b4ab63d
9 changed files with 23 additions and 30 deletions

View file

@ -601,7 +601,7 @@ fn show_title_bar(
collapsing: &mut collapsing_header::State,
collapsible: bool,
) -> TitleBar {
let title_bar_and_rect = ui.horizontal_centered(|ui| {
let title_bar_and_rect = ui.horizontal(|ui| {
ui.set_desired_height(title_label.font_height(ui.fonts(), ui.style()));
let item_spacing = ui.style().spacing.item_spacing;

View file

@ -59,7 +59,7 @@ impl ColorTest {
let tex_color = Rgba::new(1.0, 0.25, 0.25, 1.0);
let vertex_color = Rgba::new(0.5, 0.75, 0.75, 1.0);
ui.horizontal_centered(|ui| {
ui.horizontal(|ui| {
let color_size = ui.style().spacing.interact_size;
ui.label("texture");
show_color(ui, tex_color, color_size);
@ -72,7 +72,7 @@ impl ColorTest {
self.vertex_gradient(ui, "Ground truth (vertices)", WHITE, &g);
self.tex_gradient(ui, tex_loader, "Ground truth (texture)", WHITE, &g);
}
ui.horizontal_centered(|ui| {
ui.horizontal(|ui| {
let g = Gradient::one_color(Srgba::from(tex_color));
let tex = self.tex_mngr.get(tex_loader, &g);
let texel_offset = 0.5 / (g.0.len() as f32);
@ -132,7 +132,7 @@ impl ColorTest {
) {
let is_opaque = left.is_opaque() && right.is_opaque();
ui.horizontal_centered(|ui| {
ui.horizontal(|ui| {
let color_size = ui.style().spacing.interact_size;
if !is_opaque {
ui.label("Background:");
@ -228,7 +228,7 @@ impl ColorTest {
if !self.texture_gradients {
return;
}
ui.horizontal_centered(|ui| {
ui.horizontal(|ui| {
let tex = self.tex_mngr.get(tex_loader, gradient);
let texel_offset = 0.5 / (gradient.0.len() as f32);
let uv = Rect::from_min_max(pos2(texel_offset, 0.0), pos2(1.0 - texel_offset, 1.0));
@ -245,7 +245,7 @@ impl ColorTest {
if !self.vertex_gradients {
return;
}
ui.horizontal_centered(|ui| {
ui.horizontal(|ui| {
vertex_gradient(ui, bg_fill, gradient).tooltip_text(format!(
"A triangle mesh that is {} vertices wide",
gradient.0.len()

View file

@ -181,7 +181,7 @@ impl ColorWidgets {
rgba_premul,
} = self;
ui.horizontal_centered(|ui| {
ui.horizontal(|ui| {
ui.color_edit_button_srgba_unmultiplied(srgba_unmul);
ui.label(format!(
"sRGBA: {} {} {} {}",
@ -189,7 +189,7 @@ impl ColorWidgets {
));
});
ui.horizontal_centered(|ui| {
ui.horizontal(|ui| {
ui.color_edit_button_srgba_premultiplied(srgba_premul);
ui.label(format!(
"sRGBA with premultiplied alpha: {} {} {} {}",
@ -197,7 +197,7 @@ impl ColorWidgets {
));
});
ui.horizontal_centered(|ui| {
ui.horizontal(|ui| {
ui.color_edit_button_rgba_unmultiplied(rgba_unmul);
ui.label(format!(
"Linear RGBA: {:.02} {:.02} {:.02} {:.02}",
@ -205,7 +205,7 @@ impl ColorWidgets {
));
});
ui.horizontal_centered(|ui| {
ui.horizontal(|ui| {
ui.color_edit_button_rgba_premultiplied(rgba_premul);
ui.label(format!(
"Linear RGBA with premultiplied alpha: {:.02} {:.02} {:.02} {:.02}",

View file

@ -73,7 +73,7 @@ pub fn toggle(ui: &mut Ui, on: &mut bool) -> Response {
pub fn demo(ui: &mut Ui, on: &mut bool) {
ui.label("It's easy to create your own widgets!");
let url = format!("https://github.com/emilk/egui/blob/master/{}", file!());
ui.horizontal_centered(|ui| {
ui.horizontal(|ui| {
ui.label("Like this toggle switch:");
toggle(ui, on).tooltip_text("Click to toggle");
ui.add(Hyperlink::new(url).text("(source code)"));

View file

@ -55,7 +55,7 @@ impl Widgets {
ui.add(Checkbox::new(&mut self.button_enabled, "Button enabled"));
ui.horizontal_centered(|ui| {
ui.horizontal(|ui| {
if ui
.add(Button::new("Click me").enabled(self.button_enabled))
.tooltip_text("This will just increase a counter.")
@ -85,7 +85,7 @@ impl Widgets {
ui.separator();
{
ui.label("An angle stored as radians, but edited in degrees:");
ui.horizontal_centered(|ui| {
ui.horizontal(|ui| {
ui.style_mut().spacing.item_spacing.x = 0.0;
ui.drag_angle(&mut self.angle);
ui.label(format!(" = {} radians", self.angle));
@ -93,7 +93,7 @@ impl Widgets {
}
ui.separator();
ui.horizontal_centered(|ui| {
ui.horizontal(|ui| {
ui.add(Label::new("Click to select a different text color: ").text_color(self.color));
ui.color_edit_button_srgba(&mut self.color);
});

View file

@ -58,7 +58,7 @@ impl BarState {
}
pub fn bar<R>(ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> (R, Rect) {
ui.horizontal_centered(|ui| {
ui.horizontal(|ui| {
Frame::menu_bar(ui.style()).show(ui, |ui| {
let mut style = ui.style().clone();
style.spacing.button_padding = vec2(2.0, 0.0);

View file

@ -295,7 +295,7 @@ impl Style {
visuals,
animation_time,
} = self;
ui.horizontal_centered(|ui| {
ui.horizontal(|ui| {
ui.label("Default text style:");
for &value in &[TextStyle::Body, TextStyle::Monospace] {
ui.radio_value(format!("{:?}", value), body_text_style, value);
@ -435,7 +435,7 @@ impl Visuals {
impl Stroke {
pub fn ui(&mut self, ui: &mut crate::Ui, text: &str) {
let Self { width, color } = self;
ui.horizontal_centered(|ui| {
ui.horizontal(|ui| {
ui.label(format!("{}: ", text));
ui.add(DragValue::f32(width).speed(0.1).range(0.0..=5.0))
.tooltip_text("Width");
@ -451,7 +451,7 @@ fn ui_slider_vec2(
range: std::ops::RangeInclusive<f32>,
text: &str,
) -> Response {
let (_, rect) = ui.horizontal_centered(|ui| {
let (_, rect) = ui.horizontal(|ui| {
ui.label(format!("{}: ", text));
ui.add(Slider::f32(&mut value.x, range.clone()).text("w"));
ui.add(Slider::f32(&mut value.y, range.clone()).text("h"));
@ -460,7 +460,7 @@ fn ui_slider_vec2(
}
fn ui_color(ui: &mut Ui, srgba: &mut Srgba, text: &str) {
ui.horizontal_centered(|ui| {
ui.horizontal(|ui| {
ui.label(format!("{}: ", text));
ui.color_edit_button_srgba(srgba);
});

View file

@ -656,17 +656,10 @@ impl Ui {
))
}
/// Start a ui with horizontal layout
/// Start a ui with horizontal layout.
/// Elements will be centered on the Y axis.
/// Initial height is `style.spacing.interact_size.y`.
pub fn horizontal<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> (R, Rect) {
let initial_size = vec2(
self.available().width(),
self.style().spacing.interact_size.y,
);
self.inner_layout(Layout::horizontal(Align::Min), initial_size, add_contents)
}
/// Start a ui with horizontal layout where elements are centered on the Y axis.
pub fn horizontal_centered<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> (R, Rect) {
let initial_size = vec2(
self.available().width(),
self.style().spacing.interact_size.y,

View file

@ -277,7 +277,7 @@ impl<'a> Widget for Slider<'a> {
if let Some(text) = &self.text {
self.id = self.id.or_else(|| Some(ui.make_unique_child_id(text)));
ui.horizontal_centered(|ui| {
ui.horizontal(|ui| {
let slider_response = self.allocate_slide_space(ui, height);
self.slider_ui(ui, &slider_response);
let x_range = x_range(&slider_response.rect);