Skip to content

Commit

Permalink
Merge pull request #5 from hostedposted/development
Browse files Browse the repository at this point in the history
1.5.0
  • Loading branch information
hostedposted authored Jul 2, 2022
2 parents 7cb9415 + 003b080 commit 3e1ea7e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
11 changes: 6 additions & 5 deletions docs/call-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +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. |
| 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
24 changes: 24 additions & 0 deletions pygui/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ def button(
text_color[2] / 255,
text_color[3],
)
if key:
imgui.push_id(key)
clicked = imgui.button(text)
if key:
imgui.pop_id()
if wrap_text:
imgui.pop_text_wrap_pos()
if isinstance(text_color, tuple):
Expand Down Expand Up @@ -252,12 +256,16 @@ def checkbox(
bool
If the checkbox is checked.
"""
if key:
imgui.push_id(key)
changed, value = imgui.checkbox(
" " + 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 changed:
self.state[label] = value
return value
Expand Down Expand Up @@ -304,10 +312,14 @@ def color_picker(
default_value = default_value + (1,)
else:
default_value = default_value + (old_default_value[3],)
if key:
imgui.push_id(key)
changed, value = func(
" " + label, # Adding a space to the label make's it look better
*self.state.setdefault(key or label, default_value),
)
if key:
imgui.pop_id()
if changed:
self.state[key or label] = value
rgb = (round(value[0] * 255), round(value[1] * 255), round(value[2] * 255))
Expand Down Expand Up @@ -350,9 +362,13 @@ def input_int(
"""
if wrap_text:
imgui.push_text_wrap_pos(imgui.get_window_width() * WRAPPING_PERCENTAGE)
if key:
imgui.push_id(key)
changed, value = imgui.input_int(
" " + 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:
Expand Down Expand Up @@ -391,11 +407,15 @@ def input_text(
"""
if wrap_text:
imgui.push_text_wrap_pos(imgui.get_window_width() * WRAPPING_PERCENTAGE)
if key:
imgui.push_id(key)
changed, value = imgui.input_text(
" " + label,
self.state.setdefault(key or label, default_value),
max_length + 1,
) # 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:
Expand Down Expand Up @@ -433,9 +453,13 @@ def combo(
"""
if wrap_text:
imgui.push_text_wrap_pos(imgui.get_window_width() * WRAPPING_PERCENTAGE)
if key:
imgui.push_id(key)
changed, value = imgui.combo(
" " + label, self.state.setdefault(key or label, default_value), choices
) # Adding a space to the label make's it look better
if key:
imgui.pop_id()
if changed:
self.state[key or label] = value
if wrap_text:
Expand Down
11 changes: 8 additions & 3 deletions pygui/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
File for handling the window.
"""
import os
from typing import Callable, Dict, List, Literal, NamedTuple, Optional, Type
from typing import Callable, Dict, List, Literal, NamedTuple, Optional, Tuple, Type

import darkdetect
import glfw
Expand Down Expand Up @@ -64,6 +64,7 @@ class Frame(NamedTuple):
title: str
width: int
height: int
position: Optional[Tuple[int, int]]


class Menu(NamedTuple):
Expand Down Expand Up @@ -192,6 +193,10 @@ def start(self):
imgui.set_next_window_size(
frame.width, frame.height, imgui.FIRST_USE_EVER
)
if len(frame.position or ()) == 2:
imgui.set_next_window_position(
frame.position[0], frame.position[1], imgui.FIRST_USE_EVER
)
imgui.begin(frame.title)
frame.func(Elements(self.state))
imgui.end()
Expand All @@ -204,7 +209,7 @@ def start(self):
impl.shutdown()
glfw.terminate()

def frame(self, title: str, width: int = None, height: int = None):
def frame(self, title: str, width: int = None, height: int = None, position: Optional[Tuple[int, int]] = None):
"""
Create a decorator to create a frame.
Expand All @@ -223,7 +228,7 @@ def frame(self, title: str, width: int = None, height: int = None):
The decorator.
"""
return lambda func: self.frames.append(
Frame(func=func, title=title, width=width, height=height)
Frame(func=func, title=title, width=width, height=height, position=position)
)

def menu(self, category: str, title: str, keys: List[KEY] = None):
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "py-gui-tool"
version = "1.4.0"
version = "1.5.0"
description = "PyGui is an easy to use gui."
authors = ["hostedposted <[email protected]>"]
license = "MIT"
Expand All @@ -10,7 +10,7 @@ packages = [
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.9"
python = "^3.8"
glfw = "^2.5.3"
PyOpenGL = "^3.1.6"
imgui = {extras = ["glfw"], version = "^1.4.1"}
Expand Down

0 comments on commit 3e1ea7e

Please sign in to comment.