def __init__(self, parent: ba.Widget, position: Tuple[float, float], choices: Sequence[str], current_choice: str = None, on_value_change_call: Callable[[str], Any] = None, opening_call: Callable[[], Any] = None, closing_call: Callable[[], Any] = None, width: float = 230.0, maxwidth: float = None, scale: float = None, choices_disabled: Sequence[str] = None, choices_display: Sequence[ba.Lstr] = None, button_size: Tuple[float, float] = (160.0, 50.0), autoselect: bool = True): if choices_disabled is None: choices_disabled = [] if choices_display is None: choices_display = [] if scale is None: scale = (2.3 if ba.app.small_ui else 1.65 if ba.app.med_ui else 1.23) if current_choice not in choices: current_choice = None self._choices = list(choices) if not choices: raise Exception('no choices given') self._choices_display = list(choices_display) self._choices_disabled = list(choices_disabled) self._width = width self._maxwidth = maxwidth self._scale = scale self._current_choice = (current_choice if current_choice is not None else self._choices[0]) self._position = position self._parent = parent if not choices: raise Exception('Must pass at least one choice') self._parent = parent self._button_size = button_size self._button = ba.buttonwidget( parent=self._parent, position=(self._position[0], self._position[1]), autoselect=autoselect, size=self._button_size, scale=1.0, label='', on_activate_call=lambda: ba.timer( 0, self._make_popup, timetype=ba.TimeType.REAL)) self._on_value_change_call = None # Don't wanna call for initial set. self._opening_call = opening_call self._autoselect = autoselect self._closing_call = closing_call self.set_choice(self._current_choice) self._on_value_change_call = on_value_change_call self._window_widget: Optional[ba.Widget] = None # Complain if we outlive our button. ba.uicleanupcheck(self, self._button)
def __init__(self, parent: ba.Widget, configkey: str, position: Tuple[float, float], size: Tuple[float, float], displayname: Union[str, ba.Lstr] = None, scale: float = None, maxwidth: float = None, autoselect: bool = True, value_change_call: Callable[[Any], Any] = None): if displayname is None: displayname = configkey self._value_change_call = value_change_call self._configkey = configkey self.widget = ba.checkboxwidget( parent=parent, autoselect=autoselect, position=position, size=size, text=displayname, textcolor=(0.8, 0.8, 0.8), value=ba.app.config.resolve(configkey), on_value_change_call=self._value_changed, scale=scale, maxwidth=maxwidth) # complain if we outlive our checkbox ba.uicleanupcheck(self, self.widget)
def __init__(self, position: Tuple[float, float], size: Tuple[float, float], scale: float = 1.0, offset: Tuple[float, float] = (0, 0), bg_color: Tuple[float, float, float] = (0.35, 0.55, 0.15), focus_position: Tuple[float, float] = (0, 0), focus_size: Tuple[float, float] = None, toolbar_visibility: str = 'menu_minimal_no_back'): # pylint: disable=too-many-locals if focus_size is None: focus_size = size # In vr mode we can't have windows going outside the screen. if ba.app.vr_mode: focus_size = size focus_position = (0, 0) width = focus_size[0] height = focus_size[1] # Ok, we've been given a desired width, height, and scale; # we now need to ensure that we're all onscreen by scaling down if # need be and clamping it to the UI bounds. bounds = ba.app.ui_bounds edge_buffer = 15 bounds_width = (bounds[1] - bounds[0] - edge_buffer * 2) bounds_height = (bounds[3] - bounds[2] - edge_buffer * 2) fin_width = width * scale fin_height = height * scale if fin_width > bounds_width: scale /= (fin_width / bounds_width) fin_width = width * scale fin_height = height * scale if fin_height > bounds_height: scale /= (fin_height / bounds_height) fin_width = width * scale fin_height = height * scale x_min = bounds[0] + edge_buffer + fin_width * 0.5 y_min = bounds[2] + edge_buffer + fin_height * 0.5 x_max = bounds[1] - edge_buffer - fin_width * 0.5 y_max = bounds[3] - edge_buffer - fin_height * 0.5 x_fin = min(max(x_min, position[0] + offset[0]), x_max) y_fin = min(max(y_min, position[1] + offset[1]), y_max) # ok, we've calced a valid x/y position and a scale based on or # focus area. ..now calc the difference between the center of our # focus area and the center of our window to come up with the # offset we'll need to plug in to the window x_offs = ((focus_position[0] + focus_size[0] * 0.5) - (size[0] * 0.5)) * scale y_offs = ((focus_position[1] + focus_size[1] * 0.5) - (size[1] * 0.5)) * scale self.root_widget = ba.containerwidget( transition='in_scale', scale=scale, toolbar_visibility=toolbar_visibility, size=size, parent=_ba.get_special_widget('overlay_stack'), stack_offset=(x_fin - x_offs, y_fin - y_offs), scale_origin_stack_offset=(position[0], position[1]), on_outside_click_call=self.on_popup_cancel, claim_outside_clicks=True, color=bg_color, on_cancel_call=self.on_popup_cancel) # complain if we outlive our root widget ba.uicleanupcheck(self, self.root_widget)
def __init__(self, parent: ba.Widget, configkey: str, position: Tuple[float, float], minval: float = 0.0, maxval: float = 100.0, increment: float = 1.0, callback: Callable[[float], Any] = None, xoffset: float = 0.0, displayname: Union[str, ba.Lstr] = None, changesound: bool = True, textscale: float = 1.0): if displayname is None: displayname = configkey self._configkey = configkey self._minval = minval self._maxval = maxval self._increment = increment self._callback = callback self._value = ba.app.config.resolve(configkey) self.nametext = ba.textwidget(parent=parent, position=position, size=(100, 30), text=displayname, maxwidth=160 + xoffset, color=(0.8, 0.8, 0.8, 1.0), h_align='left', v_align='center', scale=textscale) self.valuetext = ba.textwidget(parent=parent, position=(246 + xoffset, position[1]), size=(60, 28), editable=False, color=(0.3, 1.0, 0.3, 1.0), h_align='right', v_align='center', text=str(self._value), padding=2) self.minusbutton = ba.buttonwidget( parent=parent, position=(330 + xoffset, position[1]), size=(28, 28), label='-', autoselect=True, on_activate_call=ba.Call(self._down), repeat=True, enable_sound=changesound) self.plusbutton = ba.buttonwidget(parent=parent, position=(380 + xoffset, position[1]), size=(28, 28), label='+', autoselect=True, on_activate_call=ba.Call(self._up), repeat=True, enable_sound=changesound) # Complain if we outlive our widgets. ba.uicleanupcheck(self, self.nametext) self._update_display()