Skip to content

Commit

Permalink
Fixed tab update issues and indentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
SirMallard committed Dec 9, 2024
1 parent d28421b commit 44aa52b
Show file tree
Hide file tree
Showing 9 changed files with 333 additions and 318 deletions.
4 changes: 2 additions & 2 deletions docs/about/_category_.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"label": "About",
"position": 6
"label": "About",
"position": 6
}
96 changes: 48 additions & 48 deletions docs/about/cycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ part of the game process happens when. A typical game loop make look very simila

```cpp
while(not_closed) {
poll_input();
update_game_state();
step_physics();
render_content();
wait(); // for a 60 fps limit
poll_input();
update_game_state();
step_physics();
render_content();
wait(); // for a 60 fps limit
}
```
Here we start firstly with polling for any input changes, since these affect the game state
Expand All @@ -33,22 +33,22 @@ seen below:

```lua
while not_closed do
update(UserInputService)
update(ContextActionService)
update(UserInputService)
update(ContextActionService)

event(RunService.BindToRenderStepped)
event(RunService.RenderStepped)
event(RunService.BindToRenderStepped)
event(RunService.RenderStepped)

render()
render()

event(wait)
event(RunService.Stepped)
update(PhysicsService)
event(wait)
event(RunService.Stepped)
update(PhysicsService)

event(RunService.Heartbeat)
update(ReplicationService)
event(RunService.Heartbeat)
update(ReplicationService)

delay() -- for a 60 fps limit
delay() -- for a 60 fps limit
end
```

Expand Down Expand Up @@ -82,38 +82,38 @@ for handling all weapons on the client. Integrating Iris may look something simi
--- game.ReplicatedStorage.Modules.Client.Weaopns.WeaponsService.lua
------------------------------------------------------------------------
local WeaponsService = {
maxWeapons = 10,
activeWeapon = nil,
weapons = {}
maxWeapons = 10,
activeWeapon = nil,
weapons = {}
}

function WeaponsService.init()
end

-- called every frame to update all weapons
function WeaponsService.update(deltaTime: number)
Iris.Window({ "Weapons Service" })

WeaponsService.doSomething()
Iris.CollapsingHeader({ "Global Variables" })
Iris.DragNum({ "Max Weapons", 1, 0 }, { number = Iris.TableState(WeaponsService.maxWeapons) })
Iris.End()

Iris.CollapsingHeader({ "Weapons" })
Iris.Tree({ `Active Weapon: {WeaponsService.activeWeapon.name}` })
WeaponsService.activeWeapon:update()
Iris.End()

Iris.SeparatorText({ "All Weapons" })
for _, weapon: weapon in WeaponsService.weapons do
Iris.Tree({ weapon.name })
weapon:update()
Iris.End()
end
Iris.End()
WeaponsService.doSomethingElse()
Iris.End()
Iris.Window({ "Weapons Service" })

WeaponsService.doSomething()
Iris.CollapsingHeader({ "Global Variables" })
Iris.DragNum({ "Max Weapons", 1, 0 }, { number = Iris.TableState(WeaponsService.maxWeapons) })
Iris.End()

Iris.CollapsingHeader({ "Weapons" })
Iris.Tree({ `Active Weapon: {WeaponsService.activeWeapon.name}` })
WeaponsService.activeWeapon:update()
Iris.End()

Iris.SeparatorText({ "All Weapons" })
for _, weapon: weapon in WeaponsService.weapons do
Iris.Tree({ weapon.name })
weapon:update()
Iris.End()
end
Iris.End()
WeaponsService.doSomethingElse()
Iris.End()
end

function WeaponsService.terminate()
Expand All @@ -131,13 +131,13 @@ function Weapon.new(...)
end

