mirror of
https://github.com/ocornut/imgui.git
synced 2026-01-11 00:04:24 +00:00
Selectable: added ImGuiSelectableFlags_Highlight flag to highlight items independently from the hovered state. (#7820)
Demo: Make the Widget/List boxes show how to use forced highlighting.
This commit is contained in:
parent
96460a8a12
commit
c7b9256097
4 changed files with 28 additions and 15 deletions
|
|
@ -1357,18 +1357,18 @@ static void ShowDemoWindowWidgets(DemoWindowData* demo_data)
|
|||
// (your selection data could be an index, a pointer to the object, an id for the object, a flag intrusively
|
||||
// stored in the object itself, etc.)
|
||||
const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK", "LLLLLLL", "MMMM", "OOOOOOO" };
|
||||
static int item_current_idx = 0; // Here we store our selection data as an index.
|
||||
static int item_selected_idx = 0; // Here we store our selection data as an index.
|
||||
|
||||
// Pass in the preview value visible before opening the combo (it could technically be different contents or not pulled from items[])
|
||||
const char* combo_preview_value = items[item_current_idx];
|
||||
const char* combo_preview_value = items[item_selected_idx];
|
||||
|
||||
if (ImGui::BeginCombo("combo 1", combo_preview_value, flags))
|
||||
{
|
||||
for (int n = 0; n < IM_ARRAYSIZE(items); n++)
|
||||
{
|
||||
const bool is_selected = (item_current_idx == n);
|
||||
const bool is_selected = (item_selected_idx == n);
|
||||
if (ImGui::Selectable(items[n], is_selected))
|
||||
item_current_idx = n;
|
||||
item_selected_idx = n;
|
||||
|
||||
// Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
|
||||
if (is_selected)
|
||||
|
|
@ -1410,14 +1410,22 @@ static void ShowDemoWindowWidgets(DemoWindowData* demo_data)
|
|||
// (your selection data could be an index, a pointer to the object, an id for the object, a flag intrusively
|
||||
// stored in the object itself, etc.)
|
||||
const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK", "LLLLLLL", "MMMM", "OOOOOOO" };
|
||||
static int item_current_idx = 0; // Here we store our selection data as an index.
|
||||
static int item_selected_idx = 0; // Here we store our selected data as an index.
|
||||
|
||||
static bool item_highlight = false;
|
||||
int item_highlighted_idx = -1; // Here we store our highlighted data as an index.
|
||||
ImGui::Checkbox("Highlight hovered item in second listbox", &item_highlight);
|
||||
|
||||
if (ImGui::BeginListBox("listbox 1"))
|
||||
{
|
||||
for (int n = 0; n < IM_ARRAYSIZE(items); n++)
|
||||
{
|
||||
const bool is_selected = (item_current_idx == n);
|
||||
const bool is_selected = (item_selected_idx == n);
|
||||
if (ImGui::Selectable(items[n], is_selected))
|
||||
item_current_idx = n;
|
||||
item_selected_idx = n;
|
||||
|
||||
if (item_highlight && ImGui::IsItemHovered())
|
||||
item_highlighted_idx = n;
|
||||
|
||||
// Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
|
||||
if (is_selected)
|
||||
|
|
@ -1433,9 +1441,10 @@ static void ShowDemoWindowWidgets(DemoWindowData* demo_data)
|
|||
{
|
||||
for (int n = 0; n < IM_ARRAYSIZE(items); n++)
|
||||
{
|
||||
const bool is_selected = (item_current_idx == n);
|
||||
if (ImGui::Selectable(items[n], is_selected))
|
||||
item_current_idx = n;
|
||||
bool is_selected = (item_selected_idx == n);
|
||||
ImGuiSelectableFlags flags = (item_highlighted_idx == n) ? ImGuiSelectableFlags_Highlight : 0;
|
||||
if (ImGui::Selectable(items[n], is_selected, flags))
|
||||
item_selected_idx = n;
|
||||
|
||||
// Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
|
||||
if (is_selected)
|
||||
|
|
@ -1482,8 +1491,8 @@ static void ShowDemoWindowWidgets(DemoWindowData* demo_data)
|
|||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
IMGUI_DEMO_MARKER("Widgets/Selectables/In columns");
|
||||
if (ImGui::TreeNode("In columns"))
|
||||
IMGUI_DEMO_MARKER("Widgets/Selectables/In Tables");
|
||||
if (ImGui::TreeNode("In Tables"))
|
||||
{
|
||||
static bool selected[10] = {};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue