Post by Danilo on Sept 15, 2019 9:39:41 GMT
Example for styling mojox views at runtime without using a theme.json file:
#import "<std>"
#import "<mojo>"
#import "<mojox>"
Using std..
Using mojo..
Using mojox..
Class Border
Method New(left:Int,top:Int,right:Int,bottom:Int)
Self.left = left
Self.top = top
Self.right = right
Self.bottom = bottom
End
Method New(leftright:Int,topbottom:Int)
Self.left = leftright
Self.top = topbottom
Self.right = leftright
Self.bottom = topbottom
End
Method New(allsides:Int)
Self.left = allsides
Self.top = allsides
Self.right = allsides
Self.bottom = allsides
End
Method To:Recti()
Return New Recti(-left,-top,right,bottom)
End
Property Left:Int()
Return Self.left
Setter( left:Int )
Self.left = left
End
Property Top:Int()
Return Self.top
Setter( top:Int )
Self.top = top
End
Property Right:Int()
Return Self.right
Setter( right:Int )
Self.right = right
End
Property Bottom:Int()
Return Self.bottom
Setter( bottom:Int )
Self.bottom = bottom
End
Protected
Field left:Int
Field top:Int
Field right:Int
Field bottom:Int
End
Alias Margin:Border
Alias Padding:Border
Class MyWindow Extends Window
Method New()
Super.New( "Button Demo",640,300,WindowFlags.Resizable )
Style.BackgroundColor = Color.White
Local style:Style
style = App.Theme.GetStyle("Button")
style.BorderColor = Color.Black
style.BackgroundColor = Color.LightGrey
style.SkinColor = Color.LightGrey
style.TextColor = Color.Black
style.Padding = New Padding(8,12)
style.Border = New Border(1)
style.Margin = New Margin(20,20,20,20)
style = App.Theme.GetStyle("Button").AddState("hover")
style.BorderColor = Color.Black
style.BackgroundColor = Color.DarkGrey
style.SkinColor = Color.DarkGrey
style.TextColor = Color.White
style.Padding = New Padding(8,12,8,12)
style.Border = New Border(1)
style.Margin = New Margin(20,20)
style = App.Theme.GetStyle("Button").AddState("active")
style.BorderColor = Color.Black
style.BackgroundColor = Color.White
style.SkinColor = Color.White
style.TextColor = Color.Black
style.Padding = New Padding(8,12)
style.Border = New Border(1)
style.Margin = New Margin(20)
Local dock := New DockingView
dock.AddView(New Button("Top"),"top")
dock.AddView(New Button("Bottom"),"bottom")
dock.AddView(New Button("Left"),"left")
dock.AddView(New Button("Right"),"right")
dock.ContentView = New Button("Mid")
ContentView=dock
End
End
Function Main()
New AppInstance
New MyWindow
App.Run()
End