Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Nats-ji authored Feb 19, 2021
1 parent 4d46587 commit fbd1561
Showing 1 changed file with 57 additions and 41 deletions.
98 changes: 57 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,54 @@ I also included some useful functions for easier and faster ImGui styling.

Please make PR if you want to fix bugs or make improvements
### How to use
```lua
CPS = require "CPStyling"
theme = CPS.theme
color = CPS.color
```

To use `CPS.loadPNG()` and `CPS.CPDraw()` functions, you need to include the `png-lua` library.
1. Add this library to your mod's requirements list (You do not need to include this lib in your mod) [[Github]](https://github.com/Nats-ji/CPStyling.lua/releases/latest) | [[Nexus]](https://www.nexusmods.com/users/106335388?tab=user+files)
2. Require CPStyling
```lua
CPS = GetMod("CPStyling"):New() -- Read below to learn how to use custom theme
theme = CPS.theme
color = CPS.color
```

#This project is still WIP, will add more widgets. You can also download the demo to play with it yourself.
\*This project is still WIP, will add more widgets. You can also download the demo to play with it yourself.

![Imgur](https://i.imgur.com/fe3cd4w.png)

### Projects using this library
CP77-TetrisArcade [[Nexus]](https://www.nexusmods.com/cyberpunk2077/mods/1118) | [[Github]](https://github.com/justarandomguyintheinternet/cp77_arcade_tetris)

![Imgur](https://i.imgur.com/zrhar0j.png)

CP77-Braindance Protocol [[Nexus]](https://www.nexusmods.com/cyberpunk2077/mods/616) | [[Github]](https://github.com/WolvenKit/BraindanceProtocol)

![Imgur](https://i.imgur.com/bVqLG7c.png)
| CP77-TetrisArcade [[Nexus]](https://www.nexusmods.com/cyberpunk2077/mods/1118) \| [[Github]](https://github.com/justarandomguyintheinternet/cp77_arcade_tetris) | CP77-Braindance Protocol [[Nexus]](https://www.nexusmods.com/cyberpunk2077/mods/616) \| [[Github]](https://github.com/WolvenKit/BraindanceProtocol) |
| ------------------ | ------------------ |
| ![Imgur](https://i.imgur.com/zrhar0j.png) | ![Imgur](https://i.imgur.com/bVqLG7c.png) |

### Custom theme
1. To use custom theme, you need to put your mod's name in `GetMod("CPStyling"):New(mod_name)`
```lua
CPS = GetMod("CPStyling"):New(mod_name)
```
2. Duplicate `./themes/default.lua` and rename it to `your_mod_name.lua`
3. Change the color scheme in `your_mod_name.lua` as you like
4. Package your mod like this:
```
.\bin\x64\plugins\cyber_engine_tweaks\mods\
├─ CPStyling
│ └─ themes
│ └─ your_mod_name.lua
└─ your_mod_name
├─ init.lua
└─ ...
```

### Utilities
```lua
--Check if a file exists
CPS.fileExists(filename)
--returns bool

--Setup the style for a new window and it's content.
CPS.setThemeBegin()
CPS:setThemeBegin()
-- ImGui.Begin("I'm a window")
-- ImGui.End()
CPS.setThemeEnd()
CPS:setThemeEnd()

--Setup the style for frame items (Checkbox, Combobox, Inputbox, etc.),
--Needs to be put bellow ImGui.Begin() or window's title will also be bordered.
CPS.setFrameThemeBegin()
CPS.setFrameThemeEnd()
--Needs to be put inside ImGui.Begin() and ImGui.End() or window's title will also be bordered.
CPS:setFrameThemeBegin()
CPS:setFrameThemeEnd()

--Same as ImGui.PushStyleColor(ImGuiCol.style, r, g, b, a), but can take any color format.
CPS.colorBegin(style, color)
Expand Down Expand Up @@ -85,65 +96,67 @@ CPButton:

![Imgur](https://i.imgur.com/4neA19J.gif)
```lua
press = CPS.CPButton(label)
press = CPS.CPButton(label, sizex, sizey)
press = CPS:CPButton(label)
press = CPS:CPButton(label, sizex, sizey)
-- label (string), sizex (float), sizey (float)
-- Returns press (bool)

---Example---
btn1 = CPS.CPButton("Btn1")
btn2 = CPS.CPButton("Btn2", 50, 30)
btn1 = CPS:CPButton("Btn1")
btn2 = CPS:CPButton("Btn2", 50, 30)
```
CPToggle:

![Imgur](https://i.imgur.com/gTwpaLY.gif)
```lua
value, press = CPS.CPToggle(label, label_on, label_off, value, sizex, sizey)
value, press = CPS:CPToggle(label, label_on, label_off, value, sizex, sizey)
-- label (string), label_on (string), label_off (string), value (bool), sizex (float), sizey (float)
-- Returns value (bool), press (bool)

---Example---
value, press = CPS.CPToggle("Toggle godmode", "OFF", "ON", value, 180, 0)
value, press = CPS:CPToggle("Toggle godmode", "OFF", "ON", value, 180, 0)
```
CPToolTip:

![Imgur](https://i.imgur.com/i467ORZ.gif)
```lua
CPS.CPToolTip1Begin(sizex, sizey)
CPS:CPToolTip1Begin(sizex, sizey)
-- ImGui.Text("This is a CPToolTip1")
CPS.CPToolTip1End()
CPS:CPToolTip1End()

CPS.CPToolTip2Begin(sizex, sizey)
CPS:CPToolTip2Begin(sizex, sizey)
-- ImGui.Text("This is a CPToolTip2")
CPS.CPToolTip2End()
CPS:CPToolTip2End()
```
CPRect:

![Imgur](https://i.imgur.com/M5FHWtb.png)
```lua
press = CPS.CPRect1(label, sizex, sizey, color, border_color [O], border_size [O], border_rounding [O], textalignx [O], textaligny [O])
press = CPS:CPRect1(label, sizex, sizey, color, border_color [O], border_size [O], border_rounding [O], textalignx [O], textaligny [O])
-- lable (string), sizex (float), sizey (float), color (any format), border_color (any format)
-- border_size (float), border_rounding (float), textalignx (float), textaligny (float)
-- Returns press (bool)

CPS.CPRect2(text_id, sizex, sizey, color)
CPS:CPRect2(text_id, sizex, sizey, color)
-- text_id (string), sizex (float), sizey(float), color (any format)
-- Faster than CPRect1 but without return value.
-- Also used in CPS.CPDraw()

---Example---
-- Draw a red 50x50 Circle
CPS.CPRect1("##circle", 50, 50, {0,0,0,0}, color.red, 5, 25)
CPS:CPRect1("##circle", 50, 50, {0,0,0,0}, color.red, 5, 25)
-- Draw a green rounded rectangle with a brown border and text inside aligned to the right.
CPS.CPRect1("I'm the text", 150, 50, color.green, color.brown, 3, 10, 1, 0.5)
CPS:CPRect1("I'm the text", 150, 50, color.green, color.brown, 3, 10, 1, 0.5)
```
loadPNG and CPDraw:

![img](https://github.com/Nats-ji/CPStyling.lua/raw/master/.image/cpdraw.gif)

```lua
-- Load a png image from file
image = CPS.loadPNG(path_to_png)
file = io.open(path_to_png, "rb")
image = CPS.loadPNG(file)
file:close()
-- Return image = { wdith = int, height = int, pixels = {
[1]:{
[1]:{ R, G, B, A },
Expand All @@ -156,12 +169,14 @@ image = CPS.loadPNG(path_to_png)
.....
}
-- Draw the png image
CPS.CPDraw(text_id, image, scale)
CPS:CPDraw(text_id, image, scale)
-- text_id (string), image (table), scale (number)

---Example---
image = CPS.loadPNG("./images/logo.png")
CPS.CPDraw("logo", image, 5)
file = io.open("./images/logo.png", "rb")
image = CPS.loadPNG(file)
file:close()
CPS:CPDraw("logo", image, 5)
```

### Color Names
Expand All @@ -184,6 +199,7 @@ CPS.CPDraw("logo", image, 5)
"maroon"
"green"
"olive"
"hidden"
```


Expand Down

0 comments on commit fbd1561

Please sign in to comment.