Skip to content

Commit

Permalink
app background color and textfield font size
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcoder04 committed Oct 26, 2022
1 parent ac761ac commit 3d7945e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ All the parts are then assembled and built into one `.tns` file by [sol-tools](h
- `res` contains any non-code resources, e. g. images and data.
- `res/data/menu.yml` is a native nspireOS-menu, written in YAML
- `components` are re-usable blocks of your GUI which can inherit from base components, written in YAML
- `solproj.yml` is where app metadata goes
- `init.lua` runs at start
- `app.lua` is your main file where you define what is your application about
- `app.lua` is your main file where you define the app logic
- `hooks.lua` is where you can hook into raw inspired Lua events, like drawing with `gc` inside `on.paint`

```text
|
Expand All @@ -38,8 +40,10 @@ All the parts are then assembled and built into one `.tns` file by [sol-tools](h
| |--header.yml
| |--text.yml
| |--...
|--solproj.yml
|--init.lua
|--app.lua
|--hooks.lua
```

## Roadmap / TODOs
Expand All @@ -62,6 +66,8 @@ All the parts are then assembled and built into one `.tns` file by [sol-tools](h
- [x] redraw on timer only if one of update functions returns true
- [x] rename `Library` to `Lib`
- [ ] schedule to do something at next redraw/update / imitating sleep function
- [ ] focusable and unfocusable components
- [ ] colorschemes

## Naming

Expand Down
6 changes: 6 additions & 0 deletions app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ App = {
License = "unknown",
RefreshRate = 10,
SolVersion = 0,
Gui = {},
Data = {
Const = {},
Var = {}
Expand Down Expand Up @@ -49,6 +50,11 @@ function App:_onElementClick()
end

function App:_draw(gc)
if App.Gui.Background ~= nil then
gc:setColorRGB(unpack(App.Gui.Background))
gc:fillRect(0, 0, platform.window:width(), platform.window:height())
gc:setColorRGB(0, 0, 0)
end
for i = 1, #(self._elements) do
if not self._elements[i].Hidden then
self._elements[i]:_draw(gc, self._focused == i)
Expand Down
5 changes: 4 additions & 1 deletion components/TextField.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Components.Base.TextField = {
PosY = 0,
Label = "",
Border = false,
Color = {0, 0, 0}
Color = {0, 0, 0},
FontSize = 12
}

function Components.Base.TextField:new(o)
Expand All @@ -26,7 +27,9 @@ end

function Components.Base.TextField:_draw(gc, focused)
gc:setColorRGB(unpack(self.Color))
gc:setFont("sansserif", "r", self.FontSize)
gc:drawString(self.Label, self.PosX, self.PosY, "top")
gc:setFont("sansserif", "r", 12)
local w, h = Lib.Gui:GetStringSize(self.Label)
if self.Border then
gc:drawRect(self.PosX, self.PosY, w, h)
Expand Down
8 changes: 6 additions & 2 deletions events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ end
function on.charIn(c)
if App._focused == 0 then
if Hooks.CharIn ~= nil then
Hooks:CharIn(c)
if Hooks:CharIn(c) then
platform.window:invalidate()
end
end
return
end
Expand All @@ -76,7 +78,9 @@ end
function on.backspaceKey()
if App._focused == 0 then
if Hooks.Backspace ~= nil then
Hooks:Backspace()
if Hooks:Backspace() then
platform.window:invalidate()
end
end
return
end
Expand Down

0 comments on commit 3d7945e

Please sign in to comment.