TheJuki / KFormMaster

Generic form builder in Kotlin
https://thejuki.github.io/KFormMaster/
Apache License 2.0
196 stars 46 forks source link

Type Radio as Button Group #41

Closed darkwood-studios closed 6 years ago

darkwood-studios commented 6 years ago

Hi there,

I'm looking for a way to create a button group which is acting like a custom radio button. So it could by something like a SwitchFormType with more than two switches.

You can find an example attached.

example

TheJuki commented 6 years ago

I could try implementing this library: https://github.com/Kaopiz/android-segmented-control or this one: https://github.com/RobertApikyan/SegmentedControl

darkwood-studios commented 6 years ago

@TheJuki I think this one could do the trick: https://github.com/Kaopiz/android-segmented-control

Or maybe an even better source without an library -> https://medium.com/@staceypyee/revealing-the-magic-of-creating-ios-segmented-control-with-image-in-android-kotlin-part-1-7d817f9d5c7

TheJuki commented 6 years ago

I just released 4.6.1. Please update your dependency and let me know if the Segmented element works for you. Check out the docs: https://thejuki.github.io/KFormMaster/element/segmented/

darkwood-studios commented 6 years ago

Hi @TheJuki

looks really great! One question left:

I want to customize colors, spacings and sizes. So my idea was to create a custom layout as you explained here : https://github.com/StarkSoftware/SSForms/issues/3

I copied the form_element_segment.xml into my project and changed some values - but unfortunately nothing changes in the app. Do you have any idea why that does not work?

Thanks for your great support.

darkwood-studios commented 6 years ago

And one more idea: if no title is provided, the view of the label should be removed - otherwise we'll have some unnecessary space above the button group.

TheJuki commented 6 years ago

I copied and converted the main class from https://github.com/Kaopiz/android-segmented-control

Here: https://github.com/TheJuki/KFormMaster/blob/master/form/src/main/java/com/thejuki/kformmaster/widget/SegmentedGroup.kt

It controls most of styling. I can add new properties to the FormSegmentedElement class which can talk to and update the SegmentedGroup class.

Also, the RadioButtons are added programmatically, so, adding RadioButtons to the XML would not work. The ones in form_element_segment.xml should probably just be removed.

As for the title, I can check if the title is null or empty and make the View be View.GONE.

darkwood-studios commented 6 years ago

As for the title, I can check if the title is null or empty and make the View be View.GONE.

That would be perfect.

It controls most of styling. I can add new properties to the FormSegmentedElement class which can talk to and update the SegmentedGroup class.

Ah I see. So I can set colors and corner with that class. But what I'm missing is to set the layout to fill horizontal. Perhaps you have an idea to implement this.

Thats now:

before

So it should look like:

after

TheJuki commented 6 years ago

Oh. Hmm. I'll play around with it but it should be possible. Again, I'll make this a property in FormSegmentedElement.

TheJuki commented 6 years ago

Setting android:layout_weight="1" in the XML for the RadioButton seems to work. So, I'll add "fillSpace" as a property.

darkwood-studios commented 6 years ago

So, I'll add "fillSpace" as a property.

Sound perfect. Thank you.

Maybe you could add some properties for colors, corner and margin/padding as well.

I may be able to change color by adding "colorFormMasterElementRadioSelected" in my colors, but changing the corner radius by adding R.dimen.elementRadioCornerRadius to my dimens.xml is not working. Maybe a property could handle that.

And some properties to change text size and button padding would add more flexibility, too. What do you think?

TheJuki commented 6 years ago

Sounds good!

TheJuki commented 6 years ago

Making progress...

TheJuki commented 6 years ago

I just released 4.6.2. Please update your dependency and let me know if the new properties work for you. The title for segmented will also be View.GONE if null or empty.

darkwood-studios commented 6 years ago

works great and looks fantastic! 🥇

Some further ideas for later:

TheJuki commented 6 years ago

Stroke size: https://thejuki.github.io/KFormMaster/element/segmented/#margin-stroke Stroke color: https://thejuki.github.io/KFormMaster/element/segmented/#tint-color

darkwood-studios commented 6 years ago

So I close this issue now. You did a great job on this feature.