1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 06:40:06 -04:00

Add #[inline] to all builder-pattern functions (#3557)

Better performance and maybe code size
This commit is contained in:
Emil Ernerfeldt
2023-11-16 13:50:05 +01:00
committed by GitHub
parent 4886c8c8c0
commit a243180600
32 changed files with 398 additions and 35 deletions

View File

@@ -90,6 +90,7 @@ impl Column {
///
/// If you don't call this, the fallback value of
/// [`TableBuilder::resizable`] is used (which by default is `false`).
#[inline]
pub fn resizable(mut self, resizable: bool) -> Self {
self.resizable = Some(resizable);
self
@@ -103,6 +104,7 @@ impl Column {
/// If you turn on clipping you should also consider calling [`Self::at_least`].
///
/// Default: `false`.
#[inline]
pub fn clip(mut self, clip: bool) -> Self {
self.clip = clip;
self
@@ -111,6 +113,7 @@ impl Column {
/// Won't shrink below this width (in points).
///
/// Default: 0.0
#[inline]
pub fn at_least(mut self, minimum: f32) -> Self {
self.width_range.min = minimum;
self
@@ -119,12 +122,14 @@ impl Column {
/// Won't grow above this width (in points).
///
/// Default: [`f32::INFINITY`]
#[inline]
pub fn at_most(mut self, maximum: f32) -> Self {
self.width_range.max = maximum;
self
}
/// Allowed range of movement (in points), if in a resizable [`Table`](crate::table::Table).
#[inline]
pub fn range(mut self, range: impl Into<Rangef>) -> Self {
self.width_range = range.into();
self
@@ -244,6 +249,7 @@ impl<'a> TableBuilder<'a> {
/// Enable striped row background for improved readability.
///
/// Default is whatever is in [`egui::Visuals::striped`].
#[inline]
pub fn striped(mut self, striped: bool) -> Self {
self.striped = Some(striped);
self
@@ -259,12 +265,14 @@ impl<'a> TableBuilder<'a> {
/// (and instead use up the remainder).
///
/// Default is `false`.
#[inline]
pub fn resizable(mut self, resizable: bool) -> Self {
self.resizable = resizable;
self
}
/// Enable vertical scrolling in body (default: `true`)
#[inline]
pub fn vscroll(mut self, vscroll: bool) -> Self {
self.scroll_options.vscroll = vscroll;
self
@@ -278,6 +286,7 @@ impl<'a> TableBuilder<'a> {
/// Enables scrolling the table's contents using mouse drag (default: `true`).
///
/// See [`ScrollArea::drag_to_scroll`] for more.
#[inline]
pub fn drag_to_scroll(mut self, drag_to_scroll: bool) -> Self {
self.scroll_options.drag_to_scroll = drag_to_scroll;
self
@@ -286,6 +295,7 @@ impl<'a> TableBuilder<'a> {
/// Should the scroll handle stick to the bottom position even as the content size changes
/// dynamically? The scroll handle remains stuck until manually changed, and will become stuck
/// once again when repositioned to the bottom. Default: `false`.
#[inline]
pub fn stick_to_bottom(mut self, stick: bool) -> Self {
self.scroll_options.stick_to_bottom = stick;
self
@@ -298,6 +308,7 @@ impl<'a> TableBuilder<'a> {
/// If `align` is `None`, the table will scroll just enough to bring the cursor into view.
///
/// See also: [`Self::vertical_scroll_offset`].
#[inline]
pub fn scroll_to_row(mut self, row: usize, align: Option<Align>) -> Self {
self.scroll_options.scroll_to_row = Some((row, align));
self
@@ -306,6 +317,7 @@ impl<'a> TableBuilder<'a> {
/// Set the vertical scroll offset position, in points.
///
/// See also: [`Self::scroll_to_row`].
#[inline]
pub fn vertical_scroll_offset(mut self, offset: f32) -> Self {
self.scroll_options.scroll_offset_y = Some(offset);
self
@@ -317,6 +329,7 @@ impl<'a> TableBuilder<'a> {
/// (and so we don't require scroll bars).
///
/// Default: `200.0`.
#[inline]
pub fn min_scrolled_height(mut self, min_scrolled_height: f32) -> Self {
self.scroll_options.min_scrolled_height = min_scrolled_height;
self
@@ -326,6 +339,7 @@ impl<'a> TableBuilder<'a> {
///
/// In other words: add scroll-bars when this height is reached.
/// Default: `800.0`.
#[inline]
pub fn max_scroll_height(mut self, max_scroll_height: f32) -> Self {
self.scroll_options.max_scroll_height = max_scroll_height;
self
@@ -338,24 +352,28 @@ impl<'a> TableBuilder<'a> {
/// Default: `true`.
///
/// See [`ScrollArea::auto_shrink`] for more.
#[inline]
pub fn auto_shrink(mut self, auto_shrink: impl Into<Vec2b>) -> Self {
self.scroll_options.auto_shrink = auto_shrink.into();
self
}
/// What layout should we use for the individual cells?
#[inline]
pub fn cell_layout(mut self, cell_layout: egui::Layout) -> Self {
self.cell_layout = cell_layout;
self
}
/// Allocate space for one column.
#[inline]
pub fn column(mut self, column: Column) -> Self {
self.columns.push(column);
self
}
/// Allocate space for several columns at once.
#[inline]
pub fn columns(mut self, column: Column, count: usize) -> Self {
for _ in 0..count {
self.columns.push(column);