def draw(self): style = imgui.get_style() imgui.begin("Colors") imgui.columns(4) for color in range(0, imgui.COLOR_COUNT): imgui.text("Color: {}".format(color)) imgui.color_button("color#{}".format(color), *style.colors[color]) imgui.next_column() imgui.end()
def on_mod(self, im): ''' 进行具体的应用逻辑绘制处理:im为imgui环境对象;返回值告知程序是否继续. 此方法应该被子类重载,完成具体的功能逻辑 ''' # 判断是否有ctrl+Q按下,结束app if im.is_key_down('ctrl+Q'): return False if not self._on_menu(): return False style = imgui.get_style() imgui.begin("Color window") imgui.columns(4) for color in range(0, imgui.COLOR_COUNT): imgui.text("Color: {} {}".format( color, imgui.get_style_color_name(color))) imgui.color_button("color#{}".format(color), *style.colors[color]) imgui.next_column() imgui.end() # 获取当前主窗口尺寸 win_width, win_height = im.main_win.get_size() # 定义菜单条高度 bar_height = 24 # 计算横向比例分隔 widths, hpos = split(win_width, (5, 15, 30)) # 计算左侧竖向比例分隔 heights, vpos = split(win_height - bar_height, (10, 30)) # 左侧列表 self.do_show_text('样本列表', hpos[0], bar_height, widths[0], win_height - bar_height, 'list') # 左上窗口 self.do_show_text('差异处', hpos[1], bar_height + vpos[0], widths[1], heights[0], 'tmp_text') # 左下窗口 self.do_show_text('新结果', hpos[1], bar_height + vpos[1], widths[1], heights[1], '测试123456') # 重新计算右侧竖向比例分隔 heights, vpos = split(win_height - bar_height, (30, 30)) # 右上窗口 self.do_show_text('原文本', hpos[2], bar_height + vpos[0], widths[2], heights[0], '测试1234') # 右下窗口 self.do_show_text('预处理', hpos[2], bar_height + vpos[1], widths[2], heights[1], '测试1234') #imgui.show_demo_window() return True
def draw(self): imgui.begin("Example: color button") if imgui.color_button("Button 1", *RED, 0, 10, 10): self.color = RED self.color_name = 'Red' if imgui.color_button("Button 2", *GREEN, 0, 10, 10): self.color = GREEN self.color_name = 'Green' if imgui.color_button("Wide Button", *BLUE, 0, 20, 10): self.color = BLUE self.color_name = 'Blue' if imgui.color_button("Tall Button", *MAGENTA, 0, 10, 20): self.color = MAGENTA self.color_name = 'Magenta' #imgui.text(f"You chose {self.color}") imgui.text_colored(f"You chose {self.color_name}", *self.color) imgui.end()
def color_button(label, color, tag=None): """ Colored button. Color can be specified in multiple ways listed in [concur.draw]. Returns `(label, None)` on click, or `(tag, None)` if tag is specified. """ r, g, b, a = color_to_rgba_tuple(color) while not imgui.color_button(label, r, g, b, a): yield return tag if tag is not None else label, None
def draw(self): imgui.new_frame() imgui.set_next_window_position(16, 32, imgui.ONCE) imgui.set_next_window_size(512, 512, imgui.ONCE) style = imgui.get_style() imgui.begin("Colors") imgui.columns(4) for color in range(0, imgui.COLOR_COUNT): imgui.text("Color: {}".format(color)) imgui.color_button("color#{}".format(color), *style.colors[color]) imgui.next_column() imgui.end() imgui.end_frame() imgui.render() self.renderer.render(imgui.get_draw_data())
def color_msg(color): msg = "" if isinstance(color, np.uint8): msg = "{0}".format(color) elif isinstance(color, np.float32): msg = "{0:.3f}".format(color) elif isinstance(color, np.float64): msg = "{0:.3f}".format(color) else: if len(color) == 3: bgr = color imgui.color_button(bgr[2] / 255., bgr[1] / 255., bgr[0] / 255.) imgui.same_line() msg = "RGB({0},{1},{2})".format(bgr[2], bgr[1], bgr[0]) elif len(color) == 4: bgra = color imgui.color_button(bgra[2] / 255., bgra[1] / 255., bgra[0] / 255., bgra[3]) imgui.same_line() msg = "RGBA({0},{1},{2},{3})".format(bgra[2], bgra[1], bgra[0], bgra[3]) return msg
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: color button") imgui.color_button("Button 1", 1, 0, 0, 1, 0, 10, 10) imgui.color_button("Button 2", 0, 1, 0, 1, 0, 10, 10) imgui.color_button("Wide Button", 0, 0, 1, 1, 0, 20, 10) imgui.color_button("Tall Button", 1, 0, 1, 1, 0, 10, 20) imgui.end() imgui.end_frame() imgui.render() self.renderer.render(imgui.get_draw_data())
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 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)
def render_palette_popup(drawing: Drawing): global edit_color global color_editor_open palette = drawing.palette fg = palette.foreground bg = palette.background fg_color = palette.foreground_color bg_color = palette.background_color open_color_editor = False _, opened = imgui.begin("Color popup", True) imgui.begin_child("Colors", height=0) imgui.push_style_var(imgui.STYLE_ITEM_SPACING, (0, 0)) # Make layout tighter width = int(imgui.get_window_content_region_width()) // 25 for i, color in enumerate(palette.colors, 0): is_foreground = i == fg is_background = (i == bg) * 2 selection = is_foreground | is_background if i in palette.overlay: color = as_float(palette.overlay[i]) else: color = as_float(color) imgui.push_style_color(imgui.COLOR_FRAME_BACKGROUND, *SELECTABLE_FRAME_COLORS[selection]) 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 = i imgui.pop_style_color(1) if imgui.core.is_item_clicked(1): edit_color = i color_editor_open = True imgui.open_popup("Edit foreground color") # imgui.set_next_window_position(w - 115 - 120, 200) if imgui.core.is_item_clicked(2): # Detect right button clicks on the button bg = i if imgui.begin_drag_drop_source(): imgui.set_drag_drop_payload('start_index', i.to_bytes(1, sys.byteorder)) imgui.color_button(f"color {i}", *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, i, image_only=image_only) # palette.clear_overlay() imgui.end_drag_drop_target() # if imgui.is_item_hovered(): # io = imgui.get_io() # delta = int(io.mouse_wheel) if i % width != width - 1: imgui.same_line() imgui.pop_style_var(1) #color_editor_open = render_color_editor_popup(drawing, edit_color, color_editor_open) imgui.end_child() imgui.end() palette.foreground = fg palette.background = bg return opened, open_color_editor
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 draw(imgui) -> None: global show_sendable_debug global show_demo global active_widgets if imgui.begin_main_menu_bar(): if imgui.begin_menu("Help"): clicked, _ = imgui.menu_item( "Hide Demo" if show_demo else "Show Demo") if clicked: show_demo = not show_demo imgui.end_menu() imgui.end_main_menu_bar() if show_demo: imgui.show_test_window() if imgui.begin('All Entries'): if imgui.begin_popup_context_window(): clicked, do_debug = imgui.checkbox('Show Chooser Debug Info', show_sendable_debug) if clicked: show_sendable_debug = do_debug imgui.end_popup() def table_tree(table: EntryGroup): for key, entry in table.items(): if isinstance(entry, NetworkTableEntry): imgui.text(entry_name(key) + ': ' + str(entry.value)) imgui.same_line() imgui.push_id(key) if imgui.button('Add'): active_widgets[key] = Widget(entry) imgui.pop_id() else: t = NetworkTables.getTable(key) if '.type' in t.getKeys(): name = t.getString('.name', '') imgui.text(name) imgui.same_line() imgui.push_id(key) if imgui.button('Add'): active_widgets[key] = Widget(t, EntryType.Chooser) imgui.pop_id() if show_sendable_debug: if imgui.tree_node('Chooser Debug (' + key + ')'): table_tree(entry) imgui.tree_pop() elif imgui.tree_node(entry_name(key), imgui.TREE_NODE_DEFAULT_OPEN): # nothing fancy, just a subtable table_tree(entry) imgui.tree_pop() entries = buildList( sorted(NetworkTables.getEntries('', 0), key=lambda e: e.getName())) table_tree(entries) imgui.end() to_close: List[str] = [] for key, widget in active_widgets.items(): expanded, opened = imgui.begin(entry_name(key), True) if not opened: to_close.append(key) if ((widget.tipe.is_entry() and widget.entry is None) or (not widget.tipe.is_entry() and widget.table is None)): imgui.text_colored('WARNING! Disconnected!', 1, 0, 0) imgui.end() continue if widget.tipe == EntryType.Boolean: assert widget.entry is not None if widget.show_indicator: imgui.push_item_width(-1) r, g, b = (0, 1, 0) if widget.entry.value else (1, 0, 0) imgui.color_button(key + '/indicator', r, g, b, width=imgui.get_window_width(), height=100) clicked, new_val = imgui.checkbox('on', widget.entry.value) if clicked: widget.entry.setValue(new_val) elif widget.tipe == EntryType.Double: assert widget.entry is not None val = str(widget.entry.getDouble(0)) changed, new_val = imgui.input_text('', val, 64, imgui.INPUT_TEXT_CHARS_DECIMAL) if changed: try: widget.entry.setDouble(float(new_val)) except ValueError: pass elif widget.tipe == EntryType.String: assert widget.entry is not None changed, new_val = imgui.input_text('', widget.entry.getString(''), 256) if changed: widget.entry.setString(new_val) elif widget.tipe == EntryType.Chooser: assert widget.table is not None values = widget.table.getStringArray('options', []) try: selected = values.index(widget.table.getString('active', '')) except ValueError: selected = 0 changed, current = imgui.combo('', selected, values) if changed: widget.table.putString('active', values[current]) else: try: assert widget.entry is not None imgui.text(str(widget.entry.value)) except AttributeError: imgui.text('Could not view contents.') if imgui.begin_popup_context_window(): if widget.tipe == EntryType.Boolean: clicked, new_val = imgui.checkbox('Show Indicator', widget.show_indicator) if clicked: widget.show_indicator = new_val imgui.end_popup() # imgui.button('Options') imgui.end() for key in to_close: active_widgets.pop(key)
def interface(): 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() if imgui.begin_menu('Windows', True): clicked_fixtureC, selected_fixtureC = imgui.menu_item( 'Fixture Controls', shortcut=None) if clicked_fixtureC: if values.showFixtureControl: values.showFixtureControl = False else: values.showFixtureControl = True imgui.end_menu() imgui.end_main_menu_bar() if values.showFixtureControl: imgui.begin("Fixture Control", True) for r in patch.rooms.values(): expanded, visible = imgui.collapsing_header(r.name) if expanded: imgui.indent() for f in r.fixtureList: expanded, visible = imgui.collapsing_header(f.name) rgb = values.values[f.name] if expanded: imgui.columns(2, f.name) imgui.indent() imgui.text('Red') changed, value = imgui.slider_int( '##int%sred' % f.name, rgb[0], 0, 255) if changed: rgb[0] = value ui.cache(f.setColor, [rgb, 0.2]) ui.update() imgui.text('Green') changed, value = imgui.slider_int( '##int%sgreen' % f.name, rgb[1], 0, 255) if changed: rgb[1] = value ui.cache(f.setColor, [rgb, 0.2]) ui.update() imgui.text('Blue') changed, value = imgui.slider_int( '##int%sblue' % f.name, rgb[2], 0, 255) if changed: rgb[2] = value ui.cache(f.setColor, [rgb, 0.2]) ui.update() imgui.next_column() imgui.color_button('Color Sample', rgb[0] / 255, rgb[1] / 255, rgb[2] / 255, width=100, height=100) imgui.columns(1) imgui.unindent() imgui.unindent() imgui.same_line(spacing=50) imgui.end()