File size: 3,189 Bytes
f12ab4c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# SPDX-FileCopyrightText: Copyright (c) 2021-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: LicenseRef-NvidiaProprietary
#
# NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
# property and proprietary rights in and to this material, related
# documentation and any modifications thereto. Any use, reproduction,
# disclosure or distribution of this material and related documentation
# without an express license agreement from NVIDIA CORPORATION or
# its affiliates is strictly prohibited.
import imgui
from gui_utils import imgui_utils
#----------------------------------------------------------------------------
class StyleMixingWidget:
def __init__(self, viz):
self.viz = viz
self.seed_def = 1000
self.seed = self.seed_def
self.animate = False
self.enables = []
@imgui_utils.scoped_by_object_id
def __call__(self, show=True):
viz = self.viz
num_ws = viz.result.get('num_ws', 0)
num_enables = viz.result.get('num_ws', 18)
self.enables += [False] * max(num_enables - len(self.enables), 0)
if show:
imgui.text('Stylemix')
imgui.same_line(viz.label_w)
with imgui_utils.item_width(viz.font_size * 8), imgui_utils.grayed_out(num_ws == 0):
_changed, self.seed = imgui.input_int('##seed', self.seed)
imgui.same_line(viz.label_w + viz.font_size * 8 + viz.spacing)
with imgui_utils.grayed_out(num_ws == 0):
_clicked, self.animate = imgui.checkbox('Anim', self.animate)
pos2 = imgui.get_content_region_max()[0] - 1 - viz.button_w
pos1 = pos2 - imgui.get_text_line_height() - viz.spacing
pos0 = viz.label_w + viz.font_size * 12
imgui.push_style_var(imgui.STYLE_FRAME_PADDING, [0, 0])
for idx in range(num_enables):
imgui.same_line(round(pos0 + (pos1 - pos0) * (idx / (num_enables - 1))))
if idx == 0:
imgui.set_cursor_pos_y(imgui.get_cursor_pos_y() + 3)
with imgui_utils.grayed_out(num_ws == 0):
_clicked, self.enables[idx] = imgui.checkbox(f'##{idx}', self.enables[idx])
if imgui.is_item_hovered():
imgui.set_tooltip(f'{idx}')
imgui.pop_style_var(1)
imgui.same_line(pos2)
imgui.set_cursor_pos_y(imgui.get_cursor_pos_y() - 3)
with imgui_utils.grayed_out(num_ws == 0):
if imgui_utils.button('Reset', width=-1, enabled=(self.seed != self.seed_def or self.animate or any(self.enables[:num_enables]))):
self.seed = self.seed_def
self.animate = False
self.enables = [False] * num_enables
if any(self.enables[:num_ws]):
viz.args.stylemix_idx = [idx for idx, enable in enumerate(self.enables) if enable]
viz.args.stylemix_seed = self.seed & ((1 << 32) - 1)
if self.animate:
self.seed += 1
#----------------------------------------------------------------------------
|