Skip to content

Commit

Permalink
Remove get_ prefix from functions to better follow Rust API Guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Aug 8, 2022
1 parent e38955f commit 7c25a92
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 63 deletions.
2 changes: 1 addition & 1 deletion egui-wgpu/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ impl RenderPass {
/// This could be used by custom paint hooks to render images that have been added through with
/// [`egui_extras::RetainedImage`](https://docs.rs/egui_extras/latest/egui_extras/image/struct.RetainedImage.html)
/// or [`egui::Context::load_texture`].
pub fn get_texture(
pub fn texture(
&self,
id: &egui::TextureId,
) -> Option<&(Option<wgpu::Texture>, wgpu::BindGroup)> {
Expand Down
4 changes: 2 additions & 2 deletions egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub struct State {

impl State {
pub fn new<T>(event_loop: &EventLoopWindowTarget<T>) -> Self {
Self::new_with_wayland_display(get_wayland_display(event_loop))
Self::new_with_wayland_display(wayland_display(event_loop))
}

pub fn new_with_wayland_display(wayland_display: Option<*mut c_void>) -> Self {
Expand Down Expand Up @@ -712,7 +712,7 @@ fn translate_cursor(cursor_icon: egui::CursorIcon) -> Option<winit::window::Curs
}

/// Returns a Wayland display handle if the target is running Wayland
fn get_wayland_display<T>(_event_loop: &EventLoopWindowTarget<T>) -> Option<*mut c_void> {
fn wayland_display<T>(_event_loop: &EventLoopWindowTarget<T>) -> Option<*mut c_void> {
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
Expand Down
14 changes: 7 additions & 7 deletions egui/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ impl MenuState {
id: Id,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> Option<R> {
let (sub_response, response) = self.get_submenu(id).map(|sub| {
let (sub_response, response) = self.submenu(id).map(|sub| {
let inner_response = Self::show(ctx, sub, id, add_contents);
(sub.read().response, inner_response.inner)
})?;
Expand Down Expand Up @@ -582,7 +582,7 @@ impl MenuState {
if pointer.is_still() {
return false;
}
if let Some(sub_menu) = self.get_current_submenu() {
if let Some(sub_menu) = self.current_submenu() {
if let Some(pos) = pointer.hover_pos() {
return Self::points_at_left_of_rect(pos, pointer.velocity(), sub_menu.read().rect);
}
Expand All @@ -592,7 +592,7 @@ impl MenuState {

/// Check if pointer is hovering current submenu.
fn hovering_current_submenu(&self, pointer: &PointerState) -> bool {
if let Some(sub_menu) = self.get_current_submenu() {
if let Some(sub_menu) = self.current_submenu() {
if let Some(pos) = pointer.hover_pos() {
return sub_menu.read().area_contains(pos);
}
Expand All @@ -608,18 +608,18 @@ impl MenuState {
}

fn is_open(&self, id: Id) -> bool {
self.get_sub_id() == Some(id)
self.sub_id() == Some(id)
}

fn get_sub_id(&self) -> Option<Id> {
fn sub_id(&self) -> Option<Id> {
self.sub_menu.as_ref().map(|(id, _)| *id)
}

fn get_current_submenu(&self) -> Option<&Arc<RwLock<MenuState>>> {
fn current_submenu(&self) -> Option<&Arc<RwLock<MenuState>>> {
self.sub_menu.as_ref().map(|(_, sub)| sub)
}

fn get_submenu(&mut self, id: Id) -> Option<&Arc<RwLock<MenuState>>> {
fn submenu(&mut self, id: Id) -> Option<&Arc<RwLock<MenuState>>> {
self.sub_menu
.as_ref()
.and_then(|(k, sub)| if id == *k { Some(sub) } else { None })
Expand Down
4 changes: 2 additions & 2 deletions egui/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl Ui {
crate::egui_assert!(!max_rect.any_nan());
let next_auto_id_source = Id::new(self.next_auto_id_source).with("child").value();
self.next_auto_id_source = self.next_auto_id_source.wrapping_add(1);
let menu_state = self.get_menu_state();
let menu_state = self.menu_state();
Ui {
id: self.id.with(id_source),
next_auto_id_source,
Expand Down Expand Up @@ -2096,7 +2096,7 @@ impl Ui {
self.menu_state = None;
}

pub(crate) fn get_menu_state(&self) -> Option<Arc<RwLock<MenuState>>> {
pub(crate) fn menu_state(&self) -> Option<Arc<RwLock<MenuState>>> {
self.menu_state.clone()
}

Expand Down
52 changes: 26 additions & 26 deletions egui/src/widgets/plot/items/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub(super) struct PlotConfig<'a> {

/// Trait shared by things that can be drawn in the plot.
pub(super) trait PlotItem {
fn get_shapes(&self, ui: &mut Ui, transform: &ScreenTransform, shapes: &mut Vec<Shape>);
fn shapes(&self, ui: &mut Ui, transform: &ScreenTransform, shapes: &mut Vec<Shape>);

fn initialize(&mut self, x_range: RangeInclusive<f64>);

Expand All @@ -46,7 +46,7 @@ pub(super) trait PlotItem {

fn geometry(&self) -> PlotGeometry<'_>;

fn get_bounds(&self) -> PlotBounds;
fn bounds(&self) -> PlotBounds;

fn find_closest(&self, point: Pos2, transform: &ScreenTransform) -> Option<ClosestElem> {
match self.geometry() {
Expand Down Expand Up @@ -167,7 +167,7 @@ impl HLine {
}

impl PlotItem for HLine {
fn get_shapes(&self, _ui: &mut Ui, transform: &ScreenTransform, shapes: &mut Vec<Shape>) {
fn shapes(&self, _ui: &mut Ui, transform: &ScreenTransform, shapes: &mut Vec<Shape>) {
let HLine {
y,
stroke,
Expand Down Expand Up @@ -204,7 +204,7 @@ impl PlotItem for HLine {
PlotGeometry::None
}

fn get_bounds(&self) -> PlotBounds {
fn bounds(&self) -> PlotBounds {
let mut bounds = PlotBounds::NOTHING;
bounds.min[1] = self.y;
bounds.max[1] = self.y;
Expand Down Expand Up @@ -277,7 +277,7 @@ impl VLine {
}

impl PlotItem for VLine {
fn get_shapes(&self, _ui: &mut Ui, transform: &ScreenTransform, shapes: &mut Vec<Shape>) {
fn shapes(&self, _ui: &mut Ui, transform: &ScreenTransform, shapes: &mut Vec<Shape>) {
let VLine {
x,
stroke,
Expand Down Expand Up @@ -314,7 +314,7 @@ impl PlotItem for VLine {
PlotGeometry::None
}

fn get_bounds(&self) -> PlotBounds {
fn bounds(&self) -> PlotBounds {
let mut bounds = PlotBounds::NOTHING;
bounds.min[0] = self.x;
bounds.max[0] = self.x;
Expand Down Expand Up @@ -401,7 +401,7 @@ fn y_intersection(p1: &Pos2, p2: &Pos2, y: f32) -> Option<f32> {
}

impl PlotItem for Line {
fn get_shapes(&self, _ui: &mut Ui, transform: &ScreenTransform, shapes: &mut Vec<Shape>) {
fn shapes(&self, _ui: &mut Ui, transform: &ScreenTransform, shapes: &mut Vec<Shape>) {
let Self {
series,
stroke,
Expand Down Expand Up @@ -484,8 +484,8 @@ impl PlotItem for Line {
PlotGeometry::Points(self.series.points())
}

fn get_bounds(&self) -> PlotBounds {
self.series.get_bounds()
fn bounds(&self) -> PlotBounds {
self.series.bounds()
}
}

Expand Down Expand Up @@ -562,7 +562,7 @@ impl Polygon {
}

impl PlotItem for Polygon {
fn get_shapes(&self, _ui: &mut Ui, transform: &ScreenTransform, shapes: &mut Vec<Shape>) {
fn shapes(&self, _ui: &mut Ui, transform: &ScreenTransform, shapes: &mut Vec<Shape>) {
let Self {
series,
stroke,
Expand Down Expand Up @@ -614,8 +614,8 @@ impl PlotItem for Polygon {
PlotGeometry::Points(self.series.points())
}

fn get_bounds(&self) -> PlotBounds {
self.series.get_bounds()
fn bounds(&self) -> PlotBounds {
self.series.bounds()
}
}

Expand Down Expand Up @@ -674,7 +674,7 @@ impl Text {
}

impl PlotItem for Text {
fn get_shapes(&self, ui: &mut Ui, transform: &ScreenTransform, shapes: &mut Vec<Shape>) {
fn shapes(&self, ui: &mut Ui, transform: &ScreenTransform, shapes: &mut Vec<Shape>) {
let color = if self.color == Color32::TRANSPARENT {
ui.style().visuals.text_color()
} else {
Expand Down Expand Up @@ -728,7 +728,7 @@ impl PlotItem for Text {
PlotGeometry::None
}

fn get_bounds(&self) -> PlotBounds {
fn bounds(&self) -> PlotBounds {
let mut bounds = PlotBounds::NOTHING;
bounds.extend_with(&self.position);
bounds
Expand Down Expand Up @@ -814,7 +814,7 @@ impl Points {
}

impl PlotItem for Points {
fn get_shapes(&self, _ui: &mut Ui, transform: &ScreenTransform, shapes: &mut Vec<Shape>) {
fn shapes(&self, _ui: &mut Ui, transform: &ScreenTransform, shapes: &mut Vec<Shape>) {
let sqrt_3 = 3_f32.sqrt();
let frac_sqrt_3_2 = 3_f32.sqrt() / 2.0;
let frac_1_sqrt_2 = 1.0 / 2_f32.sqrt();
Expand Down Expand Up @@ -965,8 +965,8 @@ impl PlotItem for Points {
PlotGeometry::Points(self.series.points())
}

fn get_bounds(&self) -> PlotBounds {
self.series.get_bounds()
fn bounds(&self) -> PlotBounds {
self.series.bounds()
}
}

Expand Down Expand Up @@ -1016,7 +1016,7 @@ impl Arrows {
}

impl PlotItem for Arrows {
fn get_shapes(&self, _ui: &mut Ui, transform: &ScreenTransform, shapes: &mut Vec<Shape>) {
fn shapes(&self, _ui: &mut Ui, transform: &ScreenTransform, shapes: &mut Vec<Shape>) {
use crate::emath::*;
let Self {
origins,
Expand Down Expand Up @@ -1080,8 +1080,8 @@ impl PlotItem for Arrows {
PlotGeometry::Points(self.origins.points())
}

fn get_bounds(&self) -> PlotBounds {
self.origins.get_bounds()
fn bounds(&self) -> PlotBounds {
self.origins.bounds()
}
}

Expand Down Expand Up @@ -1155,7 +1155,7 @@ impl PlotImage {
}

impl PlotItem for PlotImage {
fn get_shapes(&self, ui: &mut Ui, transform: &ScreenTransform, shapes: &mut Vec<Shape>) {
fn shapes(&self, ui: &mut Ui, transform: &ScreenTransform, shapes: &mut Vec<Shape>) {
let Self {
position,
texture_id,
Expand Down Expand Up @@ -1215,7 +1215,7 @@ impl PlotItem for PlotImage {
PlotGeometry::None
}

fn get_bounds(&self) -> PlotBounds {
fn bounds(&self) -> PlotBounds {
let mut bounds = PlotBounds::NOTHING;
let left_top = PlotPoint::new(
self.position.x as f32 - self.size.x / 2.0,
Expand Down Expand Up @@ -1346,7 +1346,7 @@ impl BarChart {
}

impl PlotItem for BarChart {
fn get_shapes(&self, _ui: &mut Ui, transform: &ScreenTransform, shapes: &mut Vec<Shape>) {
fn shapes(&self, _ui: &mut Ui, transform: &ScreenTransform, shapes: &mut Vec<Shape>) {
for b in &self.bars {
b.add_shapes(transform, self.highlight, shapes);
}
Expand Down Expand Up @@ -1376,7 +1376,7 @@ impl PlotItem for BarChart {
PlotGeometry::Rects
}

fn get_bounds(&self) -> PlotBounds {
fn bounds(&self) -> PlotBounds {
let mut bounds = PlotBounds::NOTHING;
for b in &self.bars {
bounds.merge(&b.bounds());
Expand Down Expand Up @@ -1488,7 +1488,7 @@ impl BoxPlot {
}

impl PlotItem for BoxPlot {
fn get_shapes(&self, _ui: &mut Ui, transform: &ScreenTransform, shapes: &mut Vec<Shape>) {
fn shapes(&self, _ui: &mut Ui, transform: &ScreenTransform, shapes: &mut Vec<Shape>) {
for b in &self.boxes {
b.add_shapes(transform, self.highlight, shapes);
}
Expand Down Expand Up @@ -1518,7 +1518,7 @@ impl PlotItem for BoxPlot {
PlotGeometry::Rects
}

fn get_bounds(&self) -> PlotBounds {
fn bounds(&self) -> PlotBounds {
let mut bounds = PlotBounds::NOTHING;
for b in &self.boxes {
bounds.merge(&b.bounds());
Expand Down
2 changes: 1 addition & 1 deletion egui/src/widgets/plot/items/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ impl PlotPoints {
(start < end).then(|| start..=end)
}

pub(super) fn get_bounds(&self) -> PlotBounds {
pub(super) fn bounds(&self) -> PlotBounds {
match self {
PlotPoints::Owned(points) => {
let mut bounds = PlotBounds::NOTHING;
Expand Down
4 changes: 2 additions & 2 deletions egui/src/widgets/plot/legend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl LegendWidget {
}

// Get the names of the hidden items.
pub fn get_hidden_items(&self) -> AHashSet<String> {
pub fn hidden_items(&self) -> AHashSet<String> {
self.entries
.iter()
.filter(|(_, entry)| !entry.checked)
Expand All @@ -208,7 +208,7 @@ impl LegendWidget {
}

// Get the name of the hovered items.
pub fn get_hovered_entry_name(&self) -> Option<String> {
pub fn hovered_entry_name(&self) -> Option<String> {
self.entries
.iter()
.find(|(_, entry)| entry.hovered)
Expand Down
14 changes: 7 additions & 7 deletions egui/src/widgets/plot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ impl Plot {
///
/// The function has this signature:
/// ```ignore
/// fn get_step_sizes(input: GridInput) -> Vec<GridMark>;
/// fn step_sizes(input: GridInput) -> Vec<GridMark>;
/// ```
///
/// This function should return all marks along the visible range of the X axis.
Expand Down Expand Up @@ -697,7 +697,7 @@ impl Plot {
}

for item in &items {
let item_bounds = item.get_bounds();
let item_bounds = item.bounds();

if auto_bounds.x {
bounds.merge_x(&item_bounds);
Expand Down Expand Up @@ -829,8 +829,8 @@ impl Plot {

if let Some(mut legend) = legend {
ui.add(&mut legend);
hidden_items = legend.get_hidden_items();
hovered_entry = legend.get_hovered_entry_name();
hidden_items = legend.hidden_items();
hovered_entry = legend.hovered_entry_name();
}

if let Some(group) = linked_axes.as_ref() {
Expand Down Expand Up @@ -1073,7 +1073,7 @@ pub struct GridMark {
/// 10 is a typical value, others are possible though.
pub fn log_grid_spacer(log_base: i64) -> GridSpacer {
let log_base = log_base as f64;
let get_step_sizes = move |input: GridInput| -> Vec<GridMark> {
let step_sizes = move |input: GridInput| -> Vec<GridMark> {
// The distance between two of the thinnest grid lines is "rounded" up
// to the next-bigger power of base
let smallest_visible_unit = next_power(input.base_step_size, log_base);
Expand All @@ -1087,7 +1087,7 @@ pub fn log_grid_spacer(log_base: i64) -> GridSpacer {
generate_marks(step_sizes, input.bounds)
};

Box::new(get_step_sizes)
Box::new(step_sizes)
}

/// Splits the grid into uniform-sized spacings (e.g. 100, 25, 1).
Expand Down Expand Up @@ -1136,7 +1136,7 @@ impl PreparedPlot {
let mut plot_ui = ui.child_ui(*transform.frame(), Layout::default());
plot_ui.set_clip_rect(*transform.frame());
for item in &self.items {
item.get_shapes(&mut plot_ui, transform, &mut shapes);
item.shapes(&mut plot_ui, transform, &mut shapes);
}

if let Some(pointer) = response.hover_pos() {
Expand Down
Loading

0 comments on commit 7c25a92

Please sign in to comment.