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.
Related
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
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. ;-)
Basically, I need a scrollView which is shrinked horizontally. Now, when I insert a bunch of text in it, it doesn't adjust it, text just goes over the edge of the scrollView, like this: http://prntscr.com/ai0100
This is my scrollView code:
local scrollView = widget.newScrollView
{
hideBackground = false,
hideScrollBar = true,
left = 64,
top = 0,
width = contW - 128,
height = contH,
topPadding = 256,
bottomPadding = 20,
horizontalScrollDisabled = true,
verticalScrollDisabled = false,
}
I insert a bunch of text later, and screenshot above is the result. How can I fix this?
Read this: https://docs.coronalabs.com/api/library/display/newText.html
In order to wrap a text you have to set the display.newText() width parameter accordingly.
So something like
scrollView.newText
{
text = "I am a super text"
width = 123 -- replace with your desired width
}
This is another way:
local lotsOfTextObject = display.newText( lotsOfText, display.contentCenterX-40, 0, samewidthasscrollview, 0, native.systemFont, 30)
scrollView:insert( lotsOfTextObject )
We are using Xamarin.Forms with Xamarin.Forms.Labs components for the ImageButton. This is iOS.
For some reason the ImageButton is changing the color of the image that we want to use in the control. The standard Button component does the same, however, the Image componet works fine.
In the image, you can see how we load the same file into an Image, ImageButton, and Button views, and you can see that the Image one is correct, but the other two are changed from red to blue.
Any idea how to make the ImageButton or Button component show the original image without altering the colors?.
Snippet:
// wrong colors
var addPins = new ImageButton() {
Image = (FileImageSource) ImageSource.FromFile("Marker.png"),
HorizontalOptions = LayoutOptions.End,
VerticalOptions = LayoutOptions.Center,
ImageHeightRequest = 50,
ImageWidthRequest = 50,
HeightRequest = 50,
WidthRequest = 50
};
// good colors
var addPins2 = new Image {
Source = ImageSource.FromFile ("Marker.png"),
HeightRequest = 50,
WidthRequest = 50,
HorizontalOptions = LayoutOptions.End,
VerticalOptions = LayoutOptions.Center
};
// wrong colors
var addPins3 = new Button {
Image = new FileImageSource { File = "Marker.png"} ,
HorizontalOptions = LayoutOptions.End,
VerticalOptions = LayoutOptions.Center,
HeightRequest = 50,
WidthRequest = 50
};
grid.Children.Add (addPins, 1, 2);
grid.Children.Add (addPins2, 1, 1);
grid.Children.Add (addPins3, 1, 0);
Sample result:
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.