overlapping widgets gtk - gtk

How can i make widgets overlap one another.
Lower most should be image, rest above can be other widgets like buttons.

Subclass the larger(parent) widget. In a create() method or in the constructor, add a layout( or container) widget to the parent widget, then inset the others into the container. Now threat this new subclass as if it were a single, but specialized, version of its super class.
A Window is an example of a parent widget, while Fixed is an example container. A child could be an EventBox enclosing an Image. The composite of all these is a new window object that has pictures that can be clicked.
For the case of a window's titlebar look with a pixmap background, and buttons, try a Window with an Image and a Fixed container to hold the buttons. The Fixed and the Image should be able to overlap as the Fixed is transparent, and an Image has no Window.
If Buttons are truly what's needed, have a look at Button Boxes and Toolbars in the list of GTK Containers. It may be possible to add an Image background to one of those.
A different approach involves an Alignment Widget(from the same list). It specifies where the smaller widgets are positioned and sized in a proportioned manner.
I assumed, OOP, but if it's not, just organize the creation of the widgets from one function. I've made composite widgets functionally in Haskell(Gtk2Hs), and in Guile Gnome Platform (with and without OOP)

Related

How to use SizeTransition with Text inside a Row without overflows

Problem summary
I'm building simple animation in which, simply, a panel expands to the right on a onTap event. The layout can be summarized as follows:
The panel has many tiles. Each tile has its own:
leading icon
title text
trailing icon
Each tile, when expanded, shows the three widgets above
Each tile, when shrinked, just shows the leading icon
The panel is scrollable to hold many icons such as these
At the end of the panel there's a simple icon which, when tapped, triggers the "expand" or "shrink" animation
The animation is built with an AnimatedContainer on the panel and a SizeTransition on the single tiles (via one single controller on the parent class)
The problem is simple: when the tiles shrink, their inner text overflows in the row.
Sample code
I just made this reproducible example on DartPad.
The obvious solution isn't helping me out
The most obvious solution is to simply wrap the Text inside a Flexible Widget: this advised by Flutter's docs and it makes sense, but unluckily it completely breaks my Layout.
Flexible introduces a flex factor that in this context is 100% unwanted.
I want my leading icons to be always at the end of the row, so my Spacer widget should "prevail" there.
I can't just play with flex factors there, as it would unintendedly hide text depending on its value.
Another code smell
Another thing I really don't like is the fact that I have to build a controller on the parent class, but I'm not actually using it on the parent class (I'm just exploiting it so I can give it to the children).
I'm new to animations in Flutter so I'm kinda confused on how I should orchestrate the whole thing here.
Any help will be appreciated / upvoted / accepted. Thank you!
As far as I understood you in a right way you just need set sizes for Row inside of SizeTransition instead of Container sizes
Here is your modified sample https://dartpad.dev/?id=a2408d29a1e8c6ce7a1cef8f21e7491d
I'd try an OverflowBox or a FittedBox (wrapping your text), depending on the result you want to achieve.

What's the difference between raisedButton and Container with onTap() (Flutter)?

When we want to achieve a button, we can choose raisedButton in flutter lib, also can a Container with onTap() function. So what's the difference between the two and which one should we choose in different situation?
Container function doesnot have onTap option, but you can achieve it by wrapping it in Guesture detector or Inkwell. There are no changes in the backend. But Raised button gives you the elevation, and animation on tap. You can also do it in the container, but it requires you to manually do it.
If you want a simple button quickly use RaisedButton.
If you want a more complex one, use Container or mixture of Containers, RaisedButton etc.
I am gonna offer something different... A tale of a treasure that is known to have answers to many questions, use cases and sometimes even examples. The name of this treasure is: official documentation. ;)
RaisedButton
A raised button is based on a Material widget whose Material.elevation increases when the button is pressed. Use raised buttons to add dimension to otherwise mostly flat layouts, e.g. in long busy lists of content, or in wide spaces. Avoid using raised buttons on already-raised content such as dialogs or cards.
Container
A convenience widget that combines common painting, positioning, and
sizing widgets.
GestureDetector
A widget that detects gestures. Attempts to recognize gestures that
correspond to its non-null callbacks. If this widget has a child, it
defers to that child for its sizing behavior. If it does not have a
child, it grows to fit the parent instead. By default a
GestureDetector with an invisible child ignores touches; this behavior
can be controlled with behavior. GestureDetector also listens for
accessibility events and maps them to the callbacks. To ignore
accessibility events, set excludeFromSemantics to true. See
flutter.dev/gestures/ for additional information. Material design
applications typically react to touches with ink splash effects. The
InkWell class implements this effect and can be used in place of a
GestureDetector for handling taps.
InkWell
A rectangular area of a Material that responds to touch. For a variant
of this widget that does not clip splashes, see InkResponse... The
InkWell widget must have a Material widget as an ancestor. The
Material widget is where the ink reactions are actually painted. This
matches the material design premise wherein the Material is what is
actually reacting to touches by spreading ink.
Well, technically you are right, they can both react to a click event. But a RaisedButton will have all the styles specific to the target platform taken care of for you (it inherits from MaterialButton).
note that it's the same in html: you can use a regular div with a click handler or use a button tag. The button will have a few styles already taken care of for you...

