Skip to content

Commit 1ad7c0f

Browse files
committed
use selectable instead of menu_item
1 parent 27bed10 commit 1ad7c0f

1 file changed

Lines changed: 19 additions & 18 deletions

File tree

fastplotlib/layouts/ui/right_click_menus/_imgui_colormap_picker.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import ctypes
33

44
import numpy as np
5+
import cmap
56

67
import wgpu
78
from imgui_bundle import imgui
@@ -11,9 +12,6 @@
1112
from ....utils import colormaps
1213

1314

14-
cmap_paths = sorted(Path(colormaps.__file__).absolute().parent.glob("*"))
15-
16-
1715
# TODO: create and upload textures only once per Figure
1816
class ColormapPicker(Popup):
1917
name = "colormap-picker"
@@ -29,17 +27,18 @@ def __init__(self, figure):
2927
self._textures = list()
3028

3129
# make all colormaps and upload representative texture for each to the GPU
32-
for path in cmap_paths:
33-
if not path.is_file():
30+
for name in sorted(cmap.Catalog().short_keys()):
31+
colormap = cmap.Colormap(name)
32+
# qualitative colormap, only show quantitative cmaps in this picker
33+
if colormap.interpolation == "nearest":
3434
continue
3535

36-
data = np.loadtxt(path).T
36+
data = colormap(np.linspace(0, 1)) * 255
37+
3738
data = np.vstack([[data]] * 2).astype(np.uint8)
3839
if data.size < 1:
3940
continue # skip any files that are not cmaps in here
4041

41-
name = path.name
42-
4342
self._texture_ids[name], texture = self._create_texture_and_upload(data)
4443
self._textures.append(texture)
4544

@@ -103,36 +102,38 @@ def update(self):
103102
# new popup has been triggered by a LUT tool
104103
self._open_new = False
105104

106-
imgui.set_next_window_pos(self._pos, imgui.Cond_.appearing)
105+
imgui.set_next_window_pos(self._pos)
107106
imgui.open_popup("cmap-picker")
108107

109108
if imgui.begin_popup("cmap-picker"):
109+
self.set_event_filter("cmap-picker-filter")
110+
110111
texture_height = (
111112
self.imgui_renderer.backend.io.font_global_scale
112113
* imgui.get_font().font_size
113114
) - 2
114115

115116
self.is_open = True
116-
if imgui.menu_item("reset vmin-vmax", None, False)[0]:
117+
if imgui.menu_item("Reset vmin-vmax", None, False)[0]:
117118
self._lut_tool.image_graphic.reset_vmin_vmax()
118119

120+
imgui.separator()
121+
119122
for cmap_name, texture_id in self._texture_ids.items():
120-
clicked, selected = imgui.menu_item(
121-
label=cmap_name,
122-
shortcut=None,
123-
p_selected=self._lut_tool.cmap == cmap_name,
123+
imgui.image(
124+
texture_id, image_size=(50, texture_height), border_col=(1, 1, 1, 1)
124125
)
125126

126127
imgui.same_line()
127-
imgui.image(
128-
texture_id, image_size=(50, texture_height), border_col=(1, 1, 1, 1)
128+
129+
clicked, selected = imgui.selectable(
130+
label=cmap_name,
131+
p_selected=cmap_name == self._lut_tool.cmap,
129132
)
130133

131134
if clicked and selected:
132135
self._lut_tool.cmap = cmap_name
133136

134-
self.set_event_filter("cmap-picker-filter")
135-
136137
imgui.end_popup()
137138

138139
else:

0 commit comments

Comments
 (0)