Skip to content

Commit

Permalink
Merge pull request #6 from hostedposted/development
Browse files Browse the repository at this point in the history
Version 1.6.0
  • Loading branch information
hostedposted authored Jul 2, 2022
2 parents 3e1ea7e + d0f56cf commit 9571627
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 7 deletions.
44 changes: 38 additions & 6 deletions docs/call-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ On this page, you will find a list of all the functions and methods that are ava

[:octicons-tag-24: 1.0.2](https://github.com/hostedposted/py-gui/tree/1.0.2) - Add a frame to the window.

| Parameter | Latest Change | Type | Required | Default Value | Description |
| :-------- | ---------------------------------------------------------------------------- | :------------ | :--------------- | :--------------- | :------------------------------- |
| title | [:octicons-tag-24: 1.0.2](https://github.com/hostedposted/py-gui/tree/1.0.2) | string | :material-check: | :material-close: | This will be the frame's title. |
| width | [:octicons-tag-24: 1.0.2](https://github.com/hostedposted/py-gui/tree/1.0.2) | integer | :material-close: | Minimum Possible | This will be the frame's width. |
| height | [:octicons-tag-24: 1.0.2](https://github.com/hostedposted/py-gui/tree/1.0.2) | integer | :material-close: | Minimum Possible | This will be the frame's height. |
| position | [:octicons-tag-24: 1.5.0](https://github.com/hostedposted/py-gui/tree/1.5.0) | tuple of ints | :material-close: | 0, 0 | This will be the position of the frame. |
| Parameter | Latest Change | Type | Required | Default Value | Description |
| :-------- | ---------------------------------------------------------------------------- | :------------ | :--------------- | :--------------- | :-------------------------------------- |
| title | [:octicons-tag-24: 1.0.2](https://github.com/hostedposted/py-gui/tree/1.0.2) | string | :material-check: | :material-close: | This will be the frame's title. |
| width | [:octicons-tag-24: 1.0.2](https://github.com/hostedposted/py-gui/tree/1.0.2) | integer | :material-close: | Minimum Possible | This will be the frame's width. |
| height | [:octicons-tag-24: 1.0.2](https://github.com/hostedposted/py-gui/tree/1.0.2) | integer | :material-close: | Minimum Possible | This will be the frame's height. |
| position | [:octicons-tag-24: 1.5.0](https://github.com/hostedposted/py-gui/tree/1.5.0) | tuple of ints | :material-close: | 0, 0 | This will be the position of the frame. |

??? example

Expand Down Expand Up @@ -358,6 +358,38 @@ Returns the index of the selected choice.
![Example Image](images/input-int-example.jpg)


### Elements.input_float(label, default_value, minimum, maximum, key, wrap_text)

[:octicons-tag-24: 1.6.0](https://github.com/hostedposted/py-gui/tree/1.6.0) - Add an input to the frame that only accepts floats.

| Parameter | Latest Change | Type | Required | Default Value | Description |
| :------------ | ---------------------------------------------------------------------------- | :------------- | :--------------- | :---------------- | :------------------------------------------------------------------- |
| label | [:octicons-tag-24: 1.6.0](https://github.com/hostedposted/py-gui/tree/1.6.0) | string | :material-check: | :material-close: | This text will appear after the input. |
| default_value | [:octicons-tag-24: 1.6.0](https://github.com/hostedposted/py-gui/tree/1.6.0) | float | :material-check: | 0 | The default value of the input. |
| minimum | [:octicons-tag-24: 1.6.0](https://github.com/hostedposted/py-gui/tree/1.6.0) | float | :material-close: | negative infinity | The minimum value of the input. |
| maximum | [:octicons-tag-24: 1.6.0](https://github.com/hostedposted/py-gui/tree/1.6.0) | float | :material-close: | positive infinity | The maximum value of the input. |
| key | [:octicons-tag-24: 1.6.0](https://github.com/hostedposted/py-gui/tree/1.6.0) | string or None | :material-close: | None | What the value will be saved under in the [state](#elementsstate_1). |
| wrap_text | [:octicons-tag-24: 1.6.0](https://github.com/hostedposted/py-gui/tree/1.6.0) | boolean | :material-close: | True | Wether or not the text should be wrapped. |

??? example

Let's add an input to the frame.

```py
import pygui

window = pygui.Window("Hello World")

@window.frame("Hello World", width=700, height=450)
def hello_world(elements: pygui.Elements):
value = elements.input_float("3.5 + 4", 7.5)
elements.text(f"You picked: {value}")

window.start()
```
![Example Image](images/input-float-example.jpg)


### Elements.input_text(label, default_value, key, wrap_text, max_length)

[:octicons-tag-24: 1.0.2](https://github.com/hostedposted/py-gui/tree/1.0.2) - Add an input to the frame.
Expand Down
Binary file added docs/images/input-float-example.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions pygui/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,54 @@ def input_int(
self.state[key or label] = value
return value

def input_float(
self,
label: str,
default_value: float = 0,
minimum: float = -math.inf,
maximum: float = math.inf,
key: Optional[str] = None,
wrap_text: bool = True,
):
"""
Create a float input.
Parameters
----------
label : str
Text that will be displayed after the input.
default_value : float, optional
The default value, by default 0
minimum : float, optional
The minimum value that can be entered, by default -math.inf
maximum : float, optional
The maximum value that can be entered, by default math.inf
key : Optional[str], optional
A key for the input. This can be used for accessing the state of the element before it is added to the frame, by default None
wrap_text : bool, optional
Wether or not the text should be wrapped to fit, by default True
Returns
-------
float
The value entered.
"""
if wrap_text:
imgui.push_text_wrap_pos(imgui.get_window_width() * WRAPPING_PERCENTAGE)
if key:
imgui.push_id(key)
changed, value = imgui.input_float(
" " + label, self.state.setdefault(key or label, default_value)
) # Adding a space to the label make's it look better
if key:
imgui.pop_id()
if wrap_text:
imgui.pop_text_wrap_pos()
if changed:
value = clamp(value, minimum, maximum)
self.state[key or label] = value
return value

def input_text(
self,
label: str,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "py-gui-tool"
version = "1.5.0"
version = "1.6.0"
description = "PyGui is an easy to use gui."
authors = ["hostedposted <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 9571627

Please sign in to comment.