Giter VIP home page Giter VIP logo

Comments (5)

lukaasm avatar lukaasm commented on July 17, 2024 1

use ImGui::SetNextItemAllowOverlap() before selectable

When multiple widgets fight over same interactive air-space ( selectable and button in this case ), first one that is encountered consumes action by default( selectable ). You can change this behaviour by allowing overlap on item that consumed your actions with side-effect that click action will be delayed by a frame

from imgui.

lukaasm avatar lukaasm commented on July 17, 2024 1

Do you know what makes my code special? This doesn't seem to be used in the advanced table demo.

Because in Advanced table demo Selectable is submited with: ImGuiSelectableFlags_AllowOverlap flag which enables same behaviour as calling ImGui::SetNextItemAllowOverlap()

ImGuiSelectableFlags selectable_flags = (contents_type == CT_SelectableSpanRow) ? ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowOverlap : ImGuiSelectableFlags_None;
if (ImGui::Selectable(label, item_is_selected, selectable_flags, ImVec2(0, row_min_height)))

from imgui.

leidegre avatar leidegre commented on July 17, 2024

I could be completely wrong here and there's ofcourse something I'm doing that's wrong with the selectable row. Seems like it's eating the click or something. I can only get it to work if I get a button on a different line.

Here's the complete code for the table.

void game::show_data_explorer_debug_window(Game_State* state) {
  if (!ImGui::Begin("Data Explorer", &state->tools_.data_explorer_.show_)) {
    ImGui::End();
    return; // early out
  }

  auto table_flags = ImGuiTableFlags_ScrollY | ImGuiTableFlags_RowBg;
  auto table_outer_size = ImVec2(0.0f, ImGui::GetTextLineHeightWithSpacing() * 8);

  static ImGuiTextFilter filter;
  
  filter.Draw();
  // ImGui::SameLine();
  if (ImGui::Button("Clear")) {
    filter.Clear();
  }

  // todo: scratch allocator
  List<int> filtered = { .allocator_ = state->frame_allocator_ };
  defer (filtered.destroy());
  for (int i = 0; i < (int)Asset_Table_Size; i += 1) {
    const Asset& asset = Asset_Table[i];
    if (filter.PassFilter(asset.path_.begin(), asset.path_.end())) {
      filtered.add(i);
    }
  }
  
  if (ImGui::BeginTable("Assets Table", 2, table_flags, table_outer_size)) {
    ImGui::TableSetupScrollFreeze(0, 1);
    ImGui::TableSetupColumn("Path", ImGuiTableColumnFlags_None, 0, 0);
    ImGui::TableSetupColumn("Mem", ImGuiTableColumnFlags_WidthFixed, 100, 1);
    ImGui::TableHeadersRow();

    ImGuiListClipper clipper;
    clipper.Begin((int)filtered.size());
    while (clipper.Step())
    {
        for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; row++)
        {
            auto& asset = Asset_Table[filtered[row]];

            ImGui::PushID(row);
            ImGui::TableNextRow();

            ImGui::TableSetColumnIndex(0);
            
            bool is_selected = state->tools_.data_explorer_.selected_asset_ == &asset;
            if (ImGui::Selectable(asset.path_.begin(), &is_selected, ImGuiSelectableFlags_SpanAllColumns)) {
              state->tools_.data_explorer_.selected_asset_ = &asset;
            }

            // don't know if we need these, maybe it's enough to just do filename
            ImGui::TableSetColumnIndex(1);
            ImGui::Text("%zu", asset.data_.size()); // Size of this asset in memory, if it is zero then it is not loaded.
            
            // Does not work, will render button non-interactable.
            ImGui::SameLine();

            if (0 < asset.data_.size()) {
              if (ImGui::SmallButton("Reload")) { 
                // ...
              }              
            } else {
              if (ImGui::SmallButton("Load")) { 
                OR_ABORT(load_asset(&asset));
              }
            }

            ImGui::PopID();
        }
    }

    ImGui::EndTable();
  }

  ImGui::End();
}

from imgui.

leidegre avatar leidegre commented on July 17, 2024

Tried 1.90.8 unfortunately it didn't fix my issue.

from imgui.

leidegre avatar leidegre commented on July 17, 2024

use ImGui::SetNextItemAllowOverlap() before selectable

@lukaasm Great, thanks this works 👍Do you know what makes my code special? This doesn't seem to be used in the advanced table demo.

from imgui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.