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: simple popup") if imgui.button("select"): imgui.open_popup("select-popup") imgui.same_line() if imgui.begin_popup("select-popup"): imgui.text("Select one") imgui.separator() imgui.selectable("One") imgui.selectable("Two") imgui.selectable("Three") imgui.end_popup() imgui.end() imgui.end_frame() imgui.render() self.renderer.render(imgui.get_draw_data())
def _draw_component(self, entity, component_name, component_name_display): if not entity.has_component(component_name): return treeNodeFlags = imgui.TREE_NODE_DEFAULT_OPEN | imgui.TREE_NODE_FRAMED | imgui.TREE_NODE_ALLOW_ITEM_OVERLAP | imgui.TREE_NODE_FRAME_PADDING component = entity.get_component(component_name) # contentRegionAvailable = imgui.get_content_region_available() # lineHeight = imgui.push_style_var(imgui.STYLE_FRAME_PADDING, (4, 4)) imgui.separator() open = imgui.tree_node(component_name_display, treeNodeFlags) imgui.pop_style_var() # TODO imgui.same_line(contentRegionAvailable.x - lin) imgui.same_line() if imgui.button("+"): imgui.open_popup("ComponentSettings") removeComponent = False if imgui.begin_popup("ComponentSettings"): if menu_item_clicked("Remove component"): removeComponent = True imgui.end_popup() if open: getattr(self, "_draw_component_%s" % component_name)(component) imgui.tree_pop() if removeComponent: entity.remove_component(component_name)
def dynamic_popup_button(self, label, error, tag=None): """ Validating button. Behaves in the same way as a regular `concur.widgets.button` when `error` is None. When `error` is a string, it displays an error popup instead of emitting an event. """ while True: if imgui.button(label): if error is not None: imgui.open_popup("Error Popup") else: return tag if tag is not None else label, None if imgui.begin_popup("Error Popup"): imgui.text(error) if self.is_continuable: if imgui.button("Continue anyway"): imgui.close_current_popup() imgui.end_popup() return tag if tag is not None else label, None imgui.same_line() if imgui.button("Cancel"): imgui.close_current_popup() imgui.end_popup() else: if imgui.button("OK"): imgui.close_current_popup() imgui.end_popup() yield
def gui(self): if imgui.begin_popup(self.name): imgui.label_text(self.name, self.name) if imgui.button('Ok'): self.callback() imgui.close_current_popup() imgui.end_popup()
def imgui_pick_file(name, base_path, wildcard="*"): if imgui.begin_popup(name): path = _imgui_pick_file_menu(base_path, wildcard) if path is not None: imgui.close_current_popup() imgui.end_popup() return path imgui.end_popup()
def gui(self): if imgui.begin_popup(self.name): self.form.gui() if imgui.button(self.name): self.callback(self.form.context) imgui.close_current_popup() self.form.init() imgui.end_popup()
def _show_custom_ui(self): super()._show_custom_ui() if imgui.button("choose file"): imgui.open_popup("choose_file") if imgui.begin_popup("choose_file"): for i, path in enumerate(self._files): if imgui.menu_item(path, "", False, True)[0]: self.set_state({"index": i}) imgui.end_popup()
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_context(self): # called from ui-node to add custom entries in nodes context menu # called only when that context menu is visible has_state = len(self.spec.initial_state) != 0 has_presets = len(self.spec.presets) != 0 if has_state: imgui.separator() if imgui.button("reset state"): self.reset_state(force=True) imgui.same_line() if imgui.button("randomize state"): self.randomize_state(force=True) changed, self.allow_state_randomization = imgui.checkbox( "allow state randomization", self.allow_state_randomization) if has_presets: imgui.separator() if imgui.button("default preset"): self.reset_preset(force=True) imgui.same_line() if imgui.button("random preset"): self.randomize_preset(force=True) imgui.same_line() if imgui.button("choose preset..."): imgui.open_popup("choose_preset") if imgui.begin_popup("choose_preset"): for name, values in self.spec.presets: if imgui.button(name): self.set_preset(values) imgui.end_popup() changed, self.allow_preset_randomization = imgui.checkbox( "allow preset randomization", self.allow_preset_randomization) if imgui.button("copy current as preset"): # copy only keys that are contained in (first) preset # TODO see how this behavior works keys = None if not has_presets else list( self.spec.presets[0][1].keys()) values = OrderedDict() for port_id, value in self.values.items(): if not is_input(port_id): continue name = port_name(port_id) if keys is not None and name not in keys: continue values[name] = value.value preset = ["name", values] clipboard.copy(json.dumps(preset))
def draw(self): imgui.begin("Example: simple popup") if imgui.button("select"): imgui.open_popup("select-popup") imgui.same_line() if imgui.begin_popup("select-popup"): imgui.text("Select one") imgui.separator() imgui.selectable("One") imgui.selectable("Two") imgui.selectable("Three") imgui.end_popup() imgui.end()
def show(self, value, read_only): # don't show it as read-only for now # as the color picker dialog might be nice for inspecting the color r, g, b, a = value.value[:] flags = imgui.COLOR_EDIT_NO_INPUTS | imgui.COLOR_EDIT_NO_LABEL | imgui.COLOR_EDIT_ALPHA_PREVIEW if imgui.color_button("color %s" % id(self), r, g, b, a, flags, 50, 50): imgui.open_popup("picker %s" % id(self)) if imgui.begin_popup("picker %s" % id(self)): changed, color = imgui.color_picker4( "color", r, g, b, a, imgui.COLOR_EDIT_ALPHA_PREVIEW) if changed: if not read_only: # careful here! update it safely (with numpy-assignment) # but also set it properly so it is regarded as changed v = value.value v[:] = color value.value = v imgui.end_popup()
def main(): renderer = NXRenderer() # My stuff MudData = { 'Player_text': '', 'Player_text_changed': False, 'Player_text_changed1': False, 'World_text': 'Please Enter the server info like this: serverhost.port', 'World_text_changed': False, 'server_host': '', 'server_port': 0, 'Entered_server_data': False, 'Clear_Player_data': False, 'Shift_enabled': False } keyboardInner = Keyboard2(MudData) TelnetSetup = TelnetBackend(MudData) # End Of my stuff while True: renderer.handleinputs() imgui.new_frame() width, height = renderer.io.display_size imgui.set_next_window_size(width, height) imgui.set_next_window_position(0, 0) imgui.begin("", flags=imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SAVED_SETTINGS) MudClientWindow(MudData) GuiProcess(MudData, TelnetSetup) if imgui.begin_popup("select-popup"): keyboardInner.create_frames_and_buttons() imgui.end_popup() imgui.end() imgui.render() renderer.render() PostGuiStuff(MudData) renderer.shutdown()
def _draw_entity_components(self, entity): ValueEdit(entity, "tag", "input_text", "Tag")() # --------------------------------------------------- # add component # --------------------------------------------------- imgui.same_line() imgui.push_item_width(-1) if imgui.button("Add Component"): imgui.open_popup("AddComponent") if imgui.begin_popup("AddComponent"): if menu_item_clicked("Transform"): entity.add_component("transform") imgui.close_current_popup() if menu_item_clicked("Camera"): print "add component camera" imgui.close_current_popup() if menu_item_clicked("Sprite Renderer"): print "add component sprite renderer" imgui.close_current_popup() if menu_item_clicked("Physics"): entity.add_component("physics") imgui.close_current_popup() imgui.end_popup() imgui.pop_item_width() # --------------------------------------------------- # draw components # --------------------------------------------------- self._draw_component(entity, "transform", "Transform") self._draw_component(entity, "camera", "Camera") self._draw_component(entity, "sprite_renderer", "Sprite Renderer") self._draw_component(entity, "physics", "Physics")
def draw_log_detail_info_panel(self, idx, log): if idx != self.detail_idx: return popup_id = "detail_log_%s" % self.detail_idx win_size = imgui.get_window_size() item_size = (win_size.x * 0.94, win_size.y * 0.5) imgui.set_next_window_size(item_size[0], item_size[1]) imgui.set_next_window_position((win_size.x - item_size[0]) * 0.5, (win_size.y - item_size[1]) * 0.5) if imgui.begin_popup(popup_id): msg = log.detail_info utils.get_win_size() btn_height = 22 padding = imgui.get_style().window_padding area_size = (item_size[0] * 0.98, item_size[1] * 0.94 - btn_height - padding.y * 0.6) imgui.input_text_multiline("##hidden", msg, len(msg) + 1, area_size[0], area_size[1], imgui.INPUT_TEXT_READ_ONLY) if imgui.button("复制", area_size[0], btn_height): print("复制") imgui.end_popup()
def main(): window, gl_context = impl_pysdl2_init() renderer = SDL2Renderer(window) # My stuff MudData = { 'Player_text': '', 'Player_text_changed': False, 'Player_text_changed1': False, 'World_text': 'Please Enter the server info like this: serverhost.port', 'World_text_changed': False, 'server_host': '', 'server_port': 0, 'Entered_server_data': False, 'Clear_Player_data': False, 'Shift_enabled': False } keyboardInner = Keyboard2(MudData) TelnetSetup = TelnetBackend(MudData) # End Of my stuff running = True event = SDL_Event() while running: while SDL_PollEvent(ctypes.byref(event)) != 0: if event.type == SDL_QUIT: running = False break renderer.process_event(event) renderer.process_inputs() imgui.new_frame() if imgui.begin_main_menu_bar(): if imgui.begin_menu("File", True): clicked_quit, selected_quit = imgui.menu_item( "Quit", 'Cmd+Q', False, True ) if clicked_quit: exit(1) imgui.end_menu() imgui.end_main_menu_bar() # imgui.show_test_window() imgui.begin("Mudlet Window") MudClientWindow(MudData) GuiProcess(MudData, TelnetSetup) if imgui.begin_popup("select-popup"): keyboardInner.create_frames_and_buttons() imgui.end_popup() imgui.end() gl.glClearColor(1., 1., 1., 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() SDL_GL_SwapWindow(window) PostGuiStuff(MudData) renderer.shutdown() SDL_GL_DeleteContext(gl_context) SDL_DestroyWindow(window) SDL_Quit()
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 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")