How to make widget to occupy all the available space in Gtk.HBox

I am implementing a custom Gtk# widget which is based on Gtk.EventBox. When I am inserting it into the HBox or VBox it occupies the exact size that is returned by OnSizeRequested method.
How can I make my widget to occupy all the space given to it by the parent box, window or the widget? Just like HBox does.
There is a slight different between the preferred way to do packing in GTK+2 vs GTK+3. With GTK+ you would typically use expand and fill properties of a GtkBox to control how space is allocated. With GTK+3 they are suggesting the user of vertical-expand, horizontal-expand, vertical-fill, horizontal-fill.
A good way to understand how packing works is to play with the fill and expand properties with Glade so you can see the effects in real time. An old tutorial (slightly out of date) shows some screenshots of different packing properties: How_Packing_Effects_the_Layout
As you are developing a widget it is more likely that users of your widget will determine how it should be packed in a larger UI. However, if you're widget is a composite widget (built from other widgets) then you will need to pack the other widgets properly.
PackStart and PackEnd have a fill parameter to specify items that should expand to fill the box. You probably want PackStart(widget, true, true, 0);

How do you get GWT 2.0 to accept clicks on two different Widgets added to a LayoutPanel?

Using GWT 2.0 I have an entry point that adds two Widgets to a LayoutPanel which in turn is added to the RootLayoutPanel. The Widgets both handle click events and have click events registered to them. The problem is that only the last widget added to the LayoutPanel can actually be clicked. Switch the order in which the widgets are added switches the widget that works. Add mroe widgets and still the only you can click is the last one added to the LayoutPanel.
Any idea why this is? Is there any reasoning behind the behaviour, or have I missunderstood what is happening under the covers? How do I gat all widgets in the LayoutPanel to accept events? Should I be using another panel class?
I'm not too bothered if the LayoutPanel prevents anything below it from being clicked, but want all Widgets added to it to be clickable.
Stupid Boy! (said in the voice of Captain Mainwaring)
There is no problem having two Widgets on a LayoutPanel accepting clicks. But if you adjust the Widgets' size by manipulating their elements' styles directly then the containing element created by the LayoutPanel will still cover the whole screen. In effect the last Widget added always covered everything else.
GWT school: D- Must try harder. Easily distracted...

ImageButton in gwt

I have to create a image button in gwt which uses three images(left side image,center stretch image and right image).Left side images and right images having rounded corners.Center Image wants to be stretched depends on button title size.Created ImageButton should have all the functionalities of Button.
Can anyone help me in how to achieve this.
If you need a button with rounded corners then there are a number of options:
Create a new widget that extends the DecoratorPanel to create the rounded corners. The DecoratorPanel will result in a table (HTML). You'll probably want to replace the standard images. Look at the standard.css that GWT provides to find the styles that define those images, then override those styles in your custom stylesheet (look for the CSS class ".gwt-DecoratorPanel"). In the widget, add a Label widget to display the button text and provide get and set methods on your widget to get and set text to the internal label. The label will resize automatically forcing the table cell to grow bigger.
Create a new widget that extends Composite. The widget should wrap a FlexTable. Use 3 cells on the same row. Add a Label to the center cell and provide get and set methods on your widget to get and set text to the internal label. The label will resize automatically forcing the table cell to grow bigger. Add the appropriate handlers to the FlexTable widget. I suggest you use those events to add or remove styles to the appropriate cells and define the background images in a stylesheet.
You could create your own widget. This requires that you generate your own HTML etc. which may not immediately work in every browser. I recommend trying option 1 or 2 first.
You might be able to get away with using only one sprite image if you can limit the maximum width of your buttons. We wrote a CssButton class (extends Button) as part of the GWT Portlets framework that uses a single background image sprite to create rounded buttons. The code uses CSS clipping to select the correct background image from the sprite based on the width of the button.
The main advantages are that it extends the normal GWT Button and uses only a single BUTTON element in the DOM (lightweight). The disadvantage is that the maximum width of the button is limited to the widest button image in the sprite.
It also handles rollover and click effects all using the same sprite.
The code is in the GWT Portlets repository if you want to look further.