@@ -154,29 +154,52 @@ void ST7920Device::ui_widget() {
154154 static long int call_count = 0 ;
155155 static uint8_t up_held = 0 , down_held = 0 ;
156156 call_count++;
157+ bool popout_begin = false ;
157158
158159 auto size = ImGui::GetContentRegionAvail ();
159- size.y = size.x / (width / (float )height);
160- ImGui::BeginChild (" ST7920Device" , size);
161- ImGui::GetCurrentWindow ()->ScrollMax .y = 1 .0f ; // disable window scroll
162-
163- ImGui::Image ((ImTextureID)(intptr_t )texture_id, size, ImVec2 (0 ,0 ), ImVec2 (1 ,1 ));
164-
165- if (ImGui::IsWindowFocused ()) {
166- key_pressed[KeyName::KILL_BUTTON] = ImGui::IsKeyDown (SDL_SCANCODE_K);
167- key_pressed[KeyName::ENCODER_BUTTON] = ImGui::IsKeyDown (SDL_SCANCODE_SPACE) || ImGui::IsKeyDown (SDL_SCANCODE_RETURN) || ImGui::IsKeyDown (SDL_SCANCODE_RIGHT);
168- key_pressed[KeyName::BACK_BUTTON] = ImGui::IsKeyDown (SDL_SCANCODE_LEFT);
169-
170- // Turn keypresses (and repeat) into encoder clicks
171- if (up_held) { up_held--; encoder_position--; }
172- else if (ImGui::IsKeyPressed (SDL_SCANCODE_UP)) up_held = 4 ;
173- if (down_held) { down_held--; encoder_position++; }
174- else if (ImGui::IsKeyPressed (SDL_SCANCODE_DOWN)) down_held = 4 ;
175-
176- if (ImGui::IsItemHovered ()) {
177- key_pressed[KeyName::ENCODER_BUTTON] |= ImGui::IsMouseClicked (0 );
178- encoder_position += ImGui::GetIO ().MouseWheel > 0 ? 1 : ImGui::GetIO ().MouseWheel < 0 ? -1 : 0 ;
160+ size.y = ((size.x / (width / (float )height)) * !render_popout) + 60 ;
161+
162+ if (ImGui::BeginChild (" ST7920Device" , size)) {
163+ ImGui::GetCurrentWindow ()->ScrollMax .y = 1 .0f ; // disable window scroll
164+ ImGui::Checkbox (" Integer Scaling" , &render_integer_scaling);
165+ ImGui::Checkbox (" Popout" , &render_popout);
166+
167+ if (render_popout) {
168+ ImGui::SetNextWindowSize (ImVec2 (width + 10 , height + 10 ), ImGuiCond_Once);
169+ popout_begin = ImGui::Begin (" ST7920DeviceRender" , &render_popout);
170+ if (!popout_begin) {
171+ ImGui::End ();
172+ return ;
173+ }
174+ size = ImGui::GetContentRegionAvail ();
175+ }
176+
177+ double scale = size.x / width;
178+ if (render_integer_scaling) {
179+ scale = scale > 1.0 ? std::floor (scale) : scale;
180+ size.x = width * scale;
179181 }
182+ size.y = height * scale;
183+
184+ ImGui::Image ((ImTextureID)(intptr_t )texture_id, size, ImVec2 (0 ,0 ), ImVec2 (1 ,1 ));
185+ if (ImGui::IsWindowFocused ()) {
186+ key_pressed[KeyName::KILL_BUTTON] = ImGui::IsKeyDown (SDL_SCANCODE_K);
187+ key_pressed[KeyName::ENCODER_BUTTON] = ImGui::IsKeyDown (SDL_SCANCODE_SPACE) || ImGui::IsKeyDown (SDL_SCANCODE_RETURN) || ImGui::IsKeyDown (SDL_SCANCODE_RIGHT);
188+ key_pressed[KeyName::BACK_BUTTON] = ImGui::IsKeyDown (SDL_SCANCODE_LEFT);
189+
190+ // Turn keypresses (and repeat) into encoder clicks
191+ if (up_held) { up_held--; encoder_position--; }
192+ else if (ImGui::IsKeyPressed (SDL_SCANCODE_UP)) up_held = 4 ;
193+ if (down_held) { down_held--; encoder_position++; }
194+ else if (ImGui::IsKeyPressed (SDL_SCANCODE_DOWN)) down_held = 4 ;
195+
196+ if (ImGui::IsItemHovered ()) {
197+ key_pressed[KeyName::ENCODER_BUTTON] |= ImGui::IsMouseClicked (0 );
198+ encoder_position += ImGui::GetIO ().MouseWheel > 0 ? 1 : ImGui::GetIO ().MouseWheel < 0 ? -1 : 0 ;
199+ }
200+ }
201+
202+ if (popout_begin) ImGui::End ();
180203 }
181204 ImGui::EndChild ();
182205}
0 commit comments