function Weapon.update(self, deltaTime: number)
Iris.Text({ `ID: {self.id}` })
Iris.Text({ `Bullets: {self.bullets}/{self.capacity}" })
Iris.Checkbox({ "No reload" }, { isChecked = Iris.TableState(self.noreload) })
...
self:updateInputs()
self:updateTransforms()
...
Iris.Text({ `ID: {self.id}` })
Iris.Text({ `Bullets: {self.bullets}/{self.capacity}" })
Iris.Checkbox({ "No reload" }, { isChecked = Iris.TableState(self.noreload) })
...
self:updateInputs()
self:updateTransforms()
...
end

function Weapon.destroy(self)
Expand Down
92 changes: 46 additions & 46 deletions docs/about/widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function in `Iris.Internal`. This takes two arguments, a type for the widget, su
or SameLine, and a widget class table, containing the functions. This WidgetClass is defined as:
```lua
export type WidgetClass = {
-- Required
-- Required
Generate: (thisWidget: Widget) -> GuiObject,
Discard: (thisWidget: Widget) -> (),
Update: (thisWidget: Widget, ...any) -> (),
Expand All @@ -32,16 +32,16 @@ export type WidgetClass = {
hasChildren: boolean,
hasState: boolean,

-- Generated on construction
-- Generated on construction
ArgNames: { [number]: string },

-- Required for widgets with state
-- Required for widgets with state
GenerateState: (thisWidget: Widget) -> (),
UpdateState: (thisWidget: Widget) -> (),

-- Required for widgets with children
-- Required for widgets with children
ChildAdded: (thisWidget: Widget, thisChild: Widget) -> GuiObject,
-- Optional for widgets with children
-- Optional for widgets with children
ChildDiscarded: (thisWidget: Widget, thisChild: Widget) -> (),
}
```
Expand Down Expand Up @@ -200,52 +200,52 @@ the generated UI instances follow:
2. The ZIndex and LayoutOrder of the root element are taken from the ZIndex property of the widget.
3. Returns the root instance.
4. Widgets are generally sized using AutomaticSize or the config over hard-coded numbers, and therefore
scale better
scale better
5. The arguments are never used to modify any instances because if the arguments change then the widget
should be able to handle the changes on existing UI rather than creating a new design.
should be able to handle the changes on existing UI rather than creating a new design.

The code of a Button best demonstrates this:
```lua
Generate = function(thisWidget: Types.Button)
-- a TextButton is the best option here because it has the correct events
local Button: TextButton = Instance.new("TextButton")
-- we rely on auomatic size
Button.Size = UDim2.fromOfset(0, 0)
-- using the config values
Button.BackgroundColor3 = Iris._config.ButtonColor
Button.BackgroundTransparency = Iris._config.ButtonTransparency
Button.AutoButtonColor = false
Button.AutomaticSize = Enum.AutomaticSize.XY

-- utility functions exist such as this one which correctly sets the text
-- style for the widget
widgets.applyTextStyle(Button)
Button.TextXAlignment = Enum.TextXAlignment.Center

-- another utility function which adds any borders or padding dependent
-- on the config
widgets.applyFrameStyle(Button)

-- an utility event which uses clicks and hovers to colour the button
-- when the mouse interacts with it: normal, hovered and clicked
widgets.applyInteractionHighlights("Background", Button, Button, {
Color = Iris._config.ButtonColor,
Transparency = Iris._config.ButtonTransparency,
HoveredColor = Iris._config.ButtonHoveredColor,
HoveredTransparency = Iris._config.ButtonHoveredTransparency,
ActiveColor = Iris._config.ButtonActiveColor,
ActiveTransparency = Iris._config.ButtonActiveTransparency,
})

-- set the correct layout order and zindex to ensure it stays in the
-- correct order. Iris relies heavily on UIListLayouts to automatically
-- position the UI, and therefore relies on the LayoutOrder property.
Button.ZIndex = thisWidget.ZIndex
Button.LayoutOrder = thisWidget.ZIndex

-- we finally return the instance, which is correctly parented and
-- Iris sets the widget.instance property to this root element
return Button
-- a TextButton is the best option here because it has the correct events
local Button: TextButton = Instance.new("TextButton")
-- we rely on auomatic size
Button.Size = UDim2.fromOfset(0, 0)
-- using the config values
Button.BackgroundColor3 = Iris._config.ButtonColor
Button.BackgroundTransparency = Iris._config.ButtonTransparency
Button.AutoButtonColor = false
Button.AutomaticSize = Enum.AutomaticSize.XY

-- utility functions exist such as this one which correctly sets the text
-- style for the widget
widgets.applyTextStyle(Button)
Button.TextXAlignment = Enum.TextXAlignment.Center

-- another utility function which adds any borders or padding dependent
-- on the config
widgets.applyFrameStyle(Button)

-- an utility event which uses clicks and hovers to colour the button
-- when the mouse interacts with it: normal, hovered and clicked
widgets.applyInteractionHighlights("Background", Button, Button, {
Color = Iris._config.ButtonColor,
Transparency = Iris._config.ButtonTransparency,
HoveredColor = Iris._config.ButtonHoveredColor,
HoveredTransparency = Iris._config.ButtonHoveredTransparency,
ActiveColor = Iris._config.ButtonActiveColor,
ActiveTransparency = Iris._config.ButtonActiveTransparency,
})

-- set the correct layout order and zindex to ensure it stays in the
-- correct order. Iris relies heavily on UIListLayouts to automatically
-- position the UI, and therefore relies on the LayoutOrder property.
Button.ZIndex = thisWidget.ZIndex
Button.LayoutOrder = thisWidget.ZIndex

-- we finally return the instance, which is correctly parented and
-- Iris sets the widget.instance property to this root element
return Button
end,
```

Expand Down
40 changes: 20 additions & 20 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,30 @@ The API documentation for a window is as follows and contains all the informatio
hasChildren = true
hasState = true
Arguments = {
Title: string,
NoTitleBar: boolean? = false,
NoBackground: boolean? = false, -- the background behind the widget container.
NoCollapse: boolean? = false,
NoClose: boolean? = false,
NoMove: boolean? = false,
NoScrollbar: boolean? = false, -- the scrollbar if the window is too short for all widgets.
NoResize: boolean? = false,
NoNav: boolean? = false, -- unimplemented.
NoMenu: boolean? = false -- whether the menubar will show if created.
Title: string,
NoTitleBar: boolean? = false,
NoBackground: boolean? = false, -- the background behind the widget container.
NoCollapse: boolean? = false,
NoClose: boolean? = false,
NoMove: boolean? = false,
NoScrollbar: boolean? = false, -- the scrollbar if the window is too short for all widgets.
NoResize: boolean? = false,
NoNav: boolean? = false, -- unimplemented.
NoMenu: boolean? = false -- whether the menubar will show if created.
}
Events = {
opened: () -> boolean, -- once when opened.
closed: () -> boolean, -- once when closed.
collapsed: () -> boolean, -- once when collapsed.
uncollapsed: () -> boolean, -- once when uncollapsed.
hovered: () -> boolean -- fires when the mouse hovers over any of the window.
opened: () -> boolean, -- once when opened.
closed: () -> boolean, -- once when closed.
collapsed: () -> boolean, -- once when collapsed.
uncollapsed: () -> boolean, -- once when uncollapsed.
hovered: () -> boolean -- fires when the mouse hovers over any of the window.
}
States = {
size = State<Vector2>? = Vector2.new(400, 300),
position = State<Vector2>?,
isUncollapsed = State<boolean>? = true,
isOpened = State<boolean>? = true,
scrollDistance = State<number>? -- vertical scroll distance, if too short.
size = State<Vector2>? = Vector2.new(400, 300),
position = State<Vector2>?,
isUncollapsed = State<boolean>? = true,
isOpened = State<boolean>? = true,
scrollDistance = State<number>? -- vertical scroll distance, if too short.
}
```

Expand Down
16 changes: 8 additions & 8 deletions lib/API.lua
Original file line number Diff line number Diff line change
Expand Up @@ -695,14 +695,14 @@ return function(Iris: Types.Iris)
Iris.CollapsingHeader = wrapper("CollapsingHeader")

--[[
--------------------------------
[SECTION] Tab Widget API
--------------------------------
]]
--[=[
@class Tab
Tab Widget API
]=]
--------------------------------
[SECTION] Tab Widget API
--------------------------------
]]
--[=[
@class Tab
Tab Widget API
]=]

--[=[
@within Tab
Expand Down
1 change: 1 addition & 0 deletions lib/Internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ return function(Iris: Types.Iris): Types.Internal
return self.value
end
self.value = newValue
self.lastChangeTick = Iris.Internal._cycleTick
for _, thisWidget: Types.Widget in self.ConnectedWidgets do
Internal._widgets[thisWidget.type].UpdateState(thisWidget)
end
Expand Down
1 change: 1 addition & 0 deletions lib/WidgetTypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type ID = string
export type State<T> = {
ID: ID,
value: T,
lastChangeTick: number,
ConnectedWidgets: { [ID]: Widget },
ConnectedFunctions: { (newValue: T) -> () },

Expand Down
5 changes: 5 additions & 0 deletions lib/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ function Iris.State<T>(initialValue: T): Types.State<T>
Internal._states[ID] = {
ID = ID,
value = initialValue,
lastChangeTick = Iris.Internal._cycleTick,
ConnectedWidgets = {},
ConnectedFunctions = {},
} :: any
Expand Down Expand Up @@ -454,6 +455,7 @@ function Iris.WeakState<T>(initialValue: T): Types.State<T>
Internal._states[ID] = {
ID = ID,
value = initialValue,
lastChangeTick = Iris.Internal._cycleTick,
ConnectedWidgets = {},
ConnectedFunctions = {},
} :: any
Expand Down Expand Up @@ -513,6 +515,7 @@ function Iris.VariableState<T>(variable: T, callback: (T) -> ()): Types.State<T>
local newState = {
ID = ID,
value = variable,
lastChangeTick = Iris.Internal._cycleTick,
ConnectedWidgets = {},
ConnectedFunctions = {},
} :: Types.State<T>
Expand Down Expand Up @@ -594,6 +597,7 @@ function Iris.TableState<K, V>(tab: { [K]: V }, key: K, callback: ((newValue: V)
local newState = {
ID = ID,
value = value,
lastChangeTick = Iris.Internal._cycleTick,
ConnectedWidgets = {},
ConnectedFunctions = {},
} :: Types.State<V>
Expand Down Expand Up @@ -639,6 +643,7 @@ function Iris.ComputedState<T, U>(firstState: Types.State<T>, onChangeCallback:
Internal._states[ID] = {
ID = ID,
value = onChangeCallback(firstState.value),
lastChangeTick = Iris.Internal._cycleTick,
ConnectedWidgets = {},
ConnectedFunctions = {},
} :: Types.State<U>
Expand Down
Loading

0 comments on commit 44aa52b

Please sign in to comment.