project-navigation
Personal tools

Author Topic: lua design thoughts  (Read 73034 times)

Offline geever

  • Project Coder
  • PHALANX Commander
  • ***
  • Posts: 2561
    • View Profile
Re: lua design thoughts
« Reply #105 on: August 24, 2015, 01:05:32 am »
2. Scrollbars
    Assigning scrollbars is annoying in the ufoscript too. Here is it in LUA:

Code: [Select]
    local ObjectInfo_info_description = ufo.create_text(ObjectInfo_info, "description", nil)
    ...
    ObjectInfo_info_description.on_viewchange = function (sender)
        ObjectInfo_info_descriptionscroll:set_fullsize(sender:fullsize())
        ObjectInfo_info_descriptionscroll:set_current(sender:viewpos())
    end
    ObjectInfo_info_description.on_wheel = function (sender)
        ObjectInfo_info_descriptionscroll:set_current(sender:viewpos())
    end

    local ObjectInfo_info_descriptionscroll = ufo.create_vscrollbar(ObjectInfo_info, "description_scroll", nil)
    ...
    ObjectInfo_info_descriptionscroll.on_change = function (sender)
        ObjectInfo_info_description:set_viewpos(sender:current())
    end

What if instead we added uiAbstractScrollableNode and uiAbstractScrollbarNode methods for assignment:
Code: [Select]
    local text1 = ufo.create_text(root, "text1", nil)
    local scroll1 = ufo.create_vscrollbar(root, "scroll1", nil)
    text1:assign_scrollbar(scroll1)

    local text2 = ufo.create_text(root, "text2", nil)
    local scroll2 = ufo.create_vscrollbar(root, "scroll2", nil)
    scroll2:assign_to(text2)

And it would automatically make the event handshake?

Scrollbar could be generated automatically: (using Suggestion#1)
Code: [Select]
    local text1 = ufo.create_text(root, "text1", {
        ...
        ["add_vscrollbar"] = auto    -- true | false | auto, where auto is the "hide if unused" option. It should be false by default.
    })

-geever

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: lua design thoughts
« Reply #106 on: August 25, 2015, 03:36:41 pm »
What if instead we could write:
Code: [Select]
    local building_head = ufo.create_string(box, "building_head", {
        ["super"]        = nil,
        ["box"]          = { 0, 20, 150, 20 },
        ["font"]         = "f_very_small_bold",
        ["contentalign"] = ufo.ALIGN_CC,
        ["longlines"]    = ufo.LONGLINES_PRETTYCHOP,
        ["text"]         = "_Building"
    })

This is much in line with an idea I had about setting a group of properties using lua's native table structure. I'm going to look into this a bit more. It would look a bit like this:

Code: [Select]
local fooNode = ufo.create_button(...)
fooNode.set_properties({
  box = {0, 0, 100, 100}
  text = "_Foo button"
  ...
})

Typically it can be solved the lua way, using boilerplate code (e.g. a "set_properties" method) taking a lua table and then calling the api. Drawback is that you have to maintain two sets of interfaces. The lua-C interface and the lua-lua interace. An alternative is to add the method to the basic node that accepts a lua table, scans it and looks for properties in on the C-side. Drawback here is that the lua api has renamed some of the properties to more logical names.

xray

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: lua design thoughts
« Reply #107 on: August 25, 2015, 03:47:55 pm »
2. Scrollbars
    Assigning scrollbars is annoying in the ufoscript too.
    ...

Problem here is that this is a flaw in the existing c-implementation of the ui, rather than a lua issue. If you look at similar implementations the actual creation of the scrollbar is delegated to the owning control. So I guess an "auto_scroll" property will need to be implemented on the c-side first. After that we have to evaluate if there is actually a need to implement a custom "on_scroll" event. However this event should not be used to scroll the parent view, since this aspect should be handled by the parent control creating the scrollbars.

Anyway, this takes some redesigning of the ui. I'll put it on the todo-list.

xray



xray

Offline geever

  • Project Coder
  • PHALANX Commander
  • ***
  • Posts: 2561
    • View Profile
Re: lua design thoughts
« Reply #108 on: August 26, 2015, 06:21:39 pm »
Anyway, this takes some redesigning of the ui. I'll put it on the todo-list.

Thanks!

What about using our bug/feature tracker as a todo-list?

-geever

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: lua design thoughts
« Reply #109 on: August 27, 2015, 07:48:43 am »
Thanks!

What about using our bug/feature tracker as a todo-list?

-geever

Added them as 2 improvements: 5495 and 5496.

xray

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: lua design thoughts
« Reply #110 on: August 30, 2015, 07:27:17 pm »
Hi,

A small update. I managed to write some lua code allowing the following construct (using lua tables). It allows for a hierarchy of (nested) tables defining ui nodes to be created in a single statement. This more or less mimics the old ufo script behaviour, only then in lua. Currently the code to create a set of nodes looks like this:

Code: [Select]
node = {
_type = "panel",
_name = "pnlTest",

pos = { 10, 250 },
size = { 200, 200 },
layout = ufo.LAYOUT_TOP_DOWN_FLOW,
layoutmargin = 15,
backgroundcolor = { 0.50, 0.00, 0.00, 1.00 },

{
_type = "MainMenuBtn",
_name = "btnTest1",
text = "_Test 1"
},

{
_type = "MainMenuBtn",
_name = "btnTest2",
text = "_Test 2"
},

{
_type = "MainMenuBtn",
_name = "btnTest3",
text = "_Test 3"
}
}

...
do
wndMain = ufo.create_window ("main", nil)
wndMain:set_background ("ui/main_bg")

local pnlTest = build(node, wndMain)

        ...


The above results in the red panel on the left (see attached image). I'm going to work on this further but for now, it looks promising.

xray

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: lua design thoughts
« Reply #111 on: September 02, 2015, 01:54:03 pm »
Hi,

I've created a pull request with an update on the lua integration of the ui. It is now possible to create windows/compones/nodes from a data structure that looks more-or-less like ufo script. Note that there are some small changes to the situation described in the previous post, they're described in the wiki.

@geever: hope this is what youre looking for  :)

xray

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: lua design thoughts
« Reply #112 on: September 17, 2015, 10:05:38 pm »
Cool stuff. Would merge the pull request - but there is a merge commit in it. If you could get rid of that one, that would be nice. Otherwise I could also cherry-pick them manually.

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: lua design thoughts
« Reply #113 on: September 18, 2015, 08:34:53 am »
... Would merge the pull request - but there is a merge commit in it. ...

How do I get rid of the merge commit?

xray

Offline DarkRain

  • Project Coder
  • Captain
  • ***
  • Posts: 746
    • View Profile
Re: lua design thoughts
« Reply #114 on: September 18, 2015, 04:56:45 pm »
Doing
Code: [Select]
git rebase <ufoai master branch> <your branch>should be enough to get rid of them, but to push a rebased branch you'll need to use the --force option, and everybody who already pulled it will need to reset/rebase their local version of your branch, and so and so on

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: lua design thoughts
« Reply #115 on: September 19, 2015, 04:28:16 pm »
Rebased the PR. Hope it is alright now.

xray