def draw_table(data, *selected_row): imgui.columns(len(data.columns) + 1, "##table") imgui.separator() imgui.text("") imgui.next_column() for c in data.columns: imgui.text(c) imgui.next_column() imgui.separator() # fill with data i = 0 for _, row in data.iterrows(): label = str(i) clicked, _ = imgui.selectable(label=label, selected=selected_row == i, flags=imgui.SELECTABLE_SPAN_ALL_COLUMNS, ) if clicked: selected_row = i hovered = imgui.is_item_hovered() imgui.next_column() for c in data.columns: imgui.text(row[c]) imgui.next_column() i += 1
def draw_list(id_str, label, items, select_item, delete_callback=None): imgui.begin_child(id_str) imgui.text(label) cur_state.hovered_item = None for idx, item in enumerate(items): cur_id_str = "##list_{}_{}".format(id_str, idx) sel_btn_id = "Select {} {}".format(idx, cur_id_str) del_btn_id = "X{}".format(cur_id_str) imgui.begin_group() if imgui.button(sel_btn_id): print("clicked {}".format(idx)) select_item(idx) imgui.same_line() imgui.text(str(item)) if delete_callback is not None: imgui.same_line() if imgui.button(del_btn_id): delete_callback(item) print("delete!!") imgui.end_group() if imgui.is_item_hovered(): cur_state.hovered_item = item imgui.end_child()
def render_unsaved_exit(window): "Popup to prevent exiting the application with unsaved work." if window.exit_unsaved_drawings: imgui.open_popup("Really exit?") imgui.set_next_window_size(500, 200) if imgui.begin_popup_modal("Really exit?")[0]: imgui.text("You have unsaved work in these drawing(s):") imgui.begin_child("unsaved", border=True, height=imgui.get_content_region_available()[1] - 26) for drawing in window.exit_unsaved_drawings: imgui.text(drawing.filename) if imgui.is_item_hovered(): pass # TODO popup thumbnail of the picture? imgui.end_child() if imgui.button("Yes, exit anyway"): imgui.close_current_popup() pyglet.app.exit() imgui.same_line() if imgui.button("Yes, but save first"): for drawing in window.exit_unsaved_drawings: window.save_drawing(drawing) pyglet.app.exit() imgui.same_line() if imgui.button("No, cancel"): window.exit_unsaved_drawings = None imgui.close_current_popup() imgui.end_popup()
def _show_custom_ui(self): if self.shader_error is None: return imgui.dummy(1, 5) imgui.text_colored("Shader error. (?)", 1.0, 0.0, 0.0) if imgui.is_item_hovered(): imgui.set_tooltip(self.shader_error)
def _show(self, value, read_only): imgui.push_item_width(self.width) changed, v = imgui.input_text("", value.value, 255, imgui.INPUT_TEXT_ENTER_RETURNS_TRUE) if imgui.is_item_hovered() and not imgui.is_item_active(): imgui.set_tooltip(value.value) if changed: value.value = v
def _image_impl( image_and_ajustments, width=None, height=None, title="", always_refresh = False, linked_user_image_address: ImageAddress = 0 ): statics = _image_impl.statics statics.last_shown_image = image_and_ajustments zoom_key = imgui_ext.make_unique_label(title) if zoom_key not in statics.zoomed_status: statics.zoom_click_times[zoom_key] = 0 statics.zoomed_status[zoom_key] = False if statics.zoomed_status[zoom_key]: viewport_size = SizePixel.from_image(image_and_ajustments.image) else: viewport_size = _image_viewport_size(image_and_ajustments.image, width, height) if zoom_key not in statics.zoomed_status: statics.zoomed_status[zoom_key] = False statics.zoom_click_times[zoom_key] = timer() texture_id = _image_to_texture( image_and_ajustments, always_refresh = always_refresh, linked_user_image_address=linked_user_image_address ) if title == "": imgui.image_button(texture_id, viewport_size.width, viewport_size.height, frame_padding=0) is_mouse_hovering = imgui.is_item_hovered() else: imgui.begin_group() imgui.image_button(texture_id, viewport_size.width, viewport_size.height, frame_padding=0) is_mouse_hovering = imgui.is_item_hovered() imgui.text(title) imgui.end_group() if is_mouse_hovering and imgui.get_io().mouse_down[0]: last_time = statics.zoom_click_times[zoom_key] now = timer() if now - last_time > 0.3: statics.zoomed_status[zoom_key] = not statics.zoomed_status[zoom_key] statics.zoom_click_times[zoom_key] = now return mouse_position_last_image()
def draw_logs(self): imgui.push_style_var(imgui.STYLE_WINDOW_PADDING, (6, 6)) cur_style = imgui.get_style() padding = cur_style.window_padding cur_cursor_pos = imgui.get_cursor_pos() imgui.set_cursor_pos( (cur_cursor_pos[0] + padding[0], cur_cursor_pos[1] + padding[1])) imgui.begin_child(self.ID_CHILD_CONSOLE, self.width - cur_style.window_padding[0] * 2, self.height - 80, True) search_text = self.config.get_string(EConfigKey.CONTENT_SEARCH_TEXT) win_width = imgui.get_window_width() for idx, record in enumerate(self.log_mgr.log_lst): if not self.config.is_has_log_level(record.level): continue if not utils.filter_search_text(search_text, record): continue old_color = None if record.level == logging.ERROR: old_color = utils.set_style_color(imgui.COLOR_TEXT, TextColor.ERed) elif record.level == logging.WARN or record.level == logging.WARNING: old_color = utils.set_style_color(imgui.COLOR_TEXT, TextColor.EYellow) elif record.level == logging.INFO: old_color = utils.set_style_color(imgui.COLOR_TEXT, TextColor.EWhite) imgui.push_id(str(idx)) ret = imgui.selectable_wrap(record.msg_with_level, idx == self.sel_idx, imgui.SELECTABLE_ALLOW_DOUBLE_CLICK, win_width * 0.98, 30) if ret[1]: self.sel_idx = idx if imgui.is_item_hovered() and imgui.is_mouse_double_clicked(0): self.detail_idx = idx imgui.open_popup("detail_log_%d" % self.detail_idx) self.draw_log_detail_info_panel(idx, record) if old_color: utils.set_style_color(imgui.COLOR_TEXT, old_color) imgui.pop_id() if imgui.is_mouse_dragging() or imgui.get_io().mouse_wheel: if imgui.get_scroll_y() >= imgui.get_scroll_max_y(): self.config.set_bool(EConfigKey.CONTENT_SCROLL_TO_BOTTOM, True) else: self.config.set_bool(EConfigKey.CONTENT_SCROLL_TO_BOTTOM, False) is_to_bottom = self.config.get_bool( EConfigKey.CONTENT_SCROLL_TO_BOTTOM, True) if is_to_bottom: imgui.set_scroll_y(imgui.get_scroll_max_y()) imgui.end_child() imgui.pop_style_var()
def _show_custom_ui(self): imgui.dummy(1, 5) imgui.text("lambda x:") imgui.push_item_width(208) changed, text = imgui.input_text("", self.get("lambda"), 255, imgui.INPUT_TEXT_ENTER_RETURNS_TRUE) if changed: self.get_input("lambda").value = text if self.compile_error is not None: imgui.text_colored("Compilation error. (?)", 1.0, 0.0, 0.0) if imgui.is_item_hovered(): imgui.set_tooltip(self.compile_error) elif self.run_error is not None: imgui.text_colored("Runtime error. (?)", 1.0, 0.0, 0.0) if imgui.is_item_hovered(): imgui.set_tooltip(self.run_error) else: imgui.text("Lambda compiled.")
def show(self, value, read_only): clicked, self.show_texture = imgui.checkbox("Show", self.show_texture) if not self.show_texture: return texture = value.value if texture is None: self.texture_aspect = None else: h, w, _ = texture.shape self.texture_aspect = w / h cursor_pos = imgui.get_cursor_screen_pos() imgui.set_next_window_size(500, 500, imgui.ONCE) imgui.set_next_window_size_constraints((0.0, 0.0), (float("inf"), float("inf")), self.window_size_callback) imgui.set_next_window_position(*imgui.get_io().mouse_pos, imgui.ONCE, pivot_x=0.5, pivot_y=0.5) expanded, opened = imgui.begin( "Texture of %s###%s%s" % (self.node.spec.name, id(self.node), id(self)), True, imgui.WINDOW_NO_SCROLLBAR) if not opened: self.show_texture = False if expanded: if texture is None: imgui.text("No texture associated") else: # [::-1] reverses list texture_size = texture.shape[:2][::-1] texture_aspect = texture_size[0] / texture_size[1] window_size = imgui.get_content_region_available() imgui.image(texture._handle, window_size[0], window_size[0] / texture_aspect) if imgui.is_item_hovered() and imgui.is_mouse_clicked(1): # little hack to have first context menu entry under cursor io = imgui.get_io() pos = io.mouse_pos io.mouse_pos = pos[0] - 20, pos[1] - 20 imgui.open_popup("context") io.mouse_pos = pos if imgui.begin_popup("context"): if imgui.menu_item("save")[0]: util.image.save_screenshot(texture.get()) imgui.menu_item("texture handle: %s" % texture._handle, None, False, False) imgui.menu_item("texture dtype: %s" % str(texture.dtype), None, False, False) imgui.menu_item("texture shape: %s" % str(texture.shape), None, False, False) imgui.end_popup() imgui.end()
def _show_custom_ui(self): imgui.push_item_width(widget.WIDGET_WIDTH) if self.duplicate: imgui.push_style_color(imgui.COLOR_TEXT, 1.0, 0.0, 0.0) changed, v = imgui.input_text("", self.get("name"), 255, imgui.INPUT_TEXT_ENTER_RETURNS_TRUE) if self.duplicate: imgui.pop_style_color() if imgui.is_item_hovered(): imgui.set_tooltip("Name is a duplicate!") if changed: self.name = v
def draw(self): imgui.begin("Example: tooltip") imgui.button("Click me!") if imgui.is_item_hovered(): imgui.begin_tooltip() imgui.text("This button is clickable.") imgui.text("This button has full window tooltip.") texture_id = imgui.get_io().fonts.texture_id imgui.image(texture_id, 512, 64, border_color=(1, 0, 0, 1)) imgui.end_tooltip() imgui.end()
def text_tooltip(text, widget): """Display a text tooltip on hover""" while True: try: imgui.begin_group() next(widget) except StopIteration as e: return e.value finally: imgui.end_group() if imgui.is_item_hovered(): imgui.set_tooltip(text) yield
def render(self): imgui.begin_group() imgui.text(self.percentLeft) if self.battery.power_plugged: imgui.text_colored("I", *theme.color("battery_charging", "success")) imgui.end_group() if imgui.is_item_hovered(): imgui.begin_tooltip() if not self.battery.power_plugged: imgui.text(f"{self.timeLeft}") else: imgui.text("Battery is charging") imgui.end_tooltip()
def render_tools(tools, icons): current_tool = tools.current selected = False for i, tool in enumerate(tools): texture = icons[tool.tool.name] with imgui.colored(imgui.COLOR_BUTTON, *TOOL_BUTTON_COLORS[tool == current_tool]): if imgui.image_button(texture.name, 16, 16): tools.select(tool.tool) selected = True if i % 3 != 2 and not i == len(tools) - 1: imgui.same_line() if imgui.is_item_hovered(): imgui.begin_tooltip() imgui.text(tool.tool.name.lower()) imgui.end_tooltip() return selected
def _show(self, value, read_only): imgui.push_item_width(self.width) changed, v = imgui.input_text("", value.value, 255, imgui.INPUT_TEXT_ENTER_RETURNS_TRUE) if imgui.is_item_hovered() and not imgui.is_item_active(): imgui.set_tooltip(value.value) if changed: value.value = v return imgui.push_item_width(self.width) if imgui.button("Select file"): imgui.open_popup("select_file") path = imgui_pick_file("select_file", assets.ASSET_PATH + "/" + self.prefix) if path is not None: value.value = os.path.relpath(path, assets.ASSET_PATH)
def zoomtip(imtex, imdim, mag=1.0): if imgui.is_item_hovered(): w, h = imgui.get_window_size() h = imdim[0] * w / imdim[1] rectmin = imgui.get_item_rect_min() mousepos = imgui.get_mouse_pos() u = float(mousepos[0] - rectmin[0]) / w v = float(mousepos[1] - rectmin[1]) / h imgui.begin_tooltip() tw = 32. / imdim[1] / mag th = 32. / imdim[0] / mag imgui.image(imtex, 64, 64, uv0=(u - tw, v - th), uv1=(u + tw, v + th)) dl = imgui.get_window_draw_list() rm = imgui.get_item_rect_min() col = imgui.get_color_u32_rgba(1, 1, 0, 1) dl.add_line(rm[0], rm[1] + 32, rm[0] + 64, rm[1] + 32, col) dl.add_line(rm[0] + 32, rm[1], rm[0] + 32, rm[1] + 64, col) imgui.end()
def tooltip(tooltip_widget, widget): """ Display a widget tooltip on hover. May contain arbitrary elements, such as images. """ while True: try: imgui.begin_group() next(widget) except StopIteration as e: return e.value finally: imgui.end_group() if imgui.is_item_hovered(): try: imgui.begin_tooltip() next(tooltip_widget) except StopIteration as e: return e.value finally: imgui.end_tooltip() yield
def draw(self): imgui.new_frame() imgui.set_next_window_position(16, 32, imgui.ONCE) imgui.set_next_window_size(512, 512, imgui.ONCE) imgui.begin("Example: tooltip") imgui.button("Click me!") if imgui.is_item_hovered(): imgui.begin_tooltip() imgui.text("This button is clickable.") imgui.text("This button has full window tooltip.") texture_id = imgui.get_io().fonts.texture_id imgui.image(texture_id, 512, 64, border_color=(1, 0, 0, 1)) imgui.end_tooltip() imgui.end() imgui.end_frame() imgui.render() self.renderer.render(imgui.get_draw_data())
def image_explorer_impl(im, title=""): # type: (ImageWithZoomInfo, str) -> None """ :return: imgui.Vec2 (mouse_location_original_image) or None (if not on image) """ if im.image.size == 0: imgui.text("empty image !") return imgui.Vec2(0, 0) zoomed_image = im.zoomed_image() if not im.hide_buttons: _display_zoom_or_pan_buttons(im) if title != "": imgui.same_line() imgui.text(" " + title) mouse_location = imgui_cv.image(zoomed_image, image_adjustments=im.image_adjustments) mouse_location_original_image = None viewport_center_original_image = im.viewport_center_original_image() if not im.hide_buttons and mouse_location is not None: mouse_drag_button = 0 is_mouse_dragging = imgui.is_mouse_dragging( mouse_drag_button) and imgui.is_item_hovered() drag_delta = imgui.get_mouse_drag_delta(mouse_drag_button) mouse_location_original_image = im.zoom_info.mouse_location_original_image( mouse_location) # Handle dragging / zoom or pan if not is_mouse_dragging: im.zoom_info.last_delta = imgui.Vec2(0, 0) if is_mouse_dragging: drag_delta_delta = imgui.Vec2( drag_delta.x - im.zoom_info.last_delta.x, drag_delta.y - im.zoom_info.last_delta.y) if im.zoom_info.zoom_or_pan == ZoomOrPan.Zoom: k = 1.03 if drag_delta.y < 0: zoom_ratio = k else: zoom_ratio = 1. / k im.zoom_info.affine_transform = np.dot( im.zoom_info.affine_transform, compute_zoom_matrix(mouse_location_original_image, zoom_ratio)) if im.zoom_info.zoom_or_pan == ZoomOrPan.Pan: im.zoom_info.affine_transform = np.dot( im.zoom_info.affine_transform, compute_pan_matrix(drag_delta_delta, im.zoom_info.affine_transform[0, 0])) im.zoom_info.last_delta = drag_delta # Zoom & Pan buttons def perform_zoom(ratio): im.zoom_info.affine_transform = np.dot( im.zoom_info.affine_transform, compute_zoom_matrix(viewport_center_original_image, ratio)) import functools perform_zoom_plus = functools.partial(perform_zoom, 1.25) perform_zoom_minus = functools.partial(perform_zoom, 1. / 1.25) def perform_scale_one(): im.zoom_info.set_scale_one(SizePixel.from_image(im.image), im.current_viewport_size()) def perform_full_view(): im.zoom_info.set_full_view(SizePixel.from_image(im.image), im.current_viewport_size()) def perform_force_viewport_size(): im.set_force_viewport_size(True) def perform_reset_viewport_size(): im.set_force_viewport_size(False) def perform_hide_buttons(): im.hide_buttons = True def perform_show_buttons(): im.hide_buttons = False def show_zoom_button(name, action, same_line=True): if imgui.small_button(imgui_ext.make_unique_label(name)): action() if same_line: imgui.same_line() if im.hide_buttons: show_zoom_button("+", perform_show_buttons, False) imgui.same_line() imgui.text(title) else: show_zoom_button("-", perform_hide_buttons) if not im.hide_buttons: show_zoom_button("zoom +", perform_zoom_plus) show_zoom_button("zoom -", perform_zoom_minus) if im.can_show_big_viewport(): show_zoom_button("scale 1", perform_scale_one) if im.is_not_full_view(): show_zoom_button("full view", perform_full_view) if not im.show_adjustments: if imgui.small_button(imgui_ext.make_unique_label("Adjust")): im.show_adjustments = True # adjustments if im.show_adjustments: imgui.new_line() imgui.text("Adjust:") imgui.same_line() imgui.push_item_width(80) # noinspection PyArgumentList changed, im.image_adjustments.factor = imgui.slider_float( imgui_ext.make_unique_label("k"), im.image_adjustments.factor, 0., 32., display_format="%.3f", power=5.) imgui.same_line() imgui.push_item_width(80) changed, im.image_adjustments.delta = imgui.slider_float( imgui_ext.make_unique_label("delta"), im.image_adjustments.delta, 0., 255., display_format="%.3f", power=5.) imgui.same_line() if not im.image_adjustments.is_none(): if imgui.small_button(imgui_ext.make_unique_label("reset")): im.image_adjustments = imgui_cv.ImageAdjustments() imgui.same_line() if imgui.small_button(imgui_ext.make_unique_label("hide adjust")): im.show_adjustments = False # Show image info image_type_msg = str(im.image.dtype) + str(im.image.shape) zoom = im.zoom_info.affine_transform[0, 0] import math if not _is_close(zoom, 1): zoom_msg = "Zoom:{0:.2f} ".format(zoom) else: zoom_msg = "" msg = zoom_msg + image_type_msg imgui.text(msg) if im.can_show_big_viewport(): imgui.same_line() if im.get_force_viewport_size(): show_zoom_button("reset viewport", perform_reset_viewport_size) else: show_zoom_button("fit viewport", perform_force_viewport_size) imgui.new_line() # Save button # imgui.same_line() imgui.push_item_width(60) changed, im.filename = imgui.input_text( imgui_ext.make_unique_label(""), im.filename, 1000) imgui.same_line() if imgui.small_button(imgui_ext.make_unique_label("save")): cv2.imwrite(im.filename, im.image) # Show pixel color info if mouse_location is not None: color = zoomed_image[int(round(mouse_location.y)), int(round(mouse_location.x))] mouse2 = np.array([[mouse_location.x], [mouse_location.y], [1.]]) pt_original = np.dot( numpy.linalg.inv(im.zoom_info.affine_transform), mouse2) position_msg = "({0},{1})".format(int(round(pt_original[0, 0])), int(round(pt_original[1, 0]))) imgui.text(position_msg + " " + color_msg(color)) else: imgui.text("") return mouse_location_original_image
def tooltip_help(self, txt): if imgui.is_item_hovered(): imgui.begin_tooltip() imgui.text(txt) imgui.end_tooltip()
def update(self): # return done, value do_return = False recipe = '' if self.extra_font: imgui.push_font(self.extra_font) width = 750 height = 250 imgui.set_next_window_size(width, height) imgui.set_next_window_position(self.center_x - width // 2, self.center_y - height // 2) imgui.push_style_var(imgui.STYLE_ALPHA, self.alpha) imgui.begin('Drop', False, flags=self.flags) self.left_label('ID:') xx, self.id = imgui.input_text('\n', self.id, 128) self.tooltip_help('Participant ID/Name') self.add_space(3) self.left_label('Español:') _, self.spanish = imgui.checkbox('', self.spanish) self.tooltip_help('Spanish text for subsequent instructions') self.add_space(3) self.left_label('Recipe:') # current filenames recipe_names = [] recipe_short = [] for file in glob.glob('recipes/**/*.toml', recursive=True): if (os.path.sep + 'defaults' + os.path.sep) not in file: recipe_names.append(file) recipe_short.append(os.path.relpath(file, 'recipes')) changed, self.current_recipe = imgui.combo(' ', self.current_recipe, recipe_short) self.tooltip_help( 'Available recipes (TOML files) in the recipe directory') imgui.same_line() imgui.button('Preview') if imgui.is_item_hovered() and recipe_names: with open(recipe_names[self.current_recipe], 'r') as f: prev = f.read() # width in characters, height in number of newlines if prev: wid = len( max(open(recipe_names[self.current_recipe], 'r'), key=len)) # TODO: need to be careful of newline char?? hei = prev.count('\n') + 1 else: wid = 10 hei = 1 fac = 0.6 font_size = imgui.get_font_size() * fac wid = int(wid * font_size / 2) # get something like pix hei = int(hei * font_size) # if height is >= half the window height, turn to scroll val = hei if hei >= self.center_y: val = self.center_y imgui.begin_tooltip() imgui.begin_child('region', wid, val) imgui.set_scroll_y(imgui.get_scroll_y() - imgui.get_io().mouse_wheel * 30) imgui.set_window_font_scale(fac) imgui.text(prev) imgui.end_child() imgui.end_tooltip() imgui.set_item_default_focus() # imgui.set_tooltip(prev) self.add_space(3) if imgui.button('Ok'): do_return = True if imgui.get_io().keys_down[imgui.KEY_ENTER]: do_return = True imgui.pop_style_var(1) imgui.end() if self.extra_font: imgui.pop_font() # disallow depending on current state if not self.id: do_return = False try: recipe = recipe_names[self.current_recipe] except IndexError: do_return = False if not os.path.isdir(self.recipe_dir): do_return = False # no need to validate data dir, we'll create it data = { 'id': self.id, 'recipe': recipe, 'spanish': 'es' if self.spanish else 'en' } return do_return, data
def frame_commands(): io = imgui.get_io() if io.key_ctrl and io.keys_down[glfw.KEY_Q]: sys.exit(0) with imgui.begin_main_menu_bar() as main_menu_bar: if main_menu_bar.opened: with imgui.begin_menu("File", True) as file_menu: if file_menu.opened: clicked_quit, selected_quit = imgui.menu_item( "Quit", "Ctrl+Q") if clicked_quit: sys.exit(0) # turn examples on/off with imgui.begin("Active examples"): for label, enabled in active.copy().items(): _, enabled = imgui.checkbox(label, enabled) active[label] = enabled if active["window"]: with imgui.begin("Hello, Imgui!"): imgui.text("Hello, World!") if active["child"]: with imgui.begin("Example: child region"): with imgui.begin_child("region", 150, -50, border=True): imgui.text("inside region") imgui.text("outside region") if active["tooltip"]: with imgui.begin("Example: tooltip"): imgui.button("Click me!") if imgui.is_item_hovered(): with imgui.begin_tooltip(): imgui.text("This button is clickable.") if active["menu bar"]: try: flags = imgui.WINDOW_MENU_BAR with imgui.begin("Child Window - File Browser", flags=flags): with imgui.begin_menu_bar() as menu_bar: if menu_bar.opened: with imgui.begin_menu('File') as file_menu: if file_menu.opened: clicked, state = imgui.menu_item('Close') if clicked: active["menu bar"] = False raise Exception except Exception: print("exception handled") if active["popup"]: with imgui.begin("Example: simple popup"): if imgui.button("select"): imgui.open_popup("select-popup") imgui.same_line() with imgui.begin_popup("select-popup") as popup: if popup.opened: imgui.text("Select one") imgui.separator() imgui.selectable("One") imgui.selectable("Two") imgui.selectable("Three") if active["popup modal"]: with imgui.begin("Example: simple popup modal"): if imgui.button("Open Modal popup"): imgui.open_popup("select-popup-modal") imgui.same_line() with imgui.begin_popup_modal("select-popup-modal") as popup: if popup.opened: imgui.text("Select an option:") imgui.separator() imgui.selectable("One") imgui.selectable("Two") imgui.selectable("Three") if active["popup context item"]: with imgui.begin("Example: popup context view"): imgui.text("Right-click to set value.") with imgui.begin_popup_context_item("Item Context Menu") as popup: if popup.opened: imgui.selectable("Set to Zero") if active["popup context window"]: with imgui.begin("Example: popup context window"): with imgui.begin_popup_context_window() as popup: if popup.opened: imgui.selectable("Clear") if active["popup context void"]: with imgui.begin_popup_context_void() as popup: if popup.opened: imgui.selectable("Clear") if active["drag drop"]: with imgui.begin("Example: drag and drop"): imgui.button('source') with imgui.begin_drag_drop_source() as src: if src.dragging: imgui.set_drag_drop_payload('itemtype', b'payload') imgui.button('dragged source') imgui.button('dest') with imgui.begin_drag_drop_target() as dst: if dst.hovered: payload = imgui.accept_drag_drop_payload('itemtype') if payload is not None: print('Received:', payload) if active["group"]: with imgui.begin("Example: item groups"): with imgui.begin_group(): imgui.text("First group (buttons):") imgui.button("Button A") imgui.button("Button B") imgui.same_line(spacing=50) with imgui.begin_group(): imgui.text("Second group (text and bullet texts):") imgui.bullet_text("Bullet A") imgui.bullet_text("Bullet B") if active["tab bar"]: with imgui.begin("Example Tab Bar"): with imgui.begin_tab_bar("MyTabBar") as tab_bar: if tab_bar.opened: with imgui.begin_tab_item("Item 1") as item1: if item1.opened: imgui.text("Here is the tab content!") with imgui.begin_tab_item("Item 2") as item2: if item2.opened: imgui.text("Another content...") global opened_state with imgui.begin_tab_item("Item 3", opened=opened_state) as item3: opened_state = item3.opened if item3.selected: imgui.text("Hello Saylor!") if active["list box"]: with imgui.begin("Example: custom listbox"): with imgui.begin_list_box("List", 200, 100) as list_box: if list_box.opened: imgui.selectable("Selected", True) imgui.selectable("Not Selected", False) if active["table"]: with imgui.begin("Example: table"): with imgui.begin_table("data", 2) as table: if table.opened: imgui.table_next_column() imgui.table_header("A") imgui.table_next_column() imgui.table_header("B") imgui.table_next_row() imgui.table_next_column() imgui.text("123") imgui.table_next_column() imgui.text("456") imgui.table_next_row() imgui.table_next_column() imgui.text("789") imgui.table_next_column() imgui.text("111") imgui.table_next_row() imgui.table_next_column() imgui.text("222") imgui.table_next_column() imgui.text("333")
def render_editor(self): if imgui.button("optimize track"): self.start_optimization() imgui.same_line() _, ks = imgui.slider_float2("kcurv, kdist", self.kcurv, self.kdist, min_value=0, max_value=100.0, power=2) self.kcurv, self.kdist = ks _, self.lanewidth = imgui.slider_float("lane width", self.lanewidth, min_value=10, max_value=1000, power=1.5) # use a child region just to keep appearing/disappearing widgets at the # top from shifting stuff around imgui.begin_child("region", 0, 25, border=False) if (self.editmode == 'turn' and self.selectedpt is not None and self.selectedpt < len(self.pts['turn'])): i = self.selectedpt T = self.pts['turn'] _, T[i][2] = imgui.slider_float("turn %d radius" % (i + 1), T[i][2], min_value=-1000., max_value=1000., power=1.2) if self.editmode == 'home': _, self.homeangle = imgui.slider_float("home position angle", self.homeangle, -3.141, 3.141) imgui.end_child() w, h = imgui.get_window_size() h = self.mapim.shape[0] * w / self.mapim.shape[1] imgui.image_button(self.maptex, w, h, frame_padding=0) rectmin = imgui.get_item_rect_min() if imgui.is_item_clicked(0): mxy = imgui.get_mouse_pos() u = (mxy[0] - rectmin[0]) * self.mapim.shape[1] / w v = (mxy[1] - rectmin[1]) * self.mapim.shape[1] / w if imgui.is_mouse_double_clicked(0): self.add_point(u, v) else: self.select_point(u, v) if (imgui.is_item_hovered() and self.selectedpt is not None and imgui.is_mouse_dragging(0)): mxy = imgui.get_mouse_pos() u = (mxy[0] - rectmin[0]) * self.mapim.shape[1] / w v = (mxy[1] - rectmin[1]) * self.mapim.shape[1] / w self.move_point(u, v) scale = w / self.mapim.shape[1] dl = imgui.get_window_draw_list() self.render_ptlist(dl, self.pts['cone'], rectmin, scale, imgui.get_color_u32_rgba(1, 0.7, 0, 1), 4, self.editmode == 'cone') self.render_ptlist(dl, self.pts['turn'], rectmin, scale, imgui.get_color_u32_rgba(0, 0.3, 1, 1), 3, self.editmode == 'turn') self.render_ptlist(dl, self.pts['home'], rectmin, scale, imgui.get_color_u32_rgba(1, 1, 1, 1), 10, self.editmode == 'home') # render home position angle if len(self.pts['home']) > 0: h = self.pts['home'][0] S = 100 * np.sin(self.homeangle) C = 100 * np.cos(self.homeangle) dl.add_line(rectmin[0] + h[0] * scale, rectmin[1] + h[1] * scale, rectmin[0] + h[0] * scale + C, rectmin[1] + h[1] * scale - S, imgui.get_color_u32_rgba(1, 1, 1, 1)) self.render_turns(scale, rectmin) self.render_opttrack(scale, rectmin) if self.editmode == "cone": zoomtip(self.maptex, self.mapim.shape, 2)
def _show_custom_ui(self): if self.filter_status is not None: imgui.dummy(1, 5) imgui.text_colored("Filter error. (?)", 1.0, 0.0, 0.0) if imgui.is_item_hovered(): imgui.set_tooltip(self.filter_status)
def _show_custom_ui(self): if self.status: imgui.dummy(1, 5) imgui.text_colored("Error. (?)", 1.0, 0.0, 0.0) if imgui.is_item_hovered(): imgui.set_tooltip(self.status)
def render_palette(drawing: Drawing): global color_editor_open # Need a persistent way to keep track of the popup being closed... global current_color_page palette = drawing.palette fg = palette.foreground bg = palette.background fg_color = palette.foreground_color bg_color = palette.background_color imgui.begin_child("Palette", border=False, height=460) # Edit foreground color if imgui.color_button(f"Foreground (#{fg})", *as_float(fg_color), 0, 30, 30): io = imgui.get_io() w, h = io.display_size imgui.open_popup("Edit foreground color") imgui.set_next_window_position(w - 115 - 120, 200) color_editor_open = True if imgui.begin_popup("Edit foreground color", flags=(imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SCROLL_WITH_MOUSE)): done, cancelled, new_color = render_color_editor( palette.colors[fg], fg_color) if done and new_color != fg_color: drawing.change_colors(fg, new_color) palette.clear_overlay() elif cancelled: palette.clear_overlay() else: palette.set_overlay(fg, new_color) imgui.end_popup() elif color_editor_open: # The popup was closed by clicking outside, keeping the change (same as OK) drawing.change_colors(fg, fg_color) palette.clear_overlay() color_editor_open = False imgui.same_line() imgui.color_button(f"Background (#{bg})", *as_float(bg_color), 0, 30, 30) max_pages = len(palette.colors) // 64 - 1 imgui.push_item_width(100) _, current_color_page = imgui.slider_int("Page", current_color_page, min_value=0, max_value=max_pages) start_color = 64 * current_color_page imgui.begin_child("Colors", border=False) imgui.push_style_var(imgui.STYLE_ITEM_SPACING, (0, 0)) # Make layout tighter width = int(imgui.get_window_content_region_width()) // 20 imgui.push_style_color(imgui.COLOR_FRAME_BACKGROUND, 0, 0, 0) colors = palette.colors # Order the colors by column instead of by row (which is the order we draw them) for i, c in enumerate( chain.from_iterable( zip(range(0, 16), range(16, 32), range(32, 48), range(48, 64)))): color = colors[start_color + c] is_foreground = c == fg is_background = (c == bg) * 2 selection = is_foreground | is_background color = as_float(color) if color[3] == 0 or selection: x, y = imgui.get_cursor_screen_pos() if imgui.color_button(f"color {i}", *color[:3], 1, 0, 25, 25): # io = imgui.get_io() # if io.key_shift: # if "spread_start" in temp_vars: # temp_vars["spread_end"] = i # else: # temp_vars["spread_start"] = i # else: fg = c if i % width != width - 1: imgui.same_line() draw_list = imgui.get_window_draw_list() if color[3] == 0: # Mark transparent color draw_list.add_line(x + 1, y + 1, x + 24, y + 24, imgui.get_color_u32_rgba(0, 0, 0, 1), 1) draw_list.add_line(x + 1, y + 2, x + 23, y + 24, imgui.get_color_u32_rgba(1, 1, 1, 1), 1) if is_foreground: # Mark foregroupd color draw_list.add_rect_filled(x + 2, y + 2, x + 10, y + 10, imgui.get_color_u32_rgba(1, 1, 1, 1)) draw_list.add_rect(x + 2, y + 2, x + 10, y + 10, imgui.get_color_u32_rgba(0, 0, 0, 1)) if is_background: # Mark background color draw_list.add_rect_filled(x + 15, y + 2, x + 23, y + 10, imgui.get_color_u32_rgba(0, 0, 0, 1)) draw_list.add_rect(x + 15, y + 2, x + 23, y + 10, imgui.get_color_u32_rgba(1, 1, 1, 1)) if imgui.core.is_item_clicked(2): # Right button sets background bg = c # Drag and drop (currently does not accomplish anything though) if imgui.begin_drag_drop_source(): imgui.set_drag_drop_payload('start_index', c.to_bytes(1, sys.byteorder)) imgui.color_button(f"color {c}", *color[:3], 1, 0, 20, 20) imgui.end_drag_drop_source() if imgui.begin_drag_drop_target(): start_index = imgui.accept_drag_drop_payload('start_index') if start_index is not None: start_index = int.from_bytes(start_index, sys.byteorder) io = imgui.get_io() image_only = io.key_shift drawing.swap_colors(start_index, c, image_only=image_only) palette.clear_overlay() imgui.end_drag_drop_target() imgui.pop_style_color(1) imgui.pop_style_var(1) imgui.end_child() imgui.end_child() if imgui.is_item_hovered(): io = imgui.get_io() delta = int(io.mouse_wheel) current_color_page = min(max(current_color_page - delta, 0), max_pages) palette.foreground = fg palette.background = bg
def main(): global width_library global width_shematic global width_context global height_window global previous_key_callback global selected_link global selected_node global iggraph global node_library global debug_is_mouse_dragging global show_debug_window # states ------------------------- scrolling = imgui.Vec2(0, 0) iggraph = IGGraph(node_library) # iggraph.reset() node_hovered_in_scene = -1 parameter_link_start = None selected_parameter = None io_hovered = None io_anchors_width_not_hovered = 10 io_anchors_width_hovered = 15 right_splitter_is_active = False left_splitter_is_active = False image_width = 0 image_height = 0 image_texture = None # states ------------------------- imgui.create_context() window = impl_glfw_init() impl = GlfwRenderer(window) io = imgui.get_io() previous_key_callback = glfw.set_key_callback(window,key_event) init_textures() assign_parameter_colors(node_library) while not glfw.window_should_close(window): glfw.poll_events() impl.process_inputs() imgui.new_frame() if imgui.begin_main_menu_bar(): if imgui.begin_menu("File", True): clicked_new, selected_new = imgui.menu_item( "New", 'Cmd+N', False, True ) if clicked_new: iggraph = IGGraph(node_library) clicked_load, selected_load = imgui.menu_item( "Load", 'Cmd+L', False, True ) if clicked_load: root = tk.Tk() root.withdraw() filename = filedialog.askopenfilename() if filename : f=open(filename) iggraph.from_json(json.load(f)) f.close() clicked_save, selected_save = imgui.menu_item( "Save", 'Cmd+S', False, True ) if clicked_save: iggraph.reset() graph_json = iggraph.to_json() text2save = json.dumps(graph_json, indent=4, sort_keys=True) root = tk.Tk() root.withdraw() f = filedialog.asksaveasfile(mode='w', defaultextension=".json") if f is None: # asksaveasfile return `None` if dialog closed with "cancel". return f.write(text2save) f.close() clicked_quit, selected_quit = imgui.menu_item( "Quit", 'Cmd+Q', False, True ) if clicked_quit: exit(0) imgui.end_menu() if imgui.begin_menu("Debug", True): show_debug_window_clicked, show_debug_window_selected = imgui.menu_item( "Show Debug window", 'Cmd+D', show_debug_window, True ) if show_debug_window_clicked: show_debug_window = not show_debug_window catch_exceptions_clicked, catch_exceptions_selected = imgui.menu_item( "Catch Exceptions", '', iggraph.catch_exceptions, True ) if catch_exceptions_clicked: iggraph.catch_exceptions = not iggraph.catch_exceptions imgui.separator() imgui.menu_item( "Examples", '', False, False ) show_example_mosaic_clicked, show_example_mosaic_selected = imgui.menu_item( "Mosaic", '', False, True ) if show_example_mosaic_clicked: example_mosaic(iggraph) imgui.end_menu() imgui.end_main_menu_bar() height_window = io.display_size.y - 18 # imgui.get_cursor_pos_y() imgui.push_style_var(imgui.STYLE_ITEM_SPACING, imgui.Vec2(0,0)) imgui.set_next_window_size(io.display_size.x, height_window) imgui.set_next_window_position(0, 18) imgui.push_style_var(imgui.STYLE_WINDOW_ROUNDING, 0) imgui.begin("Splitter test", False, imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_BRING_TO_FRONT_ON_FOCUS) imgui.pop_style_var() imgui.pop_style_var() width_shematic = io.display_size.x - separator_width - width_context - separator_width - width_library # ============================================================================== # Library # ============================================================================== imgui.push_style_var(imgui.STYLE_CHILD_BORDERSIZE, 0) imgui.begin_child("Library", width_library, 0, True) for node_name in node_library.nodes: if imgui.button(node_name, width_library): iggraph.create_node(node_name) imgui.end_child() imgui.pop_style_var() imgui.same_line() imgui.button("left_splitter", separator_width, height_window - 20) left_splitter_is_active = imgui.is_item_active() if (left_splitter_is_active): width_library += io.mouse_delta.x scrolling = imgui.Vec2(scrolling.x - io.mouse_delta.x, scrolling.y) if (imgui.is_item_hovered()): imgui.set_mouse_cursor(imgui.MOUSE_CURSOR_RESIZE_EW) imgui.same_line() # ============================================================================== # Shematic # ============================================================================== imgui.push_style_var(imgui.STYLE_CHILD_BORDERSIZE, 0) imgui.begin_child("shematic", width_shematic, 0, True) if show_inputs_popup(iggraph): imgui.open_popup("Outputs") show_outputs_popup(iggraph) # create our child canvas if iggraph.get_state() == iggraph.STATE_IDLE: imgui.text("status: edit | ") elif iggraph.get_state() == iggraph.STATE_RUNNING: imgui.text("status: run | ") imgui.same_line() if iggraph.get_state() == iggraph.STATE_IDLE: if imgui.button("run"): #TODO if not running iggraph.set_state(iggraph.STATE_RUNNING) iggraph.prepare_to_run() imgui.open_popup("User Input") imgui.same_line() if imgui.button("run one step"): iggraph.set_state(iggraph.STATE_RUNNING) iggraph.prepare_to_run() iggraph.run_one_step() elif iggraph.get_state() == iggraph.STATE_RUNNING: if imgui.button("stop running"): iggraph.reset() iggraph.set_state(iggraph.STATE_IDLE) imgui.same_line() if imgui.button("run one step"): iggraph.set_state(iggraph.STATE_RUNNING) iggraph.run_one_step() # imgui.same_line(imgui.get_window_width() - 100) imgui.push_style_var(imgui.STYLE_FRAME_PADDING, imgui.Vec2(1, 1)) imgui.push_style_var(imgui.STYLE_WINDOW_PADDING, imgui.Vec2(0, 0)) imgui.begin_child("scrolling_region", 0, 0, True, imgui.WINDOW_NO_SCROLLBAR | imgui.WINDOW_NO_MOVE) imgui.pop_style_var() imgui.pop_style_var() imgui.push_item_width(120.0) offset = add(imgui.get_cursor_screen_pos(), scrolling) draw_list = imgui.get_window_draw_list() # Display links draw_list.channels_split(2) draw_list.channels_set_current(0) for link in iggraph.links: draw_link_param_to_param(draw_list, offset, link.output_parameter, link.input_parameter, selected_link == link) # Display nodes parameter_link_end = None one_parameter_hovered = False one_node_moving_active = False for node in iggraph.nodes: imgui.push_id(str(node.id)) node_rect_min = add(offset, node.pos) draw_list.channels_set_current(1) # foreground old_any_active = imgui.is_any_item_active() #display node content first # todo test = add(node_rect_min, NODE_WINDOW_PADDING) imgui.set_cursor_screen_position(add(node_rect_min, NODE_WINDOW_PADDING)) imgui.begin_group() imgui.text("") imgui.text(node.name) imgui.text("") imgui.end_group() # save size node_widgets_active = False # (not old_any_active and imgui.is_any_item_active()) node.size = add( add( imgui.get_item_rect_size(), NODE_WINDOW_PADDING) , NODE_WINDOW_PADDING) node_rect_max = add(node.size, node_rect_min) #display node box draw_list.channels_set_current(0) # background imgui.set_cursor_screen_position(node_rect_min) imgui.invisible_button(str(node.id), node.size.x, node.size.y) if imgui.is_item_hovered(): node_hovered_in_scene = node.id else: node_hovered_in_scene = None node_moving_active = imgui.is_item_active() use_hovered_color = node_hovered_in_scene or selected_node == node draw_list.add_rect_filled(node_rect_min.x, node_rect_min.y, node_rect_max.x, node_rect_max.y, get_node_color(node, iggraph, use_hovered_color), 5) if node_hovered_in_scene and iggraph.is_error(node): imgui.begin_tooltip() imgui.text(iggraph.error_nodes[node]) imgui.end_tooltip() # input parameters for parameter_name in node.inputs: parameter = node.inputs[parameter_name] center = node.get_intput_slot_pos(parameter) center_with_offset = add(offset, center) if io_hovered == parameter: io_anchors_width = io_anchors_width_hovered else: io_anchors_width = io_anchors_width_not_hovered imgui.set_cursor_pos(imgui.Vec2(center.x-io_anchors_width/2, center.y-io_anchors_width/2)) imgui.push_id(str(str(node.id) + "input" + parameter.id)) if (imgui.invisible_button("input", io_anchors_width, io_anchors_width)): selected_parameter = parameter # imgui.is_item_hovered() does not work when dragging is_hovering = ((io.mouse_pos.x-offset.x>center.x-io_anchors_width/2) and (io.mouse_pos.x-offset.x<center.x+io_anchors_width/2) and (io.mouse_pos.y-offset.y>center.y-io_anchors_width/2) and (io.mouse_pos.y-offset.y<center.y+io_anchors_width/2)) if is_hovering: io_hovered = parameter one_parameter_hovered = True imgui.begin_tooltip() imgui.text(parameter_name) imgui.end_tooltip() if is_hovering and imgui.is_mouse_released(0): parameter_link_end = parameter imgui.pop_id() draw_list.add_circle_filled(center_with_offset.x, center_with_offset.y, io_anchors_width/2, get_parameter_color(parameter)) # output parameters for parameter_name in node.outputs: parameter = node.outputs[parameter_name] center = node.get_output_slot_pos(parameter) center_with_offset = add(offset, center) if io_hovered == parameter: io_anchors_width = io_anchors_width_hovered else: io_anchors_width = io_anchors_width_not_hovered imgui.set_cursor_pos(imgui.Vec2(center.x-io_anchors_width/2, center.y-io_anchors_width/2)) imgui.push_id(str(str(node.id) + "output" + parameter.id)) if (imgui.invisible_button("output", io_anchors_width, io_anchors_width)): selected_parameter = parameter is_hovering = ((io.mouse_pos.x-offset.x>center.x-io_anchors_width/2) and (io.mouse_pos.x-offset.x<center.x+io_anchors_width/2) and (io.mouse_pos.y-offset.y>center.y-io_anchors_width/2) and (io.mouse_pos.y-offset.y<center.y+io_anchors_width/2)) if is_hovering: io_hovered = parameter one_parameter_hovered = True imgui.begin_tooltip() imgui.text(parameter_name) imgui.end_tooltip() draw_list.add_circle_filled(center_with_offset.x, center_with_offset.y, io_anchors_width/2, get_parameter_color(parameter)) imgui.pop_id() # cannot use imgui.is_item_active, seems buggy with the scroll if is_hovering and imgui.is_mouse_down(0): parameter_link_start = parameter if node_widgets_active or node_moving_active: selected_node = node one_node_moving_active = True if node_moving_active and imgui.is_mouse_dragging(0) and node.id==selected_node.id: node.pos = add(node.pos, io.mouse_delta) debug_is_mouse_dragging = imgui.is_mouse_dragging(0) imgui.pop_id() draw_list.channels_merge() if not one_parameter_hovered: io_hovered = None # scrolling mouse_is_in_schematic = (io.mouse_pos.x > width_library) and\ (io.mouse_pos.x < (width_library + width_shematic)) and\ (io.mouse_pos.y < height_window) and\ (io.mouse_pos.y > 18) if not one_node_moving_active and\ not parameter_link_start and\ imgui.is_mouse_dragging(0) and\ mouse_is_in_schematic and\ not left_splitter_is_active and\ not right_splitter_is_active and\ imgui.is_window_focused(): scroll_offset = imgui.Vec2(io.mouse_delta.x, io.mouse_delta.y) scrolling = add(scrolling, scroll_offset) # link creation if parameter_link_start and parameter_link_end: iggraph.add_link(parameter_link_start, parameter_link_end) # creating link elif parameter_link_start and imgui.is_mouse_dragging(0): draw_link_param_to_point(draw_list, offset, parameter_link_start, io.mouse_pos.x, io.mouse_pos.y, True) # mouse release if imgui.is_mouse_released(0): parameter_link_start = None imgui.pop_item_width() imgui.end_child() # mouse click on the scene if imgui.is_mouse_clicked(0): mouse_pos = imgui.get_mouse_pos() local_mouse_pos = imgui.Vec2(mouse_pos.x - offset.x, mouse_pos.y - offset.y) selected_link = None for link in iggraph.links: start_node = link.output_parameter.owner start_pos = start_node.get_output_slot_pos(link.output_parameter) end_node = link.input_parameter.owner end_pos = end_node.get_intput_slot_pos(link.input_parameter) distance_mouse_start = math.sqrt(((local_mouse_pos.x-start_pos.x)**2) + ((local_mouse_pos.y-start_pos.y)**2)) distance_mouse_end = math.sqrt(((local_mouse_pos.x-end_pos.x)**2) + ((local_mouse_pos.y-end_pos.y)**2)) distance_start_end = math.sqrt(((start_pos.x-end_pos.x)**2) + ((start_pos.y-end_pos.y)**2)) if ((distance_mouse_start + distance_mouse_end) - distance_start_end) < 0.1: selected_link = link imgui.end_child() imgui.pop_style_var() imgui.same_line() imgui.button("right_splitter", separator_width, height_window - 20) right_splitter_is_active = imgui.is_item_active() if (right_splitter_is_active): width_context -= io.mouse_delta.x if (imgui.is_item_hovered()): imgui.set_mouse_cursor(imgui.MOUSE_CURSOR_RESIZE_EW) # ============================================================================== # Context # ============================================================================== imgui.same_line() imgui.push_style_var(imgui.STYLE_CHILD_BORDERSIZE, 0) imgui.begin_child("child3", width_context, 0, True); if selected_node: if selected_node.handle_dynamic_parameters(): if imgui.button("add parameter"): selected_node.add_dynamic_parameter() if imgui.tree_node("Inputs"): for parameter_name in selected_node.inputs: parameter = selected_node.inputs[parameter_name] if imgui.tree_node(parameter.id): display_parameter(parameter, True) imgui.tree_pop() imgui.tree_pop() if imgui.tree_node("Output"): for parameter_name in selected_node.outputs: parameter = selected_node.outputs[parameter_name] if imgui.tree_node(parameter.id): display_parameter(parameter, False) imgui.tree_pop() imgui.tree_pop() imgui.end_child() imgui.pop_style_var() # imgui.end() # ============================================================================== # Debug Window # ============================================================================== if show_debug_window: debug_window_expanded, show_debug_window = imgui.begin("Debug", True) if parameter_link_start: imgui.text("parameter_link_start: " + parameter_link_start.id) else: imgui.text("parameter_link_start: " + "None") if selected_parameter: imgui.text("selected_parameter: " + selected_parameter.id) else: imgui.text("selected_parameter: " + "None") imgui.text("is_mouse_dragging: " + str(debug_is_mouse_dragging)) imgui.text("mouse: (" + str(io.mouse_pos.x) + ", " + str(io.mouse_pos.y) + ")") imgui.end() gl.glClearColor(1., 1., 1., 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() impl.render(imgui.get_draw_data()) glfw.swap_buffers(window) impl.shutdown() glfw.terminate()
def render_color_editor(orig, color): r, g, b, a = color io = imgui.get_io() delta = 0 imgui.push_id("R") # TODO find a less verbose way to do something like this: # imgui.push_style_color(imgui.COLOR_FRAME_BACKGROUND, r/255, 0, 0) # imgui.push_style_color(imgui.COLOR_FRAME_BACKGROUND_HOVERED, r/255, 0, 0) # imgui.push_style_color(imgui.COLOR_FRAME_BACKGROUND_ACTIVE, r/255, 0, 0) # imgui.push_style_color(imgui.COLOR_SLIDER_GRAB, 1, 1, 1) # imgui.push_style_color(imgui.COLOR_SLIDER_GRAB_ACTIVE, 1, 1, 1) _, r = imgui.v_slider_int("", 30, 255, r, min_value=0, max_value=255) # imgui.pop_style_color() # imgui.pop_style_color() # imgui.pop_style_color() # imgui.pop_style_color() # imgui.pop_style_color() if imgui.is_item_hovered(): delta = int(io.mouse_wheel) if not io.key_shift: r = _change_channel(r, delta) imgui.pop_id() imgui.same_line() imgui.push_id("G") _, g = imgui.v_slider_int("", 30, 255, g, min_value=0, max_value=255) if imgui.is_item_hovered(): delta = int(io.mouse_wheel) if not io.key_shift: g = _change_channel(g, delta) imgui.pop_id() imgui.same_line() imgui.push_id("B") _, b = imgui.v_slider_int("", 30, 255, b, min_value=0, max_value=255) if imgui.is_item_hovered(): delta = int(io.mouse_wheel) if not io.key_shift: b = _change_channel(b, delta) imgui.pop_id() if delta and io.key_shift: r = _change_channel(r, delta) g = _change_channel(g, delta) b = _change_channel(b, delta) if imgui.checkbox("Transp.", a == 0)[1]: a = 0 else: a = 255 imgui.color_button("Current color", *as_float(orig)) imgui.same_line() imgui.text("->") imgui.same_line() imgui.color_button("Current color", *as_float(color)) if imgui.button("OK"): imgui.close_current_popup() return True, False, (r, g, b, a) imgui.same_line() if imgui.button("Cancel"): imgui.close_current_popup() return False, True, (r, g, b, a) return False, False, (r, g, b, a)