How to use the imgui.Vec2 function in imgui

To help you get started, we’ve selected a few imgui examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pthom / imgui_datascience / imgui_datascience / imgui_cv.py View on Github external
def mouse_position_last_image():
    io = imgui.get_io()
    mouse = io.mouse_pos
    rect_min = imgui.get_item_rect_min()
    mouse_relative = imgui.Vec2(mouse.x - rect_min.x, mouse.y - rect_min.y)
    if not _is_in_last_image(mouse_relative):
        return None
    else:
        return mouse_relative
github pthom / imgui_datascience / imgui_datascience / imgui_image_lister.py View on Github external
def _max_image_size(self):
        win_size = imgui.get_window_size()
        max_image_size = imgui.Vec2(win_size.x - (self.listbox_width + 40), win_size.y - 150)
        return max_image_size
github pthom / imgui_datascience / imgui_datascience / imgui_image_lister.py View on Github external
def actual_window_startup_size(self):
        if self.max_size:
            display_size = imgui.get_io().display_size
            return imgui.Vec2(display_size.x - 40, display_size.y - 20)
        else:
            return self.window_size
github pthom / imgui_datascience / imgui_datascience / _imgui_cv_zoom.py View on Github external
def image_explorer_impl(
    im: ImageWithZoomInfo, title:str = "", always_refresh:bool = False) \
    -> Optional[imgui.Vec2]:

    """
    :return: imgui.Vec2 (mouse_location_original_image) or None (if not on image)
    """
    linked_user_image_address = id(im.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,
        always_refresh=always_refresh,
        linked_user_image_address=linked_user_image_address
        )
    mouse_location_original_image = None
    viewport_center_original_image = im.viewport_center_original_image()
github pthom / imgui_datascience / imgui_datascience / _imgui_cv_zoom.py View on Github external
)
    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])
github pthom / imgui_datascience / imgui_datascience / imgui_image_lister.py View on Github external
def image_size_fit_in_gui(image_size, gui_size, can_make_bigger=False):
    # type: (imgui.Vec2, imgui.Vec2, bool) -> imgui.Vec2
    if image_size.x <= gui_size.x and image_size.y <= gui_size.y and not can_make_bigger:
        return image_size
    else:
        k_item = image_size.x / image_size.y
        k_gui = gui_size.x / gui_size.y
        if k_item > k_gui:
            return imgui.Vec2(gui_size.x, image_size.y / image_size.x * gui_size.x)
        else:
            return imgui.Vec2(image_size.x / image_size.y * gui_size.y, gui_size.y)
github pthom / imgui_datascience / imgui_datascience / imgui_image_lister.py View on Github external
def __init__(self):
        self.images_info = OrderedDict()
        self.current_image = ""
        self.opened = False
        self.never_shown = True
        self.listbox_width = 240
        self.position = imgui.Vec2(500, 50)
        self.window_size = imgui.Vec2(1000, 800)
        self.max_size = False