Skip to content

Commit

Permalink
ImGui widgets record their dimensions, invalidate lower uis
Browse files Browse the repository at this point in the history
The invalidation logic is already there, we just have to set the
`dimensions` so that it knows what we drew over.
  • Loading branch information
db48x authored and katemonster33 committed Feb 25, 2024
1 parent f0ae4ea commit a0e1e55
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/cata_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,22 @@ void cataimgui::client::process_input( void *input )

#endif

void cataimgui::point_to_imvec2( point *src, ImVec2 *dest )
{
if( src != nullptr && dest != nullptr ) {
dest->x = src->x;
dest->y = src->y;
}
}

void cataimgui::imvec2_to_point( ImVec2 *src, point *dest )
{
if( src != nullptr && dest != nullptr ) {
dest->x = src->x;
dest->y = src->y;
}
}

void cataimgui::window::draw_colored_text( std::string const &text, const nc_color &color,
float wrap_width, bool *is_selected, bool *is_focused, bool *is_hovered )
{
Expand Down Expand Up @@ -303,6 +319,13 @@ class cataimgui::window_impl
window_adaptor->is_imgui = true;
window_adaptor->on_redraw( [this]( ui_adaptor & ) {
win_base->draw();
point catapos;
point catasize;
ImVec2 impos = ImGui::GetWindowPos();
ImVec2 imsize = ImGui::GetWindowSize();
imvec2_to_point( &impos, &catapos );
imvec2_to_point( &imsize, &catasize );
window_adaptor->position( catapos, catasize );
} );
window_adaptor->on_screen_resize( [this]( ui_adaptor & ) {
is_resized = true;
Expand Down
6 changes: 6 additions & 0 deletions src/cata_imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ struct SDL_Renderer;
struct SDL_Window;
#endif

struct point;
class ImVec2;

namespace cataimgui
{
struct bounds {
Expand Down Expand Up @@ -55,6 +58,9 @@ class client
#endif
};

void point_to_imvec2( point *src, ImVec2 *dest );
void imvec2_to_point( ImVec2 *src, point *dest );

class window
{
std::unique_ptr<class window_impl> p_impl;
Expand Down
1 change: 1 addition & 0 deletions src/third-party/imgui/imconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \
operator MyVec4() const { return MyVec4(x,y,z,w); }
*/

//---- ...Or use Dear ImGui's own very basic math operators.
//#define IMGUI_DEFINE_MATH_OPERATORS

Expand Down

0 comments on commit a0e1e55

Please sign in to comment.