• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to create a non-static element within a View

Participant ,
Aug 08, 2022 Aug 08, 2022

Copy link to clipboard

Copied

I want to create a "Floating" dialog and inside will be a check box for each unique Job Identifier found within the catalog.  Based upon what I've seen from the user interface possible the SDK, I'm probalby on a fool's errand but I thought I would still ask and hope.

The only way I see to create a view is to create a static table via Lua's data declaration syntax.  For example:

   local f = LrView.osFactory()
   local view = f:column {
      margin = 10,
      spacing = 5,
      f:static_text {
         title = "Job Identifiers"
      },
      f:separator {
         fill_horizontal  = 1.0,
      },
      f:scrolled_view {
         horizontal_scroller = false,
         vertical_scroller = true,
         f:checkbox {
            title           = "test",
            value           = false,
            checked_value   = true,
            unchecked_value = false,
         },
      },
      f:separator {
         fill_horizontal  = 1.0,
      },
      f:push_button {
         title            = "Close",
         tooltip          = "Close the dialog",
         place_horizontal = 0.5,
         action           = function ()
            if show then
               show.close()
            end
         end,
      }
   }

I now what to put checkboxes inside the scrolled_view but I can not find any documented way to do that.  So, I dumped out the data structure created so far and tried using this code:

   local ptr = view["_children"][3]["_children"]
   for index, jobIdentifier in pairs(uniqueJobIdentifiers) do
      table.insert(ptr, index+1, f:checkbox {
                      title            = jobIdentifier,
                      value            = false,
                      checked_value    = true,
                      unchecked_value  = false,
      })
      ptr[index+1]._parent = ptr[1]._parent
      break
   end

The break is there during debugging.  The ptr[index+1]._parent = ptr[1]._parent code is because the results of the static declarations has a _parent that was not being created by the f:checkbox call within loop.  Indeed, the ptr[index+1]._parent = ptr[1]._parent does not create the _parent where it is suppose to but somehow ends up within the _viewAttributes section of the data structure.

TOPICS
SDK

Views

106

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 09, 2022 Aug 09, 2022

Once a hierarchy of controls have been created, you have very limited options for changing their layout dynamically.

 

However, you can create variable layouts during the construction of the controls. This fragment shows how to create a scrolled view of checkboxes for the job identifiers:

 

local checkboxes = {}
for _, jobId in ipairs (jobIds) do
    table.insert (checkboxes, 
        f:checkbox {title = jobId, ...})
    end

f:scrolled_view {
    horizontal_scroller = false,
    vertical_scroller =
...

Votes

Translate

Translate
LEGEND ,
Aug 09, 2022 Aug 09, 2022

Copy link to clipboard

Copied

Once a hierarchy of controls have been created, you have very limited options for changing their layout dynamically.

 

However, you can create variable layouts during the construction of the controls. This fragment shows how to create a scrolled view of checkboxes for the job identifiers:

 

local checkboxes = {}
for _, jobId in ipairs (jobIds) do
    table.insert (checkboxes, 
        f:checkbox {title = jobId, ...})
    end

f:scrolled_view {
    horizontal_scroller = false,
    vertical_scroller = true,
    f:column (checkboxes)}

 

If the list changes during the plugin's execution, you've got a couple options: 

 

- Terminate the execution of the dialog and recreate it with the new list.  There will be just a brief flicker as the dialog reopens.

 

- If you now you will never have more than, say, 100 checkboxes, create the scrolled view with 100 checkboxes bound to the properties "title1", "title2", ... "title100", "value1", "value2', ... "value100", and "visible1", "visible2", ... "visible100". Then set those title and value properties dynamically with the current list of job identifiers, setting the unused checkboxes to be invisible by setting "visible<i>" to false.  A disadvantage of this approach, besides having a maximum number of checkboxes, is that the scroll bars will be  sized to reflect all 100 checkboxes even if there are only 10 showing.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 09, 2022 Aug 09, 2022

Copy link to clipboard

Copied

LATEST

Thanks John.  I sent an email to the Lua mailing list and some nice person got me on the right track.  For some reason I was stuck on building the view from the outside in rather than from the innermost elements out.

 

But your last sentence caught my eye and sure enough you are right.  I rigged up a small test where a checkbox would make half the entries not visible and the other entries just stay in the same position.  This is true for elements in a row container, a column or a scroll box.  That really bums me out.  Maybe I'll add a Redraw button to redraw the dialog box.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines