[layout] remove ui.horizontal_centered and make centering the default
This commit is contained in:
parent
4df8def9e2
commit
283b4ab63d
9 changed files with 23 additions and 30 deletions
|
@ -601,7 +601,7 @@ fn show_title_bar(
|
||||||
collapsing: &mut collapsing_header::State,
|
collapsing: &mut collapsing_header::State,
|
||||||
collapsible: bool,
|
collapsible: bool,
|
||||||
) -> TitleBar {
|
) -> 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()));
|
ui.set_desired_height(title_label.font_height(ui.fonts(), ui.style()));
|
||||||
|
|
||||||
let item_spacing = ui.style().spacing.item_spacing;
|
let item_spacing = ui.style().spacing.item_spacing;
|
||||||
|
|
|
@ -59,7 +59,7 @@ impl ColorTest {
|
||||||
let tex_color = Rgba::new(1.0, 0.25, 0.25, 1.0);
|
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);
|
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;
|
let color_size = ui.style().spacing.interact_size;
|
||||||
ui.label("texture");
|
ui.label("texture");
|
||||||
show_color(ui, tex_color, color_size);
|
show_color(ui, tex_color, color_size);
|
||||||
|
@ -72,7 +72,7 @@ impl ColorTest {
|
||||||
self.vertex_gradient(ui, "Ground truth (vertices)", WHITE, &g);
|
self.vertex_gradient(ui, "Ground truth (vertices)", WHITE, &g);
|
||||||
self.tex_gradient(ui, tex_loader, "Ground truth (texture)", 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 g = Gradient::one_color(Srgba::from(tex_color));
|
||||||
let tex = self.tex_mngr.get(tex_loader, &g);
|
let tex = self.tex_mngr.get(tex_loader, &g);
|
||||||
let texel_offset = 0.5 / (g.0.len() as f32);
|
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();
|
let is_opaque = left.is_opaque() && right.is_opaque();
|
||||||
|
|
||||||
ui.horizontal_centered(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let color_size = ui.style().spacing.interact_size;
|
let color_size = ui.style().spacing.interact_size;
|
||||||
if !is_opaque {
|
if !is_opaque {
|
||||||
ui.label("Background:");
|
ui.label("Background:");
|
||||||
|
@ -228,7 +228,7 @@ impl ColorTest {
|
||||||
if !self.texture_gradients {
|
if !self.texture_gradients {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ui.horizontal_centered(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let tex = self.tex_mngr.get(tex_loader, gradient);
|
let tex = self.tex_mngr.get(tex_loader, gradient);
|
||||||
let texel_offset = 0.5 / (gradient.0.len() as f32);
|
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));
|
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 {
|
if !self.vertex_gradients {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ui.horizontal_centered(|ui| {
|
ui.horizontal(|ui| {
|
||||||
vertex_gradient(ui, bg_fill, gradient).tooltip_text(format!(
|
vertex_gradient(ui, bg_fill, gradient).tooltip_text(format!(
|
||||||
"A triangle mesh that is {} vertices wide",
|
"A triangle mesh that is {} vertices wide",
|
||||||
gradient.0.len()
|
gradient.0.len()
|
||||||
|
|
|
@ -181,7 +181,7 @@ impl ColorWidgets {
|
||||||
rgba_premul,
|
rgba_premul,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
ui.horizontal_centered(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.color_edit_button_srgba_unmultiplied(srgba_unmul);
|
ui.color_edit_button_srgba_unmultiplied(srgba_unmul);
|
||||||
ui.label(format!(
|
ui.label(format!(
|
||||||
"sRGBA: {} {} {} {}",
|
"sRGBA: {} {} {} {}",
|
||||||
|
@ -189,7 +189,7 @@ impl ColorWidgets {
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.horizontal_centered(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.color_edit_button_srgba_premultiplied(srgba_premul);
|
ui.color_edit_button_srgba_premultiplied(srgba_premul);
|
||||||
ui.label(format!(
|
ui.label(format!(
|
||||||
"sRGBA with premultiplied alpha: {} {} {} {}",
|
"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.color_edit_button_rgba_unmultiplied(rgba_unmul);
|
||||||
ui.label(format!(
|
ui.label(format!(
|
||||||
"Linear RGBA: {:.02} {:.02} {:.02} {:.02}",
|
"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.color_edit_button_rgba_premultiplied(rgba_premul);
|
||||||
ui.label(format!(
|
ui.label(format!(
|
||||||
"Linear RGBA with premultiplied alpha: {:.02} {:.02} {:.02} {:.02}",
|
"Linear RGBA with premultiplied alpha: {:.02} {:.02} {:.02} {:.02}",
|
||||||
|
|
|
@ -73,7 +73,7 @@ pub fn toggle(ui: &mut Ui, on: &mut bool) -> Response {
|
||||||
pub fn demo(ui: &mut Ui, on: &mut bool) {
|
pub fn demo(ui: &mut Ui, on: &mut bool) {
|
||||||
ui.label("It's easy to create your own widgets!");
|
ui.label("It's easy to create your own widgets!");
|
||||||
let url = format!("https://github.com/emilk/egui/blob/master/{}", file!());
|
let url = format!("https://github.com/emilk/egui/blob/master/{}", file!());
|
||||||
ui.horizontal_centered(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label("Like this toggle switch:");
|
ui.label("Like this toggle switch:");
|
||||||
toggle(ui, on).tooltip_text("Click to toggle");
|
toggle(ui, on).tooltip_text("Click to toggle");
|
||||||
ui.add(Hyperlink::new(url).text("(source code)"));
|
ui.add(Hyperlink::new(url).text("(source code)"));
|
||||||
|
|
|
@ -55,7 +55,7 @@ impl Widgets {
|
||||||
|
|
||||||
ui.add(Checkbox::new(&mut self.button_enabled, "Button enabled"));
|
ui.add(Checkbox::new(&mut self.button_enabled, "Button enabled"));
|
||||||
|
|
||||||
ui.horizontal_centered(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui
|
if ui
|
||||||
.add(Button::new("Click me").enabled(self.button_enabled))
|
.add(Button::new("Click me").enabled(self.button_enabled))
|
||||||
.tooltip_text("This will just increase a counter.")
|
.tooltip_text("This will just increase a counter.")
|
||||||
|
@ -85,7 +85,7 @@ impl Widgets {
|
||||||
ui.separator();
|
ui.separator();
|
||||||
{
|
{
|
||||||
ui.label("An angle stored as radians, but edited in degrees:");
|
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.style_mut().spacing.item_spacing.x = 0.0;
|
||||||
ui.drag_angle(&mut self.angle);
|
ui.drag_angle(&mut self.angle);
|
||||||
ui.label(format!(" = {} radians", self.angle));
|
ui.label(format!(" = {} radians", self.angle));
|
||||||
|
@ -93,7 +93,7 @@ impl Widgets {
|
||||||
}
|
}
|
||||||
ui.separator();
|
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.add(Label::new("Click to select a different text color: ").text_color(self.color));
|
||||||
ui.color_edit_button_srgba(&mut self.color);
|
ui.color_edit_button_srgba(&mut self.color);
|
||||||
});
|
});
|
||||||
|
|
|
@ -58,7 +58,7 @@ impl BarState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bar<R>(ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> (R, Rect) {
|
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| {
|
Frame::menu_bar(ui.style()).show(ui, |ui| {
|
||||||
let mut style = ui.style().clone();
|
let mut style = ui.style().clone();
|
||||||
style.spacing.button_padding = vec2(2.0, 0.0);
|
style.spacing.button_padding = vec2(2.0, 0.0);
|
||||||
|
|
|
@ -295,7 +295,7 @@ impl Style {
|
||||||
visuals,
|
visuals,
|
||||||
animation_time,
|
animation_time,
|
||||||
} = self;
|
} = self;
|
||||||
ui.horizontal_centered(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label("Default text style:");
|
ui.label("Default text style:");
|
||||||
for &value in &[TextStyle::Body, TextStyle::Monospace] {
|
for &value in &[TextStyle::Body, TextStyle::Monospace] {
|
||||||
ui.radio_value(format!("{:?}", value), body_text_style, value);
|
ui.radio_value(format!("{:?}", value), body_text_style, value);
|
||||||
|
@ -435,7 +435,7 @@ impl Visuals {
|
||||||
impl Stroke {
|
impl Stroke {
|
||||||
pub fn ui(&mut self, ui: &mut crate::Ui, text: &str) {
|
pub fn ui(&mut self, ui: &mut crate::Ui, text: &str) {
|
||||||
let Self { width, color } = self;
|
let Self { width, color } = self;
|
||||||
ui.horizontal_centered(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label(format!("{}: ", text));
|
ui.label(format!("{}: ", text));
|
||||||
ui.add(DragValue::f32(width).speed(0.1).range(0.0..=5.0))
|
ui.add(DragValue::f32(width).speed(0.1).range(0.0..=5.0))
|
||||||
.tooltip_text("Width");
|
.tooltip_text("Width");
|
||||||
|
@ -451,7 +451,7 @@ fn ui_slider_vec2(
|
||||||
range: std::ops::RangeInclusive<f32>,
|
range: std::ops::RangeInclusive<f32>,
|
||||||
text: &str,
|
text: &str,
|
||||||
) -> Response {
|
) -> Response {
|
||||||
let (_, rect) = ui.horizontal_centered(|ui| {
|
let (_, rect) = ui.horizontal(|ui| {
|
||||||
ui.label(format!("{}: ", text));
|
ui.label(format!("{}: ", text));
|
||||||
ui.add(Slider::f32(&mut value.x, range.clone()).text("w"));
|
ui.add(Slider::f32(&mut value.x, range.clone()).text("w"));
|
||||||
ui.add(Slider::f32(&mut value.y, range.clone()).text("h"));
|
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) {
|
fn ui_color(ui: &mut Ui, srgba: &mut Srgba, text: &str) {
|
||||||
ui.horizontal_centered(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label(format!("{}: ", text));
|
ui.label(format!("{}: ", text));
|
||||||
ui.color_edit_button_srgba(srgba);
|
ui.color_edit_button_srgba(srgba);
|
||||||
});
|
});
|
||||||
|
|
|
@ -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) {
|
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(
|
let initial_size = vec2(
|
||||||
self.available().width(),
|
self.available().width(),
|
||||||
self.style().spacing.interact_size.y,
|
self.style().spacing.interact_size.y,
|
||||||
|
|
|
@ -277,7 +277,7 @@ impl<'a> Widget for Slider<'a> {
|
||||||
if let Some(text) = &self.text {
|
if let Some(text) = &self.text {
|
||||||
self.id = self.id.or_else(|| Some(ui.make_unique_child_id(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);
|
let slider_response = self.allocate_slide_space(ui, height);
|
||||||
self.slider_ui(ui, &slider_response);
|
self.slider_ui(ui, &slider_response);
|
||||||
let x_range = x_range(&slider_response.rect);
|
let x_range = x_range(&slider_response.rect);
|
||||||
|
|
Loading…
Reference in a new issue