Add Ui::spacing() and Ui::spacing_mut() as shortcuts
This commit is contained in:
parent
c687671a9f
commit
01fca2f31c
24 changed files with 96 additions and 85 deletions
|
@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
* `egui::popup::popup_below_widget`: show a popup area below another widget.
|
||||
* Add `Slider::clamp_to_range(bool)`: if set, clamp the incoming and outgoing values to the slider range.
|
||||
* Text will now wrap at newlines, spaces, dashes, punctuation or in the middle of a words if necessary, in that order of priority.
|
||||
* Add `Ui::spacing()` and `Ui::spacing_mut()`.
|
||||
|
||||
### Changed 🔧
|
||||
|
||||
|
|
|
@ -179,17 +179,17 @@ impl CollapsingHeader {
|
|||
// TODO: horizontal layout, with icon and text as labels. Insert background behind using Frame.
|
||||
|
||||
let id = ui.make_persistent_id(id_source);
|
||||
let button_padding = ui.style().spacing.button_padding;
|
||||
let button_padding = ui.spacing().button_padding;
|
||||
|
||||
let available = ui.available_rect_before_wrap_finite();
|
||||
let text_pos = available.min + vec2(ui.style().spacing.indent, 0.0);
|
||||
let text_pos = available.min + vec2(ui.spacing().indent, 0.0);
|
||||
let galley = label.layout_width(ui, available.right() - text_pos.x);
|
||||
let text_max_x = text_pos.x + galley.size.x;
|
||||
let desired_width = text_max_x + button_padding.x - available.left();
|
||||
let desired_width = desired_width.max(available.width());
|
||||
|
||||
let mut desired_size = vec2(desired_width, galley.size.y + 2.0 * button_padding.y);
|
||||
desired_size = desired_size.at_least(ui.style().spacing.interact_size);
|
||||
desired_size = desired_size.at_least(ui.spacing().interact_size);
|
||||
let (_, rect) = ui.allocate_space(desired_size);
|
||||
|
||||
let header_response = ui.interact(rect, id, Sense::click());
|
||||
|
@ -214,9 +214,9 @@ impl CollapsingHeader {
|
|||
});
|
||||
|
||||
{
|
||||
let (mut icon_rect, _) = ui.style().spacing.icon_rectangles(header_response.rect);
|
||||
let (mut icon_rect, _) = ui.spacing().icon_rectangles(header_response.rect);
|
||||
icon_rect.set_center(pos2(
|
||||
header_response.rect.left() + ui.style().spacing.indent / 2.0,
|
||||
header_response.rect.left() + ui.spacing().indent / 2.0,
|
||||
header_response.rect.center().y,
|
||||
));
|
||||
let icon_response = Response {
|
||||
|
|
|
@ -59,19 +59,19 @@ pub fn combo_box(
|
|||
let button_active = ui.memory().is_popup_open(popup_id);
|
||||
let button_response = button_frame(ui, button_id, button_active, Sense::click(), |ui| {
|
||||
// We don't want to change width when user selects something new
|
||||
let full_minimum_width = ui.style().spacing.slider_width;
|
||||
let icon_size = Vec2::splat(ui.style().spacing.icon_width);
|
||||
let full_minimum_width = ui.spacing().slider_width;
|
||||
let icon_size = Vec2::splat(ui.spacing().icon_width);
|
||||
|
||||
let text_style = TextStyle::Button;
|
||||
let font = &ui.fonts()[text_style];
|
||||
let galley = font.layout_single_line(selected.into());
|
||||
|
||||
let width = galley.size.x + ui.style().spacing.item_spacing.x + icon_size.x;
|
||||
let width = galley.size.x + ui.spacing().item_spacing.x + icon_size.x;
|
||||
let width = width.at_least(full_minimum_width);
|
||||
let height = galley.size.y.max(icon_size.y);
|
||||
|
||||
let (_, rect) = ui.allocate_space(Vec2::new(width, height));
|
||||
let button_rect = ui.min_rect().expand2(ui.style().spacing.button_padding);
|
||||
let button_rect = ui.min_rect().expand2(ui.spacing().button_padding);
|
||||
let response = ui.interact(button_rect, button_id, Sense::click());
|
||||
// response.active |= button_active;
|
||||
|
||||
|
@ -104,8 +104,8 @@ fn button_frame(
|
|||
) -> Response {
|
||||
let where_to_put_background = ui.painter().add(Shape::Noop);
|
||||
|
||||
let margin = ui.style().spacing.button_padding;
|
||||
let interact_size = ui.style().spacing.interact_size;
|
||||
let margin = ui.spacing().button_padding;
|
||||
let interact_size = ui.spacing().interact_size;
|
||||
|
||||
let mut outer_rect = ui.available_rect_before_wrap();
|
||||
outer_rect.set_height(outer_rect.height().at_least(interact_size.y));
|
||||
|
|
|
@ -73,7 +73,7 @@ fn show_tooltip_area(
|
|||
.interactable(false)
|
||||
.show(ctx, |ui| {
|
||||
Frame::popup(&ctx.style()).show(ui, |ui| {
|
||||
ui.set_max_width(ui.style().spacing.tooltip_width);
|
||||
ui.set_max_width(ui.spacing().tooltip_width);
|
||||
add_contents(ui);
|
||||
})
|
||||
})
|
||||
|
|
|
@ -167,7 +167,7 @@ impl Resize {
|
|||
.at_least(self.min_size)
|
||||
.at_most(self.max_size)
|
||||
.at_most(
|
||||
ui.input().screen_rect().size() - 2.0 * ui.style().spacing.window_padding, // hack for windows
|
||||
ui.input().screen_rect().size() - 2.0 * ui.spacing().window_padding, // hack for windows
|
||||
);
|
||||
|
||||
State {
|
||||
|
|
|
@ -183,7 +183,7 @@ impl Prepared {
|
|||
let visible_range = top..=top + content_ui.clip_rect().height();
|
||||
let offset_y = scroll_y - lerp(visible_range, center_factor);
|
||||
|
||||
let mut spacing = ui.style().spacing.item_spacing.y;
|
||||
let mut spacing = ui.spacing().item_spacing.y;
|
||||
|
||||
// Depending on the alignment we need to add or subtract the spacing
|
||||
spacing *= remap(center_factor, 0.0..=1.0, -1.0..=1.0);
|
||||
|
@ -260,7 +260,7 @@ impl Prepared {
|
|||
if current_scroll_bar_width > 0.0 {
|
||||
let animation_t = current_scroll_bar_width / max_scroll_bar_width;
|
||||
// margin between contents and scroll bar
|
||||
let margin = animation_t * ui.style().spacing.item_spacing.x;
|
||||
let margin = animation_t * ui.spacing().item_spacing.x;
|
||||
let left = inner_rect.right() + margin;
|
||||
let right = outer_rect.right();
|
||||
let corner_radius = (right - left) / 2.0;
|
||||
|
@ -364,5 +364,5 @@ impl Prepared {
|
|||
}
|
||||
|
||||
fn max_scroll_bar_width_with_margin(ui: &Ui) -> f32 {
|
||||
ui.style().spacing.item_spacing.x + 16.0
|
||||
ui.spacing().item_spacing.x + 16.0
|
||||
}
|
||||
|
|
|
@ -669,11 +669,11 @@ fn show_title_bar(
|
|||
let (title_bar, response) = ui.horizontal(|ui| {
|
||||
let height = title_label
|
||||
.font_height(ui.fonts(), ui.style())
|
||||
.max(ui.style().spacing.interact_size.y);
|
||||
.max(ui.spacing().interact_size.y);
|
||||
ui.set_min_height(height);
|
||||
|
||||
let item_spacing = ui.style().spacing.item_spacing;
|
||||
let button_size = Vec2::splat(ui.style().spacing.icon_width);
|
||||
let item_spacing = ui.spacing().item_spacing;
|
||||
let button_size = Vec2::splat(ui.spacing().icon_width);
|
||||
|
||||
let pad = (height - button_size.y) / 2.0; // calculated so that the icon is on the diagonal (if window padding is symmetrical)
|
||||
|
||||
|
@ -753,7 +753,7 @@ impl TitleBar {
|
|||
// paint separator between title and content:
|
||||
let left = outer_rect.left();
|
||||
let right = outer_rect.right();
|
||||
let y = content_response.rect.top() + ui.style().spacing.item_spacing.y * 0.5;
|
||||
let y = content_response.rect.top() + ui.spacing().item_spacing.y * 0.5;
|
||||
// let y = lerp(self.rect.bottom()..=content_response.rect.top(), 0.5);
|
||||
ui.painter().line_segment(
|
||||
[pos2(left, y), pos2(right, y)],
|
||||
|
@ -771,7 +771,7 @@ impl TitleBar {
|
|||
}
|
||||
|
||||
fn close_button_ui(&self, ui: &mut Ui) -> Response {
|
||||
let button_size = Vec2::splat(ui.style().spacing.icon_width);
|
||||
let button_size = Vec2::splat(ui.spacing().icon_width);
|
||||
let pad = (self.rect.height() - button_size.y) / 2.0; // calculated so that the icon is on the diagonal (if window padding is symmetrical)
|
||||
let button_rect = Rect::from_min_size(
|
||||
pos2(
|
||||
|
|
|
@ -64,10 +64,10 @@ impl GridLayout {
|
|||
id,
|
||||
prev_state,
|
||||
curr_state: State::default(),
|
||||
spacing: ui.style().spacing.item_spacing,
|
||||
spacing: ui.spacing().item_spacing,
|
||||
striped: false,
|
||||
initial_x: ui.cursor().x,
|
||||
min_cell_size: ui.style().spacing.interact_size,
|
||||
min_cell_size: ui.spacing().interact_size,
|
||||
col: 0,
|
||||
row: 0,
|
||||
}
|
||||
|
@ -276,9 +276,9 @@ impl Grid {
|
|||
min_row_height,
|
||||
spacing,
|
||||
} = self;
|
||||
let min_col_width = min_col_width.unwrap_or_else(|| ui.style().spacing.interact_size.x);
|
||||
let min_row_height = min_row_height.unwrap_or_else(|| ui.style().spacing.interact_size.y);
|
||||
let spacing = spacing.unwrap_or_else(|| ui.style().spacing.item_spacing);
|
||||
let min_col_width = min_col_width.unwrap_or_else(|| ui.spacing().interact_size.x);
|
||||
let min_row_height = min_row_height.unwrap_or_else(|| ui.spacing().interact_size.y);
|
||||
let spacing = spacing.unwrap_or_else(|| ui.spacing().item_spacing);
|
||||
|
||||
// Each grid cell is aligned LEFT_CENTER.
|
||||
// If somebody wants to wrap more things inside a cell,
|
||||
|
|
|
@ -53,7 +53,7 @@ pub fn bar<R>(ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> (R, Respo
|
|||
ui.set_style(style);
|
||||
|
||||
// Take full width and fixed height:
|
||||
let height = ui.style().spacing.interact_size.y;
|
||||
let height = ui.spacing().interact_size.y;
|
||||
ui.set_min_size(vec2(ui.available_width(), height));
|
||||
|
||||
add_contents(ui)
|
||||
|
|
|
@ -567,12 +567,12 @@ fn ui_slider_vec2(
|
|||
fsw - 2 * space - value = 2 * ssw
|
||||
ssw = fsw / 2 - space - value / 2
|
||||
*/
|
||||
// let spacing = &ui.style().spacing;
|
||||
// let spacing = &ui.spacing();
|
||||
// let space = spacing.item_spacing.x;
|
||||
// let value_w = spacing.interact_size.x;
|
||||
// let full_slider_width = spacing.slider_width;
|
||||
// let small_slider_width = full_slider_width / 2.0 - space - value_w / 2.0;
|
||||
// ui.style_mut().spacing.slider_width = small_slider_width;
|
||||
// ui.spacing_mut().slider_width = small_slider_width;
|
||||
|
||||
ui.add(Slider::f32(&mut value.x, range.clone()).text("w"));
|
||||
ui.add(Slider::f32(&mut value.y, range.clone()).text("h"));
|
||||
|
|
|
@ -108,6 +108,18 @@ impl Ui {
|
|||
self.style = style.into();
|
||||
}
|
||||
|
||||
/// Short for `&self.style().spacing`
|
||||
/// Spacing options for this `Ui` and its children.
|
||||
pub fn spacing(&self) -> &crate::style::Spacing {
|
||||
&self.style.spacing
|
||||
}
|
||||
|
||||
/// Mutably borrow internal `Spacing`.
|
||||
/// Changes apply to this `Ui` and its subsequent children.
|
||||
pub fn spacing_mut(&mut self) -> &mut crate::style::Spacing {
|
||||
&mut self.style_mut().spacing
|
||||
}
|
||||
|
||||
/// Get a reference to the parent [`CtxRef`].
|
||||
pub fn ctx(&self) -> &CtxRef {
|
||||
self.painter.ctx()
|
||||
|
@ -355,7 +367,7 @@ impl Ui {
|
|||
pub fn interact(&self, rect: Rect, id: Id, sense: Sense) -> Response {
|
||||
self.ctx().interact(
|
||||
self.clip_rect(),
|
||||
self.style().spacing.item_spacing,
|
||||
self.spacing().item_spacing,
|
||||
self.layer_id(),
|
||||
id,
|
||||
rect,
|
||||
|
@ -517,7 +529,7 @@ impl Ui {
|
|||
/// Reserve this much space and move the cursor.
|
||||
/// Returns where to put the widget.
|
||||
fn allocate_space_impl(&mut self, desired_size: Vec2) -> Rect {
|
||||
let item_spacing = self.style().spacing.item_spacing;
|
||||
let item_spacing = self.spacing().item_spacing;
|
||||
let frame_rect = self.placer.next_space(desired_size, item_spacing);
|
||||
let widget_rect = self.placer.justify_or_align(frame_rect, desired_size);
|
||||
|
||||
|
@ -534,7 +546,7 @@ impl Ui {
|
|||
}
|
||||
|
||||
pub(crate) fn advance_cursor_after_rect(&mut self, rect: Rect) -> Id {
|
||||
let item_spacing = self.style().spacing.item_spacing;
|
||||
let item_spacing = self.spacing().item_spacing;
|
||||
self.placer.advance_after_rects(rect, rect, item_spacing);
|
||||
|
||||
self.next_auto_id = self.next_auto_id.wrapping_add(1);
|
||||
|
@ -554,7 +566,7 @@ impl Ui {
|
|||
desired_size: Vec2,
|
||||
add_contents: impl FnOnce(&mut Self) -> R,
|
||||
) -> (R, Response) {
|
||||
let item_spacing = self.style().spacing.item_spacing;
|
||||
let item_spacing = self.spacing().item_spacing;
|
||||
let outer_child_rect = self.placer.next_space(desired_size, item_spacing);
|
||||
let inner_child_rect = self.placer.justify_or_align(outer_child_rect, desired_size);
|
||||
|
||||
|
@ -929,7 +941,7 @@ impl Ui {
|
|||
"You can only indent vertical layouts, found {:?}",
|
||||
self.layout()
|
||||
);
|
||||
let indent = vec2(self.style().spacing.indent, 0.0);
|
||||
let indent = vec2(self.spacing().indent, 0.0);
|
||||
let child_rect = Rect::from_min_max(self.cursor() + indent, self.max_rect().right_bottom()); // TODO: wrong for reversed layouts
|
||||
let mut child_ui = Self {
|
||||
id: self.id.with(id_source),
|
||||
|
@ -1016,10 +1028,10 @@ impl Ui {
|
|||
let font = &ui.fonts()[text_style];
|
||||
let row_height = font.row_height();
|
||||
let space_width = font.glyph_width(' ');
|
||||
let style = ui.style_mut();
|
||||
style.spacing.interact_size.y = row_height;
|
||||
style.spacing.item_spacing.x = space_width;
|
||||
style.spacing.item_spacing.y = 0.0;
|
||||
let spacing = ui.spacing_mut();
|
||||
spacing.interact_size.y = row_height;
|
||||
spacing.item_spacing.x = space_width;
|
||||
spacing.item_spacing.y = 0.0;
|
||||
ui.horizontal(add_contents).0
|
||||
})
|
||||
}
|
||||
|
@ -1060,10 +1072,10 @@ impl Ui {
|
|||
let font = &ui.fonts()[text_style];
|
||||
let row_height = font.row_height();
|
||||
let space_width = font.glyph_width(' ');
|
||||
let style = ui.style_mut();
|
||||
style.spacing.interact_size.y = row_height;
|
||||
style.spacing.item_spacing.x = space_width;
|
||||
style.spacing.item_spacing.y = 0.0;
|
||||
let spacing = ui.spacing_mut();
|
||||
spacing.interact_size.y = row_height;
|
||||
spacing.item_spacing.x = space_width;
|
||||
spacing.item_spacing.y = 0.0;
|
||||
ui.horizontal_wrapped(add_contents).0
|
||||
})
|
||||
}
|
||||
|
@ -1075,7 +1087,7 @@ impl Ui {
|
|||
) -> (R, Response) {
|
||||
let initial_size = vec2(
|
||||
self.available_size_before_wrap_finite().x,
|
||||
self.style().spacing.interact_size.y, // Assume there will be something interactive on the horizontal layout
|
||||
self.spacing().interact_size.y, // Assume there will be something interactive on the horizontal layout
|
||||
);
|
||||
|
||||
let layout = if self.placer.prefer_right_to_left() {
|
||||
|
@ -1123,7 +1135,7 @@ impl Ui {
|
|||
let mut child_ui = self.child_ui(self.available_rect_before_wrap(), layout);
|
||||
let ret = add_contents(&mut child_ui);
|
||||
let rect = child_ui.min_rect();
|
||||
let item_spacing = self.style().spacing.item_spacing;
|
||||
let item_spacing = self.spacing().item_spacing;
|
||||
self.placer.advance_after_rects(rect, rect, item_spacing);
|
||||
(ret, self.interact(rect, child_ui.id, Sense::hover()))
|
||||
}
|
||||
|
@ -1144,7 +1156,7 @@ impl Ui {
|
|||
/// Otherwise does nothing.
|
||||
pub fn end_row(&mut self) {
|
||||
self.placer
|
||||
.end_row(self.style().spacing.item_spacing, &self.painter().clone());
|
||||
.end_row(self.spacing().item_spacing, &self.painter().clone());
|
||||
}
|
||||
|
||||
/// Temporarily split split an Ui into several columns.
|
||||
|
@ -1161,7 +1173,7 @@ impl Ui {
|
|||
F: FnOnce(&mut [Self]) -> R,
|
||||
{
|
||||
// TODO: ensure there is space
|
||||
let spacing = self.style().spacing.item_spacing.x;
|
||||
let spacing = self.spacing().item_spacing.x;
|
||||
let total_spacing = spacing * (num_columns as f32 - 1.0);
|
||||
let column_width = (self.available_width() - total_spacing) / (num_columns as f32);
|
||||
let top_left = self.cursor();
|
||||
|
|
|
@ -96,14 +96,14 @@ impl Widget for Button {
|
|||
font.layout_multiline(text, ui.available_width())
|
||||
};
|
||||
|
||||
let mut button_padding = ui.style().spacing.button_padding;
|
||||
let mut button_padding = ui.spacing().button_padding;
|
||||
if small {
|
||||
button_padding.y = 0.0;
|
||||
}
|
||||
|
||||
let mut desired_size = galley.size + 2.0 * button_padding;
|
||||
if !small {
|
||||
desired_size.y = desired_size.y.at_least(ui.style().spacing.interact_size.y);
|
||||
desired_size.y = desired_size.y.at_least(ui.spacing().interact_size.y);
|
||||
}
|
||||
|
||||
let (rect, response) = ui.allocate_at_least(desired_size, sense);
|
||||
|
@ -174,9 +174,9 @@ impl<'a> Widget for Checkbox<'a> {
|
|||
let text_style = TextStyle::Button;
|
||||
let font = &ui.fonts()[text_style];
|
||||
|
||||
let spacing = &ui.style().spacing;
|
||||
let spacing = &ui.spacing();
|
||||
let icon_width = spacing.icon_width;
|
||||
let icon_spacing = ui.style().spacing.icon_spacing;
|
||||
let icon_spacing = ui.spacing().icon_spacing;
|
||||
let button_padding = spacing.button_padding;
|
||||
let total_extra = button_padding + vec2(icon_width + icon_spacing, 0.0) + button_padding;
|
||||
|
||||
|
@ -200,7 +200,7 @@ impl<'a> Widget for Checkbox<'a> {
|
|||
rect.min.x + button_padding.x + icon_width + icon_spacing,
|
||||
rect.center().y - 0.5 * galley.size.y,
|
||||
);
|
||||
let (small_icon_rect, big_icon_rect) = ui.style().spacing.icon_rectangles(rect);
|
||||
let (small_icon_rect, big_icon_rect) = ui.spacing().icon_rectangles(rect);
|
||||
ui.painter().add(Shape::Rect {
|
||||
rect: big_icon_rect.expand(visuals.expansion),
|
||||
corner_radius: visuals.corner_radius,
|
||||
|
@ -267,9 +267,9 @@ impl Widget for RadioButton {
|
|||
let text_style = TextStyle::Button;
|
||||
let font = &ui.fonts()[text_style];
|
||||
|
||||
let icon_width = ui.style().spacing.icon_width;
|
||||
let icon_spacing = ui.style().spacing.icon_spacing;
|
||||
let button_padding = ui.style().spacing.button_padding;
|
||||
let icon_width = ui.spacing().icon_width;
|
||||
let icon_spacing = ui.spacing().icon_spacing;
|
||||
let button_padding = ui.spacing().button_padding;
|
||||
let total_extra = button_padding + vec2(icon_width + icon_spacing, 0.0) + button_padding;
|
||||
|
||||
let single_line = ui.layout().is_horizontal();
|
||||
|
@ -280,7 +280,7 @@ impl Widget for RadioButton {
|
|||
};
|
||||
|
||||
let mut desired_size = total_extra + galley.size;
|
||||
desired_size = desired_size.at_least(ui.style().spacing.interact_size);
|
||||
desired_size = desired_size.at_least(ui.spacing().interact_size);
|
||||
desired_size.y = desired_size.y.max(icon_width);
|
||||
let (rect, response) = ui.allocate_exact_size(desired_size, Sense::click());
|
||||
|
||||
|
@ -291,7 +291,7 @@ impl Widget for RadioButton {
|
|||
|
||||
let visuals = ui.style().interact(&response);
|
||||
|
||||
let (small_icon_rect, big_icon_rect) = ui.style().spacing.icon_rectangles(rect);
|
||||
let (small_icon_rect, big_icon_rect) = ui.spacing().icon_rectangles(rect);
|
||||
|
||||
let painter = ui.painter();
|
||||
|
||||
|
@ -383,7 +383,7 @@ impl Widget for ImageButton {
|
|||
selected,
|
||||
} = self;
|
||||
|
||||
let button_padding = ui.style().spacing.button_padding;
|
||||
let button_padding = ui.spacing().button_padding;
|
||||
let size = image.size() + 2.0 * button_padding;
|
||||
let (rect, response) = ui.allocate_exact_size(size, sense);
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ fn show_hsva(ui: &mut Ui, color: Hsva, desired_size: Vec2) -> Response {
|
|||
}
|
||||
|
||||
fn color_button(ui: &mut Ui, color: Color32) -> Response {
|
||||
let size = ui.style().spacing.interact_size;
|
||||
let size = ui.spacing().interact_size;
|
||||
let (rect, response) = ui.allocate_exact_size(size, Sense::click());
|
||||
let visuals = ui.style().interact(&response);
|
||||
let rect = rect.expand(visuals.expansion);
|
||||
|
@ -89,8 +89,8 @@ fn color_slider_1d(ui: &mut Ui, value: &mut f32, color_at: impl Fn(f32) -> Color
|
|||
#![allow(clippy::identity_op)]
|
||||
|
||||
let desired_size = vec2(
|
||||
ui.style().spacing.slider_width,
|
||||
ui.style().spacing.interact_size.y * 2.0,
|
||||
ui.spacing().slider_width,
|
||||
ui.spacing().interact_size.y * 2.0,
|
||||
);
|
||||
let (rect, response) = ui.allocate_at_least(desired_size, Sense::click_and_drag());
|
||||
|
||||
|
@ -146,7 +146,7 @@ fn color_slider_2d(
|
|||
y_value: &mut f32,
|
||||
color_at: impl Fn(f32, f32) -> Color32,
|
||||
) -> Response {
|
||||
let desired_size = Vec2::splat(ui.style().spacing.slider_width);
|
||||
let desired_size = Vec2::splat(ui.spacing().slider_width);
|
||||
let (rect, response) = ui.allocate_at_least(desired_size, Sense::click_and_drag());
|
||||
|
||||
if let Some(mpos) = response.interact_pointer_pos() {
|
||||
|
@ -254,8 +254,8 @@ fn color_picker_hsvag_2d(ui: &mut Ui, hsva: &mut HsvaGamma, alpha: Alpha) {
|
|||
|
||||
crate::Grid::new(grid_id).show(ui, |ui| {
|
||||
let current_color_size = vec2(
|
||||
ui.style().spacing.slider_width,
|
||||
ui.style().spacing.interact_size.y * 2.0,
|
||||
ui.spacing().slider_width,
|
||||
ui.spacing().interact_size.y * 2.0,
|
||||
);
|
||||
|
||||
let opaque = HsvaGamma { a: 1.0, ..*hsva };
|
||||
|
@ -328,7 +328,7 @@ pub fn color_edit_button_hsva(ui: &mut Ui, hsva: &mut Hsva, alpha: Alpha) -> Res
|
|||
.order(Order::Foreground)
|
||||
.default_pos(button_response.rect.max)
|
||||
.show(ui.ctx(), |ui| {
|
||||
ui.style_mut().spacing.slider_width = 256.0;
|
||||
ui.spacing_mut().slider_width = 256.0;
|
||||
Frame::popup(ui.style()).show(ui, |ui| {
|
||||
color_picker_hsva_2d(ui, hsva, alpha);
|
||||
})
|
||||
|
|
|
@ -162,7 +162,7 @@ impl<'a> Widget for DragValue<'a> {
|
|||
let is_kb_editing = ui.memory().has_kb_focus(kb_edit_id);
|
||||
|
||||
if is_kb_editing {
|
||||
let button_width = ui.style().spacing.interact_size.x;
|
||||
let button_width = ui.spacing().interact_size.x;
|
||||
let mut value_text = ui.memory().temp_edit_string.take().unwrap_or(value_text);
|
||||
let response = ui.add(
|
||||
TextEdit::singleline(&mut value_text)
|
||||
|
|
|
@ -59,7 +59,7 @@ pub fn stroke_ui(ui: &mut crate::Ui, stroke: &mut epaint::Stroke, text: &str) {
|
|||
ui.label(text);
|
||||
|
||||
// stroke preview:
|
||||
let (_id, stroke_rect) = ui.allocate_space(ui.style().spacing.interact_size);
|
||||
let (_id, stroke_rect) = ui.allocate_space(ui.spacing().interact_size);
|
||||
let left = stroke_rect.left_center();
|
||||
let right = stroke_rect.right_center();
|
||||
ui.painter().line_segment([left, right], (*width, *color));
|
||||
|
|
|
@ -26,13 +26,13 @@ impl Widget for SelectableLabel {
|
|||
let text_style = TextStyle::Button;
|
||||
let font = &ui.fonts()[text_style];
|
||||
|
||||
let button_padding = ui.style().spacing.button_padding;
|
||||
let button_padding = ui.spacing().button_padding;
|
||||
let total_extra = button_padding + button_padding;
|
||||
|
||||
let galley = font.layout_multiline(text, ui.available_width() - total_extra.x);
|
||||
|
||||
let mut desired_size = total_extra + galley.size;
|
||||
desired_size.y = desired_size.y.at_least(ui.style().spacing.interact_size.y);
|
||||
desired_size.y = desired_size.y.at_least(ui.spacing().interact_size.y);
|
||||
let (rect, response) = ui.allocate_at_least(desired_size, Sense::click());
|
||||
|
||||
let text_cursor = ui
|
||||
|
|
|
@ -266,7 +266,7 @@ fn x_range(rect: &Rect) -> RangeInclusive<f32> {
|
|||
impl<'a> Slider<'a> {
|
||||
/// Just the slider, no text
|
||||
fn allocate_slider_space(&self, ui: &mut Ui, height: f32) -> Response {
|
||||
let desired_size = vec2(ui.style().spacing.slider_width, height);
|
||||
let desired_size = vec2(ui.spacing().slider_width, height);
|
||||
ui.allocate_response(desired_size, Sense::click_and_drag())
|
||||
}
|
||||
|
||||
|
@ -343,7 +343,7 @@ impl<'a> Slider<'a> {
|
|||
let value_text = self.format_value(aim_radius, x_range);
|
||||
|
||||
if is_kb_editing {
|
||||
let button_width = ui.style().spacing.interact_size.x;
|
||||
let button_width = ui.spacing().interact_size.x;
|
||||
let mut value_text = ui.memory().temp_edit_string.take().unwrap_or(value_text);
|
||||
ui.add(
|
||||
TextEdit::singleline(&mut value_text)
|
||||
|
@ -409,9 +409,7 @@ impl<'a> Widget for Slider<'a> {
|
|||
fn ui(mut self, ui: &mut Ui) -> Response {
|
||||
let text_style = TextStyle::Button;
|
||||
let font = &ui.fonts()[text_style];
|
||||
let height = font
|
||||
.row_height()
|
||||
.at_least(ui.style().spacing.interact_size.y);
|
||||
let height = font.row_height().at_least(ui.spacing().interact_size.y);
|
||||
|
||||
if self.text.is_some() {
|
||||
ui.horizontal(|ui| {
|
||||
|
|
|
@ -289,7 +289,7 @@ impl<'t> TextEdit<'t> {
|
|||
font.layout_single_line(text.clone())
|
||||
};
|
||||
|
||||
let desired_width = desired_width.unwrap_or_else(|| ui.style().spacing.text_edit_width);
|
||||
let desired_width = desired_width.unwrap_or_else(|| ui.spacing().text_edit_width);
|
||||
let desired_height = (desired_height_rows.at_least(1) as f32) * line_spacing;
|
||||
let desired_size = vec2(
|
||||
galley.size.x.max(desired_width.min(available_width)),
|
||||
|
|
|
@ -71,7 +71,7 @@ impl ColorTest {
|
|||
ui.heading("sRGB color test");
|
||||
ui.label("Use a color picker to ensure this color is (255, 165, 0) / #ffa500");
|
||||
ui.wrap(|ui| {
|
||||
ui.style_mut().spacing.item_spacing.y = 0.0; // No spacing between gradients
|
||||
ui.spacing_mut().item_spacing.y = 0.0; // No spacing between gradients
|
||||
let g = Gradient::one_color(Color32::from_rgb(255, 165, 0));
|
||||
self.vertex_gradient(ui, "orange rgb(255, 165, 0) - vertex", WHITE, &g);
|
||||
self.tex_gradient(
|
||||
|
@ -87,13 +87,13 @@ impl ColorTest {
|
|||
|
||||
ui.label("Test that vertex color times texture color is done in linear space:");
|
||||
ui.wrap(|ui| {
|
||||
ui.style_mut().spacing.item_spacing.y = 0.0; // No spacing between gradients
|
||||
ui.spacing_mut().item_spacing.y = 0.0; // No spacing between gradients
|
||||
|
||||
let tex_color = Rgba::from_rgb(1.0, 0.25, 0.25);
|
||||
let vertex_color = Rgba::from_rgb(0.5, 0.75, 0.75);
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
let color_size = ui.style().spacing.interact_size;
|
||||
let color_size = ui.spacing().interact_size;
|
||||
ui.label("texture");
|
||||
show_color(ui, tex_color, color_size);
|
||||
ui.label(" * ");
|
||||
|
@ -174,7 +174,7 @@ impl ColorTest {
|
|||
let is_opaque = left.is_opaque() && right.is_opaque();
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
let color_size = ui.style().spacing.interact_size;
|
||||
let color_size = ui.spacing().interact_size;
|
||||
if !is_opaque {
|
||||
ui.label("Background:");
|
||||
show_color(ui, bg_fill, color_size);
|
||||
|
@ -186,7 +186,7 @@ impl ColorTest {
|
|||
});
|
||||
|
||||
ui.wrap(|ui| {
|
||||
ui.style_mut().spacing.item_spacing.y = 0.0; // No spacing between gradients
|
||||
ui.spacing_mut().item_spacing.y = 0.0; // No spacing between gradients
|
||||
if is_opaque {
|
||||
let g = Gradient::ground_truth_linear_gradient(left, right);
|
||||
self.vertex_gradient(ui, "Ground Truth (CPU gradient) - vertices", bg_fill, &g);
|
||||
|
|
|
@ -90,7 +90,7 @@ impl super::View for FontBook {
|
|||
|
||||
egui::ScrollArea::auto_sized().show(ui, |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.style_mut().spacing.item_spacing = egui::Vec2::splat(2.0);
|
||||
ui.spacing_mut().item_spacing = egui::Vec2::splat(2.0);
|
||||
|
||||
if self.standard {
|
||||
self.characters_ui(ui, UBUNTU_FONT_CHARACTERS);
|
||||
|
|
|
@ -19,7 +19,7 @@ pub fn toggle(ui: &mut egui::Ui, on: &mut bool) -> egui::Response {
|
|||
// 1. Deciding widget size:
|
||||
// You can query the `ui` how much space is available,
|
||||
// but in this example we have a fixed size widget of the default size for a button:
|
||||
let desired_size = ui.style().spacing.interact_size;
|
||||
let desired_size = ui.spacing().interact_size;
|
||||
|
||||
// 2. Allocating space:
|
||||
// This is where we get a region of the screen assigned.
|
||||
|
@ -61,7 +61,7 @@ pub fn toggle(ui: &mut egui::Ui, on: &mut bool) -> egui::Response {
|
|||
/// Here is the same code again, but a bit more compact:
|
||||
#[allow(dead_code)]
|
||||
fn toggle_compact(ui: &mut egui::Ui, on: &mut bool) -> egui::Response {
|
||||
let desired_size = ui.style().spacing.interact_size;
|
||||
let desired_size = ui.spacing().interact_size;
|
||||
let (rect, response) = ui.allocate_exact_size(desired_size, egui::Sense::click());
|
||||
*on ^= response.clicked(); // toggle if clicked
|
||||
|
||||
|
|
|
@ -239,7 +239,7 @@ impl ColoredText {
|
|||
pub fn ui(&self, ui: &mut egui::Ui) {
|
||||
for line in &self.0 {
|
||||
ui.horizontal_wrapped_for_text(egui::TextStyle::Monospace, |ui| {
|
||||
ui.style_mut().spacing.item_spacing.x = 0.0;
|
||||
ui.spacing_mut().item_spacing.x = 0.0;
|
||||
for (style, range) in line {
|
||||
let fg = style.foreground;
|
||||
let text_color = egui::Color32::from_rgb(fg.r, fg.g, fg.b);
|
||||
|
|
|
@ -64,7 +64,7 @@ impl FrameHistory {
|
|||
let history = &self.frame_times;
|
||||
|
||||
// TODO: we should not use `slider_width` as default graph width.
|
||||
let height = ui.style().spacing.slider_width;
|
||||
let height = ui.spacing().slider_width;
|
||||
let size = vec2(ui.available_size_before_wrap_finite().x, height);
|
||||
let (rect, response) = ui.allocate_at_least(size, Sense::hover());
|
||||
let style = ui.style().noninteractive();
|
||||
|
|
|
@ -261,7 +261,7 @@ impl BackendPanel {
|
|||
let pixels_per_point = self.pixels_per_point.as_mut()?;
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.style_mut().spacing.slider_width = 90.0;
|
||||
ui.spacing_mut().slider_width = 90.0;
|
||||
ui.add(
|
||||
egui::Slider::f32(pixels_per_point, 0.5..=5.0)
|
||||
.logarithmic(true)
|
||||
|
|
Loading…
Reference in a new issue