I want to create a simple widget which is a progress bar that gets its value set to 1 when we click it with left mouse button.
local myFirstWidget = wibox.widget {
{
value = 0.5,
color = "#ff0000",
widget = wibox.widget.progressbar,
width = 100,
forced_height = 20,
shape = gears.shape.rounded_bar,
border_width = 2,
border_color = beautiful.border_color,
ticks = true,
clip = true,
margins = {top = 5, bottom = 5},
paddings = 2
},
layout = wibox.layout.fixed.horizontal
}
myFirstWidget:connect_signal("button::press",
function(w, _, _, btn) w.value = 1 end)
When I press the bar - nothing really happens. And if I use
w.set_value(1)
then clicking the bar shows an error
attempt to call a nil value (field 'set_value')
How do I make it work?
It turnes out that w is the "parent" widget which contains progressbar widget. So I had to do it this way
myFirstWidget:connect_signal("button::press", function(w)
local children = w:get_all_children()
children[1].value = 1;
end)
so basically I retrieve a table of all children widgets and then use [1] to refer to the first widget in the table and after that I assign a value to its property
Related
I would like to know how to center a wibox.widget.textbox in wibox.container.background, because I would like to center the text in this image.
s.mytaglist = awful.widget.taglist {
screen = s,
filter = awful.widget.taglist.filter.all,
buttons = tag_list_buttons,
widget_template = {
id = 'background_role',
widget = wibox.container.background,
forced_width = 40,
{
layout = wibox.layout.fixed.horizontal,
{
id = 'text_role',
widget = wibox.widget.textbox,
},
},
},
}
I have try to add expand = "outside" but that doesn't work. Also, I doesn't want to use a wibox.container.margin, because it's not precise enough.
Thanks in advance for your help.
Set the align and valign properties of the textbox to "center" for horizontal and vertical center alignment.
Here on the right , I have a list of items in a composable , Every item is inside a row , All the items are inside a column
All the children of the are getting clipped to fit the screen which I don't want , I want these items to render completely even if outside of screen since I have a zoomable container above them
As you can see how text in the text field is all in one line vertically rather than expanding the width , This is the problem
Code :
Row(
modifier = modifier.zIndex(3f),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
) {
SimpleNodesList(
modifier = Modifier.padding(8.dp),
parentNode = state.center,
nodes = state.center.left,
renderRight = false,
)
SimpleNode(node = state.center, parentNode = null)
SimpleNodesList(
modifier = Modifier.padding(8.dp),
parentNode = state.center,
nodes = state.center.right,
renderLeft = false
)
}
Simple Nodes List is a column of rows , I have one column on left and one on the right , If the width of the left column increases , right row get's clipped by the screen
Using this modifier does the job for the row , In my case I also needed this layout modifier , wrapContentSize(unbounded = true) was working but children weren't clickable for some reason outside the bounds of the zoom container !
I also had to create a modifier zoomable rather than use a zoomable box , so the zoomable touch events would be dispatched on the this composable rather than the parent !
modifier = Modifier
.layout { measurable, constraints ->
val r =
measurable.measure(constraints = constraints.copy(maxWidth = Constraints.Infinity))
layout(r.measuredWidth, r.measuredHeight, placementBlock = {
r.placeWithLayer(0, 0, 0f) {
}
})
}
.wrapContentSize(unbounded = true)
If you are using hard-coded width for the text, applying Modifier.wrapContentSize() on every container might do the job
Use SimpleFlowRow in place of Row. It will fix the clipping issue.
I have a wibox with vertical layout and two text widgets:
local w = wibox {
width = 300,
height = 80,
ontop = true,
screen = mouse.screen,
}
w:setup {
{
id = 'header',
widget = wibox.widget.textbox
},
{
id = 'body',
widget = wibox.widget.textbox
},
id = 'text',
layout = wibox.layout.flex.vertical,
}
When string in 'body' textbox is short everything is ok, the widgets looks this way:
But if string is long, the size of the wibox is not enough to display it all so part of the string is cut out:
Is it possible to make wibox size change dynamically depending on size of the content?
I'm not quit sure what you want. If you want to adjust the height of the wibox for the content:
After you change the text of the textboxes, run something like the following code:
local t1 = w:get_children_by_id("header")[1]
local t2 = w:get_children_by_id("body")[1]
local h1 = t1:get_height_for_width(w.width, w.screen)
local h2 = t2:get_height_for_width(w.width, w.screen)
w.height = h1 + h2
If you want some extra empty space like in your first screenshot, you could add some number to the height. 42 is always a good answer. ;-)
In my menu.lua I have the following code:storyboard.gotoScene( "vegScreen" ), meaning: vegetable screen/menu
In the scene:createScene function of my vegScreen.lua I try to create a tabBar with 2 tabs. Using the following code:
local tabButtons = {
{
width = 50, height = 40,
defaultFile = "assets/tabIcon.png",
overFile = "assets/tabIcon-down.png",
label = "Per catagory",
onPress = function() storyboard.gotoScene( "catagory" ); end,
selected = true
},
{
width = 50, height = 40,
defaultFile = "assets/tabIcon.png",
overFile = "assets/tabIcon-down.png",
label = "All products",
onPress = function() storyboard.gotoScene( "all" ); end,
}
}
productBar = widget.newTabBar{ -- line 82
top = 65,
width = display.contentWidth,
backgroundFile = "assets/tabBar_background.png",
tabSelectedLeftFile = "assets/tabBar_background.png",
tabSelectedMiddleFile = "assets/tabBar_background.png",
tabSelectedRightFile = "assets/tabBar_background.png",
tabSelectedFrameWidth = 20,
tabSelectedFrameHeight = 52,
buttons = tabButtons
}
group:insert(productBar)
Using this code I get the following error:
http://i.imgur.com/0koV4PK.png
Line 82 in vegScreen.lua is where I create the new tabBar ( productBar = widget.newTabBar )
Though I don't know if the images I created are used correctly, it should show me something right? I have the module require statements at the top of my vegScreen.lua file (for storyboard and widget), created the catagory.lua and all.lua files which are located in the same folder as the vegScreen.lua and I have defined the group variable. Could somebody help me out? The error doesn't make any sense to me.
Not really an answer but I solved my problem. I had created files in which I used code to load content. I think the issue with that lies in not being able to add content to existing titanium views.
So what I did was deleted those files and created the views through code, which works like a charm.
In main.lua I create tabBar with three buttons and three screens (screen1, screen2, screen3)
In screen1 I would like to show modal overlay
local options = {
effect = "fromBottom",
time = 400,
isModal = true,
}
storyboard.showOverlay( "get", options )
Everything works, but I would like to show the overlay over tabBar (like modal view in xCode).
How can I do it?
In one case I should "goto" screen3 from screen1
storyboard.gotoScene( "screen3")
It's works, but selected tabButton is still tabButton1 (with screen1)
How to select tabButton programmatically?
Here is the code of creating tabBar in main.lua:
-- Create buttons table for the tab bar
local tabButtons = {
{
width = 32, height = 32,
defaultFile = "assets/tabIcon.png", overFile = "assets/tabIcon-down.png",
label = translations["tab1"][language],
onPress = function() storyboard.gotoScene( "screen1" ); end,
selected = true
},
{
width = 32, height = 32,
defaultFile = "assets/tabIcon.png", overFile = "assets/tabIcon-down.png",
label = translations["tab2"][language],
onPress = function() storyboard.gotoScene( "screen2" ); end,
},
{
width = 32, height = 32,
defaultFile = "assets/tabIcon.png", overFile = "assets/tabIcon-down.png",
label = translations["tab3"][language],
onPress = function() storyboard.gotoScene( "screen3" ); end,
}
}
--Create a tab-bar and place it at the bottom of the screen
local tabBar = widget.newTabBar {
top = display.contentHeight - 50,
height = 50,
width = display.contentWidth,
--backgroundFile = "assets/tabbar.png",
tabSelectedFrameWidth = 1,
tabSelectedFrameHeight = 49,
buttons = tabButtons
}
storyboard.gotoScene( "screen1", "crossFade", 200 )
I don't think you can show any image over the tab bar since it's a native object. The only way I could see it possibly working is by inserting the image and tabBar into a 2 groups. Then making the one display.newGroup() over the other one. I don't even think that will work though, but give it a shot.
Actually in Corona's case, if you are using widget.newTabBar(), they are Corona display objects. I think the issue you are running into is that storyboard objects live below any objects that are not being managed by storyboard.
Because your tabBar is typically not managed by storyboard it will sit on top of any storyboard scene, including overlays. To make this work the way you want, you would probably need to create a scene (call it menu.lua or tabbar.lua) that creates the tabBar in it's createScene function and make sure to add the tabBar to the scene's view. Now that scene is being managed by storyboard and your overlay can now cover it.