Skip to content

Commit

Permalink
Merge render & render util modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerthox committed Jan 19, 2025
1 parent b9d6d15 commit 754329e
Show file tree
Hide file tree
Showing 57 changed files with 110 additions and 136 deletions.
2 changes: 1 addition & 1 deletion reffect/src/action/dynamic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(unused)]

use crate::render_util::item_context_menu;
use crate::render::item_context_menu;
use nexus::imgui::{MenuItem, Ui};
use std::fmt;

Expand Down
2 changes: 1 addition & 1 deletion reffect/src/action/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod dynamic;
mod element;

use crate::render_util::{button_size_with_spacing, close_button};
use crate::render::{button_size_with_spacing, close_button};
use nexus::imgui::{Direction, Ui};

pub use self::{dynamic::*, element::*};
Expand Down
6 changes: 3 additions & 3 deletions reffect/src/addon/ui/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
context::Context,
internal::Resources,
internal::{BuffMap, Error, Interface, Internal},
render::colors::{Colored, GREEN, RED},
render::colors::{self, Colored},
};
use nexus::imgui::{StyleColor, Ui, Window};
use reffect_internal::{SkillInfo, Slot, State};
Expand Down Expand Up @@ -163,13 +163,13 @@ impl Addon {
fn debug_result<T>(ui: &Ui, result: Result<&T, &Error>, tooltip: impl FnOnce(&T)) {
match result {
Ok(value) => {
ui.text_colored(GREEN, "available");
ui.text_colored(colors::GREEN, "available");
if ui.is_item_hovered() {
ui.tooltip(|| tooltip(value));
}
}
Err(err) => {
ui.text_colored(RED, "unavailable");
ui.text_colored(colors::RED, "unavailable");
if ui.is_item_hovered() {
ui.tooltip_text(err.to_string());
}
Expand Down
3 changes: 1 addition & 2 deletions reffect/src/addon/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use crate::{
elements::ELEMENT_ID,
internal::Error,
internal::State,
render::colors,
render_util::{next_window_size_constraints, small_padding},
render::{colors, next_window_size_constraints, small_padding},
};
use nexus::imgui::{ChildWindow, StyleVar, Ui};

Expand Down
2 changes: 1 addition & 1 deletion reffect/src/addon/ui/options.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::Addon;
use crate::render_util::{helper, input_u32};
use crate::render::{helper, input_u32};
use nexus::imgui::{TreeNodeFlags, Ui};

impl Addon {
Expand Down
2 changes: 1 addition & 1 deletion reffect/src/elements/anchor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::render_util::{enum_combo, impl_static_variants};
use crate::render::{enum_combo, impl_static_variants};
use nexus::imgui::{ComboBoxFlags, Ui};
use serde::{Deserialize, Serialize};
use strum::{AsRefStr, EnumIter, VariantArray};
Expand Down
3 changes: 1 addition & 2 deletions reffect/src/elements/animation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{
context::Context,
render::RenderOptions,
render_util::{cycle_progress, enum_combo, helper, input_seconds, push_alpha_change},
render::{cycle_progress, enum_combo, helper, input_seconds, push_alpha_change, RenderOptions},
util::non_zero_u32,
};
use nexus::imgui::{ComboBoxFlags, Ui};
Expand Down
10 changes: 4 additions & 6 deletions reffect/src/elements/bar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ use crate::{
action::Action,
context::Context,
render::{
colors::with_alpha_factor, Bounds, ComponentWise, Render, RenderDebug, RenderOptions,
},
render_util::{
enum_combo, helper, helper_slider, input_color_alpha, input_float_with_format,
input_percent, input_percent_inverse, input_positive_with_format, input_size, input_u32,
slider_percent, Rect,
colors::with_alpha_factor, enum_combo, helper, helper_slider, input_color_alpha,
input_float_with_format, input_percent, input_percent_inverse, input_positive_with_format,
input_size, input_u32, slider_percent, Bounds, ComponentWise, Rect, Render, RenderDebug,
RenderOptions,
},
tree::TreeNode,
};
Expand Down
7 changes: 3 additions & 4 deletions reffect/src/elements/bar/props.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::{
context::Context,
elements::PartialProps,
render::{colors, RenderOptions},
render_util::{
input_color_alpha, input_optional, input_percent, input_percent_inverse,
input_positive_with_format,
render::{
colors, input_color_alpha, input_optional, input_percent, input_percent_inverse,
input_positive_with_format, RenderOptions,
},
};
use nexus::imgui::{InputTextFlags, Ui};
Expand Down
7 changes: 3 additions & 4 deletions reffect/src/elements/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ use crate::{
action::ChildElementAction,
context::{Context, EditState},
id::Id,
render::{colors, ComponentWise, RenderDebug, RenderOptions},
render_util::{
helper_slider, input_pos, push_alpha_change, push_window_clip_rect_fullscreen,
slider_percent, EnumStaticVariants, Rect,
render::{
colors, helper_slider, input_pos, push_alpha_change, push_window_clip_rect_fullscreen,
slider_percent, ComponentWise, EnumStaticVariants, Rect, RenderDebug, RenderOptions,
},
serde::migrate,
trigger::ProgressTrigger,
Expand Down
2 changes: 1 addition & 1 deletion reffect/src/elements/direction.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{align::Align, Icon};
use crate::{render::ComponentWise, render_util::Rect};
use crate::{render::ComponentWise, render::Rect};
use serde::{Deserialize, Serialize};
use strum::{AsRefStr, EnumIter, VariantArray};

Expand Down
3 changes: 1 addition & 2 deletions reffect/src/elements/element/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use super::Element;
use crate::{
context::Context,
elements::{Bar, Group, IconElement, IconList, RenderState, Text},
render::{Bounds, Render, RenderDebug, RenderOptions},
render_util::{impl_static_variants, Rect},
render::{impl_static_variants, Bounds, Rect, Render, RenderDebug, RenderOptions},
tree::TreeNode,
};
use nexus::imgui::Ui;
Expand Down
6 changes: 3 additions & 3 deletions reffect/src/elements/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use super::{Animation, Common, RenderState};
use crate::{
action::ElementAction,
context::{Context, EditState},
render::{colors, Bounds, Render, RenderDebug, RenderOptions},
render_util::{
delete_confirm_modal, item_context_menu, style_disabled_if, tree_select_empty, Rect,
render::{
colors, delete_confirm_modal, item_context_menu, style_disabled_if, tree_select_empty,
Bounds, Rect, Render, RenderDebug, RenderOptions,
},
tree::{Loader, TreeNode, VisitMut},
trigger::{FilterTrigger, Trigger},
Expand Down
3 changes: 1 addition & 2 deletions reffect/src/elements/group/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use super::{Element, RenderState};
use crate::{
context::Context,
render::{Bounds, Render, RenderDebug, RenderOptions},
render_util::Rect,
render::{Bounds, Rect, Render, RenderDebug, RenderOptions},
tree::TreeNode,
};
use nexus::imgui::Ui;
Expand Down
3 changes: 1 addition & 2 deletions reffect/src/elements/icon/element.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use super::{Icon, RenderState};
use crate::{
context::Context,
render::{Bounds, Render, RenderDebug, RenderOptions},
render_util::{input_size, Rect},
render::{input_size, Bounds, Rect, Render, RenderDebug, RenderOptions},
tree::TreeNode,
};
use nexus::imgui::Ui;
Expand Down
4 changes: 2 additions & 2 deletions reffect/src/elements/icon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use crate::{
context::Context,
render::{
colors::{self, with_alpha, with_alpha_factor},
ComponentWise, RenderDebug, RenderOptions,
debug_optional, draw_spinner_bg, draw_text_bg, ComponentWise, Rect, RenderDebug,
RenderOptions,
},
render_copy_field,
render_util::{debug_optional, draw_spinner_bg, draw_text_bg, Rect},
settings::icon::{DurationBarSettings, DurationTextSettings, StackTextSettings},
trigger::{ProgressActive, ProgressValue, Skill},
};
Expand Down
9 changes: 4 additions & 5 deletions reffect/src/elements/icon/props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ use crate::{
action::DynAction,
context::Context,
elements::PartialProps,
render::{colors, RenderOptions},
render_copy_field,
render_util::{
helper, input_color_alpha, input_optional, input_percent_inverse,
input_positive_with_format, slider_percent_capped,
render::{
colors, helper, input_color_alpha, input_optional, input_percent_inverse,
input_positive_with_format, slider_percent_capped, RenderOptions,
},
render_copy_field,
};
use nexus::imgui::{InputTextFlags, Ui};
use partial::Partial;
Expand Down
2 changes: 1 addition & 1 deletion reffect/src/elements/icon/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
addon::Addon,
context::Context,
lockbox::Lockbox,
render_util::{enum_combo, impl_static_variants, input_text_simple_menu, Validation},
render::{enum_combo, impl_static_variants, input_text_simple_menu, Validation},
texture_manager::TextureManager,
trigger::Skill,
};
Expand Down
3 changes: 1 addition & 2 deletions reffect/src/elements/list/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use crate::{
action::DynAction,
context::Context,
elements::{Common, Element, ElementType, Icon, IconElement, RenderState},
render::{RenderDebug, RenderOptions},
render_util::Rect,
render::{Rect, RenderDebug, RenderOptions},
trigger::{FilterTrigger, ProgressTrigger, Trigger},
};
use nexus::imgui::Ui;
Expand Down
8 changes: 4 additions & 4 deletions reffect/src/elements/list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use super::{Direction, RenderState};
use crate::{
action::DynAction,
context::Context,
render::{colors, Bounds, Render, RenderDebug, RenderOptions},
render_util::{
collapsing_header_same_line_end, delete_confirm_modal, enum_combo, input_float_with_format,
input_size, item_context_menu, style_disabled_if, Rect,
render::{
collapsing_header_same_line_end, colors, delete_confirm_modal, enum_combo,
input_float_with_format, input_size, item_context_menu, style_disabled_if, Bounds, Rect,
Render, RenderDebug, RenderOptions,
},
tree::TreeNode,
};
Expand Down
7 changes: 3 additions & 4 deletions reffect/src/elements/pack/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use super::{Anchor, Common, Element, ScreenAnchor};
use crate::{
context::{Context, EditState},
render::{colors, Bounds, RenderDebug, RenderOptions},
render_util::{
delete_confirm_modal, item_context_menu, style_disabled, style_disabled_if,
tree_select_empty,
render::{
colors, delete_confirm_modal, item_context_menu, style_disabled, style_disabled_if,
tree_select_empty, Bounds, RenderDebug, RenderOptions,
},
schema::Schema,
tree::{FontReloader, Loader, TreeNode, VisitMut},
Expand Down
3 changes: 1 addition & 2 deletions reffect/src/elements/props.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::{
action::{Action, DynAction},
context::Context,
render::colors,
render_util::{collapsing_header_same_line_end, delete_confirm_modal},
render::{collapsing_header_same_line_end, colors, delete_confirm_modal},
trigger::{Condition, ProgressActive},
};
use nexus::imgui::{CollapsingHeader, Direction, StyleColor, TreeNodeFlags, Ui};
Expand Down
5 changes: 1 addition & 4 deletions reffect/src/elements/text/decoration.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
render::ComponentWise,
render_util::{draw_text_bg, enum_combo, helper_warn},
};
use crate::render::{draw_text_bg, enum_combo, helper_warn, ComponentWise};
use nexus::imgui::{ComboBoxFlags, Ui};
use serde::{Deserialize, Serialize};
use strum::{AsRefStr, EnumIter, VariantArray};
Expand Down
6 changes: 3 additions & 3 deletions reffect/src/elements/text/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use super::{align::AlignHorizontal, Props, RenderState};
use crate::{
context::{Context, ContextUpdate},
fmt::Unit,
render::{Bounds, ComponentWise, Render, RenderDebug, RenderOptions},
render_util::{
debug_optional, draw_text_bg, helper, input_text_multi_with_menu, LoadedFont, Rect,
render::{
debug_optional, draw_text_bg, helper, input_text_multi_with_menu, Bounds, ComponentWise,
LoadedFont, Rect, Render, RenderDebug, RenderOptions,
},
tree::TreeNode,
trigger::{ProgressActive, ProgressValue},
Expand Down
3 changes: 1 addition & 2 deletions reffect/src/elements/text/props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use super::TextDecoration;
use crate::{
context::Context,
elements::PartialProps,
render::{colors, RenderOptions},
render_util::{input_color_alpha, input_optional, input_percent},
render::{colors, input_color_alpha, input_optional, input_percent, RenderOptions},
};
use nexus::imgui::Ui;
use partial::Partial;
Expand Down
1 change: 0 additions & 1 deletion reffect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ mod internal;
mod interval;
mod lockbox;
mod render;
mod render_util;
mod schema;
mod serde;
mod settings;
Expand Down
8 changes: 8 additions & 0 deletions reffect/src/render/animation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use nexus::imgui::Ui;
use std::num::NonZero;

pub fn cycle_progress(ui: &Ui, period_ms: NonZero<u32>) -> f32 {
let time = (1000.0 * ui.time()) as u32;
let passed = time % period_ms;
passed as f32 / period_ms.get() as f32
}
7 changes: 2 additions & 5 deletions reffect/src/render/bounds.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use super::ComponentWise;
use crate::{
context::Context,
render_util::{Point, Rect},
};
use super::{ComponentWise, Point, Rect};
use crate::context::Context;
use nexus::imgui::Ui;

/// UI element bounds.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::style_disabled;
use super::style::style_disabled;
use crate::render::{colors::TRANSPARENT, ComponentWise};
use nexus::imgui::{StyleColor, Ui};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ where
/// Helper to implement [`EnumStaticVariants`] for enums already implementing [`IntoEnumIterator`].
macro_rules! impl_static_variants {
($ty:ty) => {
impl $crate::render_util::EnumStaticVariants for $ty {
impl $crate::render::EnumStaticVariants for $ty {
fn with_variants<R>(action: impl FnOnce(&[Self]) -> R) -> R {
use ::std::thread_local;
use ::strum::IntoEnumIterator;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
30 changes: 28 additions & 2 deletions reffect/src/render/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
mod animation;
mod bounds;
pub mod colors;
mod button;
mod combo;
mod component_wise;
mod draw_list;
mod font;
mod helper;
mod input;
mod input_color;
mod input_text;
mod map_ids;
mod popup;
mod slider;
mod spinner;
mod style;
mod text;
mod tree;
mod window;

pub mod colors;

pub use self::{bounds::*, component_wise::*};
pub use self::{
animation::*, bounds::*, button::*, combo::*, component_wise::*, draw_list::*, font::*,
helper::*, input::*, input_color::*, input_text::*, map_ids::*, popup::*, slider::*,
spinner::*, style::*, text::*, tree::*, window::*,
};

use crate::{context::Context, elements::RenderState};
use nexus::imgui::Ui;

pub type Point = [f32; 2];

pub type Rect = (Point, Point);

/// Render UI element.
pub trait Render<T = ()> {
/// Renders the UI element.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions reffect/src/render/window.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use nexus::imgui::sys;
use std::ptr;

pub fn next_window_size_constraints(size_min: [f32; 2], size_max: [f32; 2]) {
unsafe {
sys::igSetNextWindowSizeConstraints(size_min.into(), size_max.into(), None, ptr::null_mut())
}
}
Loading

0 comments on commit 754329e

Please sign in to comment.