def render_ui(self): """Render the UI""" 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("Custom window", True) imgui.text("Bar") imgui.text_colored("Eggs", 0.2, 1., 0.) imgui.end() # Create window with the framebuffer image imgui.begin("Custom window with Image", True) # Create an image control by passing in the OpenGL texture ID (glo) # and pass in the image size as well. # The texture needs to he registered using register_texture for this to work imgui.image(self.fbo.color_attachments[0].glo, *self.fbo.size) imgui.end() imgui.render() self.imgui.render(imgui.get_draw_data())
def draw(self, *args, **kwargs): 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("Custom window", True) imgui.text("Bar") imgui.text_colored("Eggs", 0.2, 1., 0.) imgui.end() gl.glClearColor(1., 1., 1., 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render()
def testWindow(self): imgui.begin("Custom window", False) # start new window: Custom Window imgui.text("Bar") # text label imgui.text_colored("Eggs", 0.2, 1., 0.) # colored text label (text, r, g , b) imgui.button("Test Button", 100, 20) imgui.end() # End window def: Custom Window
def __call__(self): _, show = imgui.begin("Custom window1", True) if not show: main_frame.s1 = False imgui.text("BarBarBar") imgui.text_colored("Eggs", 1., 0.1, 0.2) imgui.end()
async def signal_plot_window( plot_box_state: PlotBoxState, m_inputs: List[Maybe[Signal]], ui_settings: Dict[str, Any]) -> Eff[[ACTIONS], IMGui[None]]: m_signal = m_inputs[0] assert ((type(m_signal.val) == Signal) if m_signal.is_Just() else True), repr(m_signal) PLOT_WINDOW_FLAGS = 0 if ui_settings[ 'plot_window_movable'] else im.WINDOW_NO_MOVE plot_name = "Plot (id={id})###{id}".format(id=plot_box_state.id_) with window(name=plot_name, flags=PLOT_WINDOW_FLAGS): plot_width = -1. # auto plot_height = im.get_content_region_available().y - 20 await signal_plot(plot_box_state, m_signal, width=plot_width, height=plot_height, ui_settings=ui_settings) if m_signal.is_Nothing(): im.text(" ") elif m_signal.is_Just(): signal = m_signal.val im.text_colored(str(signal), 0.8, 0.8, 0.8) return get_window_rect()
def update(dt): 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() show_test_window() #imgui.show_test_window() imgui.begin("Custom window", True) imgui.text("Bar") imgui.text_colored("Eggs", 0.2, 1., 0.) imgui.text_ansi("B\033[31marA\033[mnsi ") imgui.text_ansi_colored("Eg\033[31mgAn\033[msi ", 0.2, 1., 0.) imgui.end()
def __call__(self): _, show = imgui.begin("LOL", True) if not show: main_frame.s1 = False imgui.text("BarBar") imgui.text_colored("Eggs", 0.7, 0.4, 0.2) imgui.end()
def draw(self): imgui.new_frame() imgui.set_next_window_position(16, 32, imgui.ONCE) imgui.set_next_window_size(512, 512, imgui.ONCE) 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("Custom window", True) imgui.text("Bar") imgui.text_colored("Eggs", 0.2, 1., 0.) imgui.end() imgui.end_frame() imgui.render() self.renderer.render(imgui.get_draw_data())
def draw_console(): global _console_text_temp if console.SHOW_CONSOLE: imgui.set_next_window_bg_alpha(0.35) imgui.set_next_window_position(0, 0) imgui.set_next_window_size(screen_utils.WIDTH, 110) imgui.begin( "ConsoleWindow", False, imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_COLLAPSE | imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_SAVED_SETTINGS) imgui.begin_child("ConsoleOutput", 0, -25, False) for text, color in console.text_buffer: if color is None: color = (0.25, 0.75, 1) imgui.text_colored(text, color[0], color[1], color[2], 0.8) imgui.text("") imgui.set_scroll_y(imgui.get_scroll_max_y()) imgui.end_child() buf_size = 256 if len(_console_text_temp) > 0 and not _console_text_temp[0] == "/": buf_size = 64 enter, text = imgui.input_text("Input", _console_text_temp, buf_size, imgui.INPUT_TEXT_ENTER_RETURNS_TRUE) if enter: if str.startswith(text, "/"): text = str.replace(text, "/", "", 1) console.handle_input(text) else: client_net.send_message(text) text = "" _console_text_temp = text imgui.end()
def show_main_menu(): global text, ip_text style: GuiStyle = imgui.get_style() style.window_border_size = 0 style.colors[imgui.COLOR_BUTTON] = Vec4(0.26, 0.59, 0.5, 0.4) style.colors[imgui.COLOR_BUTTON_ACTIVE] = Vec4(0.06, 0.53, 0.4, 1.0) style.colors[imgui.COLOR_BUTTON_HOVERED] = Vec4(0.26, 0.59, 0.5, 1.0) imgui.set_next_window_bg_alpha(0) imgui.set_next_window_position(300, 220) imgui.set_next_window_size(180, 200) imgui.begin("tremor0", False, imgui.WINDOW_NO_COLLAPSE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_ALWAYS_USE_WINDOW_PADDING) _, username = imgui.input_text("Name", text, 16) _, ip = imgui.input_text("Host", ip_text, 32) ip_text = ip text = username imgui.end() imgui.set_next_window_bg_alpha(0) imgui.set_next_window_size(100, 100) imgui.set_next_window_position(200, 200) imgui.begin("tremor1", False, imgui.WINDOW_NO_COLLAPSE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_ALWAYS_USE_WINDOW_PADDING) imgui.text_colored("Tremor", 0.9, 0.6, 1.0) play_clicked = imgui.button("Play", 82, 25) exit_clicked = imgui.button("Exit", 82, 25) if exit_clicked: graphics_subsystem.request_close() if play_clicked: print(username) client_net.connect_to_server((ip, 27070), username) imgui.end()
def __call__(self): _, show = imgui.begin("ROFL", True) if not show: main_frame.s1 = False imgui.text("BarB.B") imgui.text(str(math.fabs(math.sin(time.time())))) imgui.text_colored("Egg", 1., 0.1, 0.2) imgui.end()
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 render ( self ): super().render() if imgui.begin( "Music Editor" ): ( width, height ) = imgui.get_content_region_available(); ( changed, value ) = imgui.input_text_multiline( "###Code", self.code, 1000, width = width, height = height / 2 ) if changed: self.code = value to_parse = False to_play = False if imgui.button( "Parse" ): to_parse = True imgui.same_line() if imgui.button( "Play" ): to_play = True try: if to_parse or to_play: self.player = Player() self.player.sequencers.append( FluidSynthSequencer() ) parser = Parser(); self.parsedTree = parser.parse( self.code ) self.context = self.create_context( self.player ) value = self.parsedTree.eval( self.context ) self.player.events = events = list( value ) if isinstance( value, Music ) else [] self.parsedException = None if to_play: self.player.play() except Exception as ex: self.parsedException = ex print(ex) traceback.print_tb(ex.__traceback__) if self.parsedException != None: imgui.text_colored( str( self.parsedException ), 1, 0, 0 ) self.expressionTab = self.imgui_tabbar( self.expressionTab, [ ( EXPRESSION_TAB_AST, "AST", self.render_inspector_ast ), ( EXPRESSION_TAB_EVENTS, "Events", self.render_inspector_events ), ( EXPRESSION_TAB_KEYBOARD, "Keyboard", self.render_inspector_keyboard ) ] ) imgui.end()
def main(): pygame.init() size = 800, 600 pygame.display.set_mode(size, pygame.DOUBLEBUF | pygame.OPENGL | pygame.RESIZABLE) imgui.create_context() impl = PygameRenderer() io = imgui.get_io() io.display_size = size while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() impl.process_event(event) 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("Custom window", True) imgui.text("Bar") #imgui.same_line() imgui.text_colored("Eggs", 0.2, 1., 0.) #imgui.same_line() imgui.bullet_text("bullet_text") # 不换行 #imgui.same_line() imgui.end() # note: cannot use screen.fill((1, 1, 1)) because pygame's screen # does not support fill() on OpenGL sufraces gl.glClearColor(1, 1, 1, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() impl.render(imgui.get_draw_data()) pygame.display.flip()
def render_ui(self): # Test window imgui.new_frame() imgui.begin("Custom window", True) imgui.text("Bar") imgui.text_colored("Eggs", 0.2, 1., 0.) imgui.end() # Render imgui.render() self.imgui.render(imgui.get_draw_data())
def main(): pygame.init() clock = pygame.time.Clock() size = 640, 480 pygame.display.set_mode(size, pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.OPENGL) io = imgui.get_io() io.fonts.add_font_default() io.display_size = size renderer = PygameRenderer() while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() renderer.process_event(event) 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: pygame.quit() exit(1) imgui.end_menu() imgui.end_main_menu_bar() imgui.show_test_window() imgui.begin("Custom window", True) imgui.text("Bar") imgui.text_colored("Eggs", 0.2, 1., 0.) imgui.end() # note: cannot use screen.fill((1, 1, 1)) because pygame's screen # does not support fill() on OpenGL sufraces gl.glClearColor(1, 1, 1, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() pygame.display.flip() clock.tick(60)
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 main(): window, gl_context = impl_pysdl2_init() impl = SDL2Impl(window) opened = True running = True event = SDL_Event() while running: while SDL_PollEvent(ctypes.byref(event)) != 0: if event.type == SDL_QUIT: running = False break impl.process_event(event) impl.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_user_guide() imgui.show_test_window() if opened: expanded, opened = imgui.begin("fooo", True) imgui.text("Bar") imgui.text_colored("Eggs", 0.2, 1., 0.) imgui.end() with imgui.styled(imgui.STYLE_ALPHA, 1): imgui.show_metrics_window() gl.glClearColor(114 / 255., 144 / 255., 154 / 255., 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() SDL_GL_SwapWindow(window) impl.shutdown() SDL_GL_DeleteContext(gl_context) SDL_DestroyWindow(window) SDL_Quit()
def on_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("Custom window", True) imgui.text("Bar") imgui.text_colored("Eggs", 0.2, 1., 0.) imgui.end()
def main(): window, gl_context = impl_pysdl2_init() imgui.create_context() impl = SDL2Renderer(window) running = True event = SDL_Event() while running: while SDL_PollEvent(ctypes.byref(event)) != 0: if event.type == SDL_QUIT: running = False break impl.process_event(event) impl.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() show_test_window() #imgui.show_test_window() imgui.begin("Custom window", True) imgui.text("Bar") imgui.text_colored("Eggs", 0.2, 1., 0.) imgui.end() gl.glClearColor(1., 1., 1., 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() impl.render(imgui.get_draw_data()) SDL_GL_SwapWindow(window) impl.shutdown() SDL_GL_DeleteContext(gl_context) SDL_DestroyWindow(window) SDL_Quit()
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 log_widget(self, text): # TODO Fix autoscrolling """ Log widget with auto-scroll. """ while True: # https://pyimgui.readthedocs.io/en/latest/reference/imgui.core.html#imgui.core.push_text_wrap_position imgui.push_text_wrap_pos() # Colored logging for t in self.log_list: text, color = t r, g, b = color imgui.text_colored(text, r, g, b) imgui.pop_text_wrap_pos() if imgui.get_scroll_y() >= imgui.get_scroll_max_y() - 30: imgui.set_scroll_here(1.0) yield
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 main(): window = impl_glfw_init() impl = GlfwImpl(window) opened = True 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_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_user_guide() imgui.show_test_window() if opened: expanded, opened = imgui.begin("fooo", True) imgui.text("Bar") imgui.text_colored("Eggs", 0.2, 1., 0.) imgui.end() with imgui.styled(imgui.STYLE_ALPHA, 1): imgui.show_metrics_window() gl.glClearColor(114 / 255., 144 / 255., 154 / 255., 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() glfw.swap_buffers(window) impl.shutdown() imgui.shutdown() glfw.terminate()
def main(): imgui.create_context() window = impl_glfw_init() impl = GlfwRenderer(window) 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_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("Custom window", True) imgui.text("Bar") imgui.text_colored("Eggs", 0.2, 1., 0.) 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_inspector_keyboard ( self ): imgui.begin_child( "keyboard", 0, 0, border = True ) if self.context != None: current_keys = list( self.get_pressed_keystrokes() ) keyboard : KeyboardLibrary = self.context.library( KeyboardLibrary ) for key in current_keys: keyboard.on_press( key, self.player ) released = set( keyboard.pressed_keys ) - set( current_keys ) for key in released: keyboard.on_release( key, self.player ) for key, expr in keyboard.keys: imgui.bullet() if expr.is_pressed: imgui.text_colored( str( key ), 0, 1, 0 ) else: imgui.text( str( key ) ) imgui.end_child()
def render_ui(self): 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("Custom window", True) imgui.text("Bar") imgui.text_colored("Eggs", 0.2, 1., 0.) imgui.end() imgui.render() self.imgui.render(imgui.get_draw_data())
def main(): window = impl_glfw_init() impl = GlfwRenderer(window) 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_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("Custom window", True) imgui.text("Bar") imgui.text_colored("Eggs", 0.2, 1., 0.) imgui.end() display() imgui.render() glfw.swap_buffers(window) impl.shutdown() imgui.shutdown() glfw.terminate()
def render_ui(self): imgui.new_frame() imgui.begin("Description - Functions", False) imgui.text("This is a visualisation of two variable functions") imgui.text("Points are colored based on their Z coordinate") imgui.text("Same visualisation could be used for heatmaps or simillar data") imgui.text("FPS: %.2f" % self.fps) imgui.end() imgui.begin("Controls - Functions", False) imgui.text("UP and DOWN to change colors") imgui.text("Press 1,2,3,4,5,6 to change function") imgui.text("LEFT and RIGHT to change point size") imgui.text_colored("Warning:", 1,0,0) imgui.text("Depending on your machine, this may take a while") imgui.end() imgui.render() self.imgui.render(imgui.get_draw_data())
def drawTools(self): imgui.begin("Drawing Tools") if self.draw_mode == "c": imgui.text_colored("Currently drawing: Circle", 0.0, 1.0, 0.0) elif self.draw_mode == "e": imgui.text_colored("Currently drawing: Circle", 0.0, 1.0, 0.0) else: imgui.text_colored("Nothing Currently Selected.", 0.0, 1.0, 0.0) imgui.new_line() if imgui.button("Circle", 100, 20): # imgui.core.button, https://github.com/ocornut/imgui/issues/2481 self.draw_mode = 'c' imgui.same_line(115) if imgui.button("Ellipse", 100, 20): self.draw_mode = 'e' if self.draw_mode == 'c': changed, self.vrad = imgui.input_int("Radius", self.vrad, 1, 100) # imgui.core.input_int changed, self.x_center = imgui.input_int("X-axis center", self.x_center, 1, 800) # imgui.core.slider_int, set max to window size changed, self.y_center = imgui.input_int("Y-axis center", self.y_center, 1, 600) changed, self.color = imgui.color_edit3("Set Color", *self.color) # asterisk used for tuple, I think... elif self.draw_mode == 'e': changed, self.vrad = imgui.input_int("Vertical Radius", self.vrad, 1, 100) # imgui.core.input_int # changed, self.vrad = imgui.slider_int("", self.vrad, 0, 1000) changed, self.hrad = imgui.input_int("Horizontal Radius", self.hrad, 1, 100) # changed, self.hrad = imgui.slider_int("Horizontal Radius", self.hrad, 0, 1000) changed, self.x_center = imgui.input_int("X-axis center", self.x_center, 1, 800) # imgui.core.slider_int, set max to window size changed, self.y_center = imgui.input_int("Y-axis center", self.y_center, 1, 600) changed, self.color = imgui.color_edit3("Set Color", *self.color) # asterisk used for tuple, I think... imgui.new_line() if imgui.button("Reset", 100, 20): self.color = [.0, .0, .0] self.draw_mode = "" self.vrad = 0 self.hrad = 0 self.x_center = 400 self.y_center = 300 imgui.same_line(115) if imgui.button("Enter", 100, 20): if self.draw_mode == "": pass elif self.draw_mode == "c": drawCircle = Circle(self.x_center, self.y_center, self.vrad, color=Color(self.color[0], self.color[1], self.color[2])) self.canvas.add_object(drawCircle) elif self.draw_mode == "e": drawEllipse = Ellipse(self.x_center, self.y_center, self.vrad, self.hrad, color=Color(self.color[0], self.color[1], self.color[2])) self.canvas.add_object(drawEllipse) imgui.